1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-01 12:04:15 +00:00
cchat-gtk/internal/ui/messages/container/cozy/message_collapsed.go

75 lines
2.1 KiB
Go
Raw Normal View History

2020-06-07 04:27:28 +00:00
package cozy
import (
2020-06-28 23:01:08 +00:00
"time"
"github.com/diamondburned/cchat"
2020-06-28 23:01:08 +00:00
"github.com/diamondburned/cchat-gtk/internal/humanize"
"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"
)
// Collapsed is a message that follows after FullMessage. It does not show
2020-06-07 04:27:28 +00:00
// the header, and the avatar is invisible.
type CollapsedMessage struct {
// Author is still updated normally.
*message.GenericContainer
}
func NewCollapsedMessage(msg cchat.MessageCreate) *CollapsedMessage {
msgc := WrapCollapsedMessage(message.NewContainer(msg))
message.FillContainer(msgc, msg)
return msgc
}
func WrapCollapsedMessage(gc *message.GenericContainer) *CollapsedMessage {
// Set Timestamp's padding accordingly to Avatar's.
gc.Timestamp.SetSizeRequest(AvatarSize, -1)
gc.Timestamp.SetVAlign(gtk.ALIGN_START)
2020-06-29 02:55:13 +00:00
gc.Timestamp.SetXAlign(0.5) // middle align
gc.Timestamp.SetMarginStart(container.ColumnSpacing * 2)
// Set Content's padding accordingly to FullMessage's main box.
gc.Content.SetMarginEnd(container.ColumnSpacing * 2)
return &CollapsedMessage{
GenericContainer: gc,
}
}
func (c *CollapsedMessage) Collapsed() bool { return true }
2020-06-28 23:01:08 +00:00
func (c *CollapsedMessage) UpdateTimestamp(t time.Time) {
c.GenericContainer.UpdateTimestamp(t)
2020-07-06 00:19:48 +00:00
c.Timestamp.SetText(humanize.TimeAgoShort(t))
2020-06-28 23:01:08 +00:00
}
func (c *CollapsedMessage) Unwrap(grid *gtk.Grid) *message.GenericContainer {
// Remove GenericContainer's widgets from the containers.
grid.Remove(c.Timestamp)
grid.Remove(c.Content)
// Return after removing.
return c.GenericContainer
}
func (c *CollapsedMessage) Attach(grid *gtk.Grid, row int) {
container.AttachRow(grid, row, c.Timestamp, c.Content)
}
type CollapsedSendingMessage struct {
2020-06-29 02:55:13 +00:00
*CollapsedMessage
message.PresendContainer
}
func NewCollapsedSendingMessage(msg input.PresendMessage) *CollapsedSendingMessage {
var msgc = message.NewPresendContainer(msg)
2020-06-07 04:27:28 +00:00
return &CollapsedSendingMessage{
2020-06-29 02:55:13 +00:00
CollapsedMessage: WrapCollapsedMessage(msgc.GenericContainer),
PresendContainer: msgc,
}
2020-06-07 04:27:28 +00:00
}