mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2024-11-17 03:32:56 +00:00
49 lines
1.3 KiB
Go
49 lines
1.3 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.addMessage(msg)
|
|
c.CleanMessages()
|
|
})
|
|
}
|
|
|
|
func (c *Container) addMessage(msg container.MessageRow) {
|
|
_, at := container.InsertPosition(c, msg.Unwrap().Time)
|
|
c.AddMessageAt(msg, at)
|
|
}
|
|
|
|
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()) })
|
|
}
|