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-02 09:24:14 +00:00
|
|
|
c := container.NewListContainer(constructor{}, ctrl)
|
2020-06-13 07:29:32 +00:00
|
|
|
primitives.AddClass(c, "compact-conatainer")
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-06-07 04:27:28 +00:00
|
|
|
type constructor struct{}
|
|
|
|
|
2021-01-02 09:24:14 +00:00
|
|
|
func (constructor) NewMessage(msg cchat.MessageCreate) container.MessageRow {
|
2020-06-06 07:44:36 +00:00
|
|
|
return NewMessage(msg)
|
|
|
|
}
|
|
|
|
|
2021-01-02 09:24:14 +00:00
|
|
|
func (constructor) NewPresendMessage(msg input.PresendMessage) container.PresendMessageRow {
|
2020-06-06 07:44:36 +00:00
|
|
|
return NewPresendMessage(msg)
|
|
|
|
}
|