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"
|
2021-01-02 09:24:14 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
|
2020-06-06 07:44:36 +00:00
|
|
|
"github.com/gotk3/gotk3/gtk"
|
2021-01-02 09:24:14 +00:00
|
|
|
"github.com/gotk3/gotk3/pango"
|
2020-06-06 07:44:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2021-01-02 09:24:14 +00:00
|
|
|
msgc := message.NewPresendContainer(msg)
|
|
|
|
attachCompact(msgc.GenericContainer)
|
2020-06-07 04:27:28 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-01-02 09:24:14 +00:00
|
|
|
var _ container.MessageRow = (*Message)(nil)
|
2020-06-06 07:44:36 +00:00
|
|
|
|
|
|
|
func NewMessage(msg cchat.MessageCreate) Message {
|
2020-06-07 04:27:28 +00:00
|
|
|
msgc := message.NewContainer(msg)
|
2021-01-02 09:24:14 +00:00
|
|
|
attachCompact(msgc)
|
2020-06-07 04:27:28 +00:00
|
|
|
message.FillContainer(msgc, msg)
|
2020-06-13 07:29:32 +00:00
|
|
|
|
2020-06-07 04:27:28 +00:00
|
|
|
return Message{msgc}
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmptyMessage() Message {
|
2021-01-02 09:24:14 +00:00
|
|
|
ct := message.NewEmptyContainer()
|
|
|
|
attachCompact(ct)
|
|
|
|
|
|
|
|
return Message{ct}
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 09:24:14 +00:00
|
|
|
var messageTimeCSS = primitives.PrepareClassCSS("message-time", `
|
|
|
|
.message-time {
|
|
|
|
margin-left: 1em;
|
|
|
|
margin-right: 1em;
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
var messageAuthorCSS = primitives.PrepareClassCSS("message-author", `
|
|
|
|
.message-author {
|
|
|
|
margin-right: 0.5em;
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
func attachCompact(container *message.GenericContainer) {
|
|
|
|
container.Timestamp.SetVAlign(gtk.ALIGN_START)
|
|
|
|
container.Username.SetMaxWidthChars(25)
|
|
|
|
container.Username.SetEllipsize(pango.ELLIPSIZE_NONE)
|
|
|
|
container.Username.SetLineWrap(true)
|
|
|
|
container.Username.SetLineWrapMode(pango.WRAP_WORD_CHAR)
|
|
|
|
|
|
|
|
messageTimeCSS(container.Timestamp)
|
|
|
|
messageAuthorCSS(container.Username)
|
|
|
|
|
|
|
|
container.PackStart(container.Timestamp, false, false, 0)
|
|
|
|
container.PackStart(container.Username, false, false, 0)
|
|
|
|
container.PackStart(container.Content, true, true, 0)
|
|
|
|
container.SetClass("compact")
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|