2020-06-07 04:27:28 +00:00
|
|
|
package cozy
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
import (
|
2020-06-28 23:01:08 +00:00
|
|
|
"time"
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
"github.com/diamondburned/cchat"
|
2020-06-28 23:01:08 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/humanize"
|
2020-06-13 07:29:32 +00:00
|
|
|
"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.
|
2020-06-13 07:29:32 +00:00
|
|
|
type CollapsedMessage struct {
|
|
|
|
// Author is still updated normally.
|
|
|
|
*message.GenericContainer
|
2021-01-05 02:05:33 +00:00
|
|
|
Timestamp *gtk.Label
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2021-01-05 02:05:33 +00:00
|
|
|
ts := message.NewTimestamp()
|
|
|
|
ts.SetSizeRequest(AvatarSize, -1)
|
|
|
|
ts.SetVAlign(gtk.ALIGN_START)
|
|
|
|
ts.SetXAlign(0.5) // middle align
|
|
|
|
ts.SetMarginEnd(container.ColumnSpacing)
|
|
|
|
ts.SetMarginStart(container.ColumnSpacing * 2)
|
2020-06-13 07:29:32 +00:00
|
|
|
|
|
|
|
// Set Content's padding accordingly to FullMessage's main box.
|
2020-07-10 23:26:07 +00:00
|
|
|
gc.Content.ToWidget().SetMarginEnd(container.ColumnSpacing * 2)
|
2020-06-13 07:29:32 +00:00
|
|
|
|
2021-01-05 02:05:33 +00:00
|
|
|
gc.PackStart(ts, false, false, 0)
|
2021-01-02 09:24:14 +00:00
|
|
|
gc.PackStart(gc.Content, true, true, 0)
|
|
|
|
gc.SetClass("cozy-collapsed")
|
2020-12-31 03:00:00 +00:00
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
return &CollapsedMessage{
|
|
|
|
GenericContainer: gc,
|
2021-01-05 02:05:33 +00:00
|
|
|
Timestamp: ts,
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-13 21:51:03 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-02 09:24:14 +00:00
|
|
|
func (c *CollapsedMessage) Unwrap() *message.GenericContainer {
|
2020-06-13 07:29:32 +00:00
|
|
|
// Remove GenericContainer's widgets from the containers.
|
2021-01-02 09:24:14 +00:00
|
|
|
c.Remove(c.Timestamp)
|
|
|
|
c.Remove(c.Content)
|
2020-06-13 07:29:32 +00:00
|
|
|
|
|
|
|
// Return after removing.
|
|
|
|
return c.GenericContainer
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollapsedSendingMessage struct {
|
2020-06-29 02:55:13 +00:00
|
|
|
*CollapsedMessage
|
2020-06-13 07:29:32 +00:00
|
|
|
message.PresendContainer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCollapsedSendingMessage(msg input.PresendMessage) *CollapsedSendingMessage {
|
|
|
|
var msgc = message.NewPresendContainer(msg)
|
2020-06-07 04:27:28 +00:00
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
return &CollapsedSendingMessage{
|
2020-06-29 02:55:13 +00:00
|
|
|
CollapsedMessage: WrapCollapsedMessage(msgc.GenericContainer),
|
2020-06-13 07:29:32 +00:00
|
|
|
PresendContainer: msgc,
|
|
|
|
}
|
2020-06-07 04:27:28 +00:00
|
|
|
}
|