2020-06-06 07:44:36 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/cchat"
|
2020-11-05 19:08:30 +00:00
|
|
|
"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"
|
2020-06-13 07:29:32 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
|
2020-06-06 07:44:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Container struct {
|
2021-01-02 09:24:14 +00:00
|
|
|
*container.ListContainer
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:29:32 +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")
|
2020-06-13 07:29:32 +00:00
|
|
|
return &Container{c}
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:08:30 +00:00
|
|
|
func (c *Container) CreateMessage(msg cchat.MessageCreate) {
|
2020-11-06 03:23:06 +00:00
|
|
|
gts.ExecAsync(func() {
|
2021-01-02 09:24:14 +00:00
|
|
|
c.ListContainer.CreateMessageUnsafe(msg)
|
|
|
|
c.ListContainer.CleanMessages()
|
2020-11-06 03:23:06 +00:00
|
|
|
})
|
2020-11-05 19:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) UpdateMessage(msg cchat.MessageUpdate) {
|
2021-01-02 09:24:14 +00:00
|
|
|
gts.ExecAsync(func() { c.ListContainer.UpdateMessageUnsafe(msg) })
|
2020-11-05 19:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) DeleteMessage(msg cchat.MessageDelete) {
|
2021-01-02 09:24:14 +00:00
|
|
|
gts.ExecAsync(func() { c.ListContainer.DeleteMessageUnsafe(msg) })
|
2020-11-05 19:08:30 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|