This commit is contained in:
diamondburned (Forefront) 2020-07-05 17:19:48 -07:00
parent 3cb3ad9852
commit 10e8a58bea
4 changed files with 24 additions and 14 deletions

View File

@ -8,7 +8,6 @@ import (
"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/diamondburned/cchat-gtk/internal/ui/rich"
"github.com/gotk3/gotk3/gtk"
)
@ -44,7 +43,7 @@ func (c *CollapsedMessage) Collapsed() bool { return true }
func (c *CollapsedMessage) UpdateTimestamp(t time.Time) {
c.GenericContainer.UpdateTimestamp(t)
c.Timestamp.SetMarkup(rich.Small(humanize.TimeAgoShort(t)))
c.Timestamp.SetText(humanize.TimeAgoShort(t))
}
func (c *CollapsedMessage) Unwrap(grid *gtk.Grid) *message.GenericContainer {

View File

@ -10,7 +10,6 @@ import (
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/message"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
"github.com/diamondburned/cchat-gtk/internal/ui/rich"
"github.com/diamondburned/cchat-gtk/internal/ui/service/menu"
"github.com/diamondburned/imgutil"
"github.com/gotk3/gotk3/gtk"
@ -40,6 +39,10 @@ var (
_ container.GridMessage = (*FullMessage)(nil)
)
var boldCSS = primitives.PrepareCSS(`
* { font-weight: 600; }
`)
func NewFullMessage(msg cchat.MessageCreate) *FullMessage {
msgc := WrapFullMessage(message.NewContainer(msg))
// Don't update the avatar. NewMessage in controller will try and reuse the
@ -64,6 +67,9 @@ func WrapFullMessage(gc *message.GenericContainer) *FullMessage {
// Attach the class for the left avatar.
primitives.AddClass(avatar, "cozy-avatar")
// Attach the username style provider.
primitives.AttachCSS(gc.Username, boldCSS)
header, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
header.PackStart(gc.Username, false, false, 0)
header.PackStart(gc.Timestamp, false, false, 7) // padding
@ -101,7 +107,7 @@ func (m *FullMessage) Unwrap(grid *gtk.Grid) *message.GenericContainer {
func (m *FullMessage) UpdateTimestamp(t time.Time) {
m.GenericContainer.UpdateTimestamp(t)
m.Timestamp.SetMarkup(rich.Small(humanize.TimeAgoLong(t)))
m.Timestamp.SetText(humanize.TimeAgoLong(t))
}
func (m *FullMessage) UpdateAuthor(author cchat.MessageAuthor) {

View File

@ -61,6 +61,15 @@ type GenericContainer struct {
var _ Container = (*GenericContainer)(nil)
var timestampCSS = primitives.PrepareCSS(`
.message-time {
opacity: 0.3;
font-size: 0.8em;
margin-top: 0.2em;
margin-bottom: 0.2em;
}
`)
// NewContainer creates a new message container with the given ID and nonce. It
// does not update the widgets, so FillContainer should be called afterwards.
func NewContainer(msg cchat.MessageCreate) *GenericContainer {
@ -105,6 +114,9 @@ func NewEmptyContainer() *GenericContainer {
primitives.AddClass(user, "message-author")
primitives.AddClass(content, "message-content")
// Attach the timestamp CSS.
primitives.AttachCSS(ts, timestampCSS)
gc := &GenericContainer{
Timestamp: ts,
Username: user,
@ -145,7 +157,7 @@ func (m *GenericContainer) Nonce() string {
func (m *GenericContainer) UpdateTimestamp(t time.Time) {
m.time = t
m.Timestamp.SetMarkup(rich.Small(humanize.TimeAgo(t)))
m.Timestamp.SetText(humanize.TimeAgo(t))
m.Timestamp.SetTooltipText(t.Format(time.Stamp))
}
@ -170,13 +182,6 @@ func (m *GenericContainer) UpdateContent(content text.Rich, edited bool) {
}
m.Content.SetMarkup(markup)
// // Render the content.
// parser.RenderTextBuffer(m.CBuffer, content)
// if edited {
// parser.AppendEditBadge(m.CBuffer, m.Time())
// }
}
// AttachMenu connects signal handlers to handle a list of menu items from

View File

@ -109,9 +109,9 @@ func render(typers []cchat.Typer) string {
}
if len(typers) == 1 {
builder.WriteString(" is typing.")
builder.WriteString(" is typing...")
} else {
builder.WriteString(" are typing.")
builder.WriteString(" are typing...")
}
return builder.String()