2020-06-06 07:44:36 +00:00
|
|
|
package compact
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/cchat"
|
|
|
|
"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/messages/message"
|
|
|
|
"github.com/gotk3/gotk3/gtk"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PresendMessage struct {
|
2020-06-07 04:27:28 +00:00
|
|
|
message.PresendContainer
|
|
|
|
Message
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPresendMessage(msg input.PresendMessage) PresendMessage {
|
2020-06-07 04:27:28 +00:00
|
|
|
var msgc = message.NewPresendContainer(msg)
|
|
|
|
|
2020-06-06 07:44:36 +00:00
|
|
|
return PresendMessage{
|
2020-06-07 04:27:28 +00:00
|
|
|
PresendContainer: msgc,
|
|
|
|
Message: Message{msgc.GenericContainer},
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
*message.GenericContainer
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ container.GridMessage = (*Message)(nil)
|
|
|
|
|
|
|
|
func NewMessage(msg cchat.MessageCreate) Message {
|
2020-06-07 04:27:28 +00:00
|
|
|
msgc := message.NewContainer(msg)
|
|
|
|
message.FillContainer(msgc, msg)
|
|
|
|
return Message{msgc}
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmptyMessage() Message {
|
2020-06-07 04:27:28 +00:00
|
|
|
return Message{message.NewEmptyContainer()}
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: fix a bug here related to new messages overlapping
|
|
|
|
func (m Message) Attach(grid *gtk.Grid, row int) {
|
|
|
|
attachGenericContainer(m.GenericContainer, grid, row)
|
|
|
|
}
|
|
|
|
|
|
|
|
func attachGenericContainer(m *message.GenericContainer, grid *gtk.Grid, row int) {
|
2020-06-07 04:27:28 +00:00
|
|
|
container.AttachRow(grid, row, m.Timestamp, m.Username, m.Content)
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|