1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-01 12:04:15 +00:00
cchat-gtk/internal/ui/messages/container/compact/compact.go

45 lines
1.2 KiB
Go
Raw Normal View History

2020-06-06 07:44:36 +00:00
package compact
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/gts"
2020-06-06 07:44:36 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
2020-06-06 07:44:36 +00:00
)
type Container struct {
*container.ListContainer
2020-06-06 07:44:36 +00:00
}
func NewContainer(ctrl container.Controller) *Container {
c := container.NewListContainer(constructor{}, ctrl)
primitives.AddClass(c, "compact-conatainer")
return &Container{c}
2020-06-06 07:44:36 +00:00
}
func (c *Container) CreateMessage(msg cchat.MessageCreate) {
2020-11-06 03:23:06 +00:00
gts.ExecAsync(func() {
c.ListContainer.CreateMessageUnsafe(msg)
c.ListContainer.CleanMessages()
2020-11-06 03:23:06 +00:00
})
}
func (c *Container) UpdateMessage(msg cchat.MessageUpdate) {
gts.ExecAsync(func() { c.ListContainer.UpdateMessageUnsafe(msg) })
}
func (c *Container) DeleteMessage(msg cchat.MessageDelete) {
gts.ExecAsync(func() { c.ListContainer.DeleteMessageUnsafe(msg) })
}
2020-06-07 04:27:28 +00:00
type constructor struct{}
func (constructor) NewMessage(msg cchat.MessageCreate) container.MessageRow {
2020-06-06 07:44:36 +00:00
return NewMessage(msg)
}
func (constructor) NewPresendMessage(msg input.PresendMessage) container.PresendMessageRow {
2020-06-06 07:44:36 +00:00
return NewPresendMessage(msg)
}