diff --git a/internal/ui/chat/messageslist/model.go b/internal/ui/chat/messageslist/model.go index 84d560b..77111c1 100644 --- a/internal/ui/chat/messageslist/model.go +++ b/internal/ui/chat/messageslist/model.go @@ -37,10 +37,10 @@ import ( ) type messageItem struct { - message discord.Message - view tview.Widget + message discord.Message + view tview.Widget + // A separator shows the date of the message after it. separator bool - timestamp discord.Timestamp // A preview is blank while loading and empty if loading failed. previews map[discord.URL]tviewimage.Widget @@ -197,7 +197,7 @@ func (ml *Model) setMessages(messages []discord.Message) { func (ml *Model) AddMessage(message discord.Message) tview.Cmd { // Appending keeps the items before it as they are, so only the separator of a new day is added rather than all rebuilt. if ml.cfg.DateSeparator.Enabled && (len(ml.items) == 0 || !sameLocalDate(ml.items[len(ml.items)-1].message.Timestamp, message.Timestamp)) { - ml.items = append(ml.items, messageItem{separator: true, timestamp: message.Timestamp}) + ml.items = append(ml.items, messageItem{separator: true}) } ml.items = append(ml.items, messageItem{message: message}) return ml.loadPreviews() @@ -242,7 +242,7 @@ func (ml *Model) buildItem(index int) tview.Widget { } item := &ml.items[index] if item.separator { - date := item.timestamp.Time().In(time.Local).Format(ml.cfg.DateSeparator.Format) + date := ml.items[index+1].message.Timestamp.Time().In(time.Local).Format(ml.cfg.DateSeparator.Format) return dateSeparator{date: date, fill: ml.cfg.DateSeparator.Character, style: ml.cfg.Theme.MessagesList.MessageStyle.Style.Dim(true)} } @@ -351,7 +351,7 @@ func (ml *Model) rebuildItems() { continue } if ml.cfg.DateSeparator.Enabled && (len(items) == 0 || !sameLocalDate(previous, item.message.Timestamp)) { - items = append(items, messageItem{separator: true, timestamp: item.message.Timestamp}) + items = append(items, messageItem{separator: true}) } if i == cursor { selected = len(items) diff --git a/internal/ui/chat/messageslist/model_test.go b/internal/ui/chat/messageslist/model_test.go index a8a5d4f..9386d28 100644 --- a/internal/ui/chat/messageslist/model_test.go +++ b/internal/ui/chat/messageslist/model_test.go @@ -93,8 +93,8 @@ func TestModelRebuildItems(t *testing.T) { var got []discord.MessageID for i, item := range ml.items { if item.separator { - if !tt.separators || i+1 == len(ml.items) || ml.items[i+1].separator || item.timestamp != ml.items[i+1].message.Timestamp { - t.Fatalf("item %d: orphaned or incorrect separator", i) + if !tt.separators || i+1 == len(ml.items) || ml.items[i+1].separator { + t.Fatalf("item %d: orphaned separator", i) } } else { got = append(got, item.message.ID)