func (c *Chat) ClearMessages() {
	c.Messages = make(map[string]Message)
}
ClearMessages clear the c.Messages
package components
import (
	"fmt"
	"sort"
	"strings"
	"time"
	"github.com/erroneousboat/termui"
	runewidth "github.com/mattn/go-runewidth"
	"github.com/erroneousboat/slack-term/config"
)
type Chat struct {
	List     *termui.List
	Messages map[string]Message
	Offset   int
}
func CreateChatComponent(inputHeight int) *Chat {
	chat := &Chat{
		List:     termui.NewList(),
		Messages: make(map[string]Message),
		Offset:   0,
	}
	chat.List.Height = termui.TermHeight() - inputHeight
	chat.List.Overflow = "wrap"
	return chat
}
func (c *Chat) Buffer() termui.Buffer {
	cells := c.MessagesToCells(c.Messages)
	type Line struct {
		cells []termui.Cell
	}
	lines := []Line{}
	line := Line{}
	x := 0
	for _, cell := range cells {
		if cell.Ch == '\n' {
			lines = append(lines, line)
			line = Line{}
			x = 0
			continue
		}
		if x+cell.Width() > c.List.InnerBounds().Dx() {
			lines = append(lines, line)
			line = Line{}
			x = 0
		}
		line.cells = append(line.cells, cell)
		x += cell.Width()
	}
	lines = append(lines, line)
	buf := c.List.Buffer()
	linesHeight := len(lines)
	paneMinY := c.List.InnerBounds().Min.Y
	paneMaxY := c.List.InnerBounds().Max.Y
	currentY := paneMaxY - 1
	for i := (linesHeight - 1) - c.Offset; i >= 0; i-- {
		if currentY < paneMinY {
			break
		}
		x := c.List.InnerBounds().Min.X
		for _, cell := range lines[i].cells {
			buf.Set(x, currentY, cell)
			x += cell.Width()
		}
		for x < c.List.InnerBounds().Max.X {
			buf.Set(
				x, currentY,
				termui.Cell{
					Ch: ' ',
					Fg: c.List.ItemFgColor,
					Bg: c.List.ItemBgColor,
				},
			)
			x += runewidth.RuneWidth(' ')
		}
		currentY--
	}
	for currentY >= paneMinY {
		x := c.List.InnerBounds().Min.X
		for x < c.List.InnerBounds().Max.X {
			buf.Set(
				x, currentY,
				termui.Cell{
					Ch: ' ',
					Fg: c.List.ItemFgColor,
					Bg: c.List.ItemBgColor,
				},
			)
			x += runewidth.RuneWidth(' ')
		}
		currentY--
	}
	return buf
}
func (c *Chat) GetHeight() int {
	return c.List.Block.GetHeight()
}
func (c *Chat) SetWidth(w int) {
	c.List.SetWidth(w)
}
func (c *Chat) SetX(x int) {
	c.List.SetX(x)
}
func (c *Chat) SetY(y int) {
	c.List.SetY(y)
}
func (c *Chat) GetMaxItems() int {
	return c.List.InnerBounds().Max.Y - c.List.InnerBounds().Min.Y
}
func (c *Chat) SetMessages(messages []Message) {
	c.Offset = 0
	for _, msg := range messages {
		c.Messages[msg.ID] = msg
	}
}
func (c *Chat) AddMessage(message Message) {
	c.Messages[message.ID] = message
}
func (c *Chat) AddReply(parentID string, message Message) {
	if _, ok := c.Messages[parentID]; ok {
		message.Thread = "  "
		c.Messages[parentID].Messages[message.ID] = message
	} else {
		c.AddMessage(message)
	}
}
func (c *Chat) IsNewThread(parentID string) bool {
	if parent, ok := c.Messages[parentID]; ok {
		if len(parent.Messages) > 0 {
			return true
		}
	}
	return false
}