1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-17 03:32:56 +00:00
cchat-gtk/internal/ui/messages/container/compact/compact.go

43 lines
1.1 KiB
Go

package compact
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/gts"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/message"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
)
type Container struct {
*container.ListContainer
}
var _ container.Container = (*Container)(nil)
func NewContainer(ctrl container.Controller) *Container {
c := container.NewListContainer(ctrl)
primitives.AddClass(c, "compact-container")
return &Container{c}
}
func (c *Container) NewPresendMessage(state *message.PresendState) container.PresendMessageRow {
msg := WrapPresendMessage(state)
c.AddMessage(msg)
return msg
}
func (c *Container) CreateMessage(msg cchat.MessageCreate) {
gts.ExecAsync(func() {
msg := WrapMessage(message.NewState(msg))
c.ListContainer.AddMessage(msg)
})
}
func (c *Container) UpdateMessage(msg cchat.MessageUpdate) {
gts.ExecAsync(func() { container.UpdateMessage(c, msg) })
}
func (c *Container) DeleteMessage(msg cchat.MessageDelete) {
gts.ExecAsync(func() { c.PopMessage(msg.ID()) })
}