1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-16 19:22:51 +00:00
cchat-gtk/internal/ui/messages/container/compact/compact.go

52 lines
1.3 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 {
2021-01-05 02:05:33 +00:00
c := container.NewListContainer(ctrl, constructors)
primitives.AddClass(c, "compact-container")
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) })
}
2021-01-05 02:05:33 +00:00
var constructors = container.Constructor{
NewMessage: newMessage,
NewPresendMessage: newPresendMessage,
}
func newMessage(
msg cchat.MessageCreate, _ container.MessageRow) container.MessageRow {
2020-06-07 04:27:28 +00:00
2020-06-06 07:44:36 +00:00
return NewMessage(msg)
}
2021-01-05 02:05:33 +00:00
func newPresendMessage(
msg input.PresendMessage, _ container.MessageRow) container.PresendMessageRow {
2020-06-06 07:44:36 +00:00
return NewPresendMessage(msg)
}