aboutsummaryrefslogtreecommitdiff
path: root/ui/widget
diff options
context:
space:
mode:
Diffstat (limited to 'ui/widget')
-rw-r--r--ui/widget/message-view.go24
-rw-r--r--ui/widget/room-view.go2
2 files changed, 18 insertions, 8 deletions
diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go
index 14d026a..78d37c1 100644
--- a/ui/widget/message-view.go
+++ b/ui/widget/message-view.go
@@ -42,7 +42,7 @@ type MessageView struct {
prevHeight int
prevMsgCount int
- messageIDs map[string]bool
+ messageIDs map[string]*types.Message
messages []*types.Message
textBuffer []string
@@ -60,7 +60,7 @@ func NewMessageView() *MessageView {
ScrollOffset: 0,
messages: make([]*types.Message, 0),
- messageIDs: make(map[string]bool),
+ messageIDs: make(map[string]*types.Message),
textBuffer: make([]string, 0),
metaBuffer: make([]types.MessageMeta, 0),
@@ -87,15 +87,25 @@ func (view *MessageView) updateWidestSender(sender string) {
}
}
+type MessageDirection int
+
const (
- AppendMessage = iota
+ AppendMessage MessageDirection = iota
PrependMessage
+ IgnoreMessage
)
-func (view *MessageView) AddMessage(message *types.Message, direction int) {
- _, messageExists := view.messageIDs[message.ID]
+func (view *MessageView) UpdateMessageID(message *types.Message, newID string) {
+ delete(view.messageIDs, message.ID)
+ message.ID = newID
+ view.messageIDs[message.ID] = message
+}
+
+func (view *MessageView) AddMessage(message *types.Message, direction MessageDirection) {
+ msg, messageExists := view.messageIDs[message.ID]
if messageExists {
- return
+ message.CopyTo(msg)
+ direction = IgnoreMessage
}
view.updateWidestSender(message.Sender)
@@ -114,7 +124,7 @@ func (view *MessageView) AddMessage(message *types.Message, direction int) {
view.messages = append([]*types.Message{message}, view.messages...)
}
- view.messageIDs[message.ID] = true
+ view.messageIDs[message.ID] = message
}
func (view *MessageView) appendBuffer(message *types.Message) {
diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go
index 316fcef..b103490 100644
--- a/ui/widget/room-view.go
+++ b/ui/widget/room-view.go
@@ -147,6 +147,6 @@ func (view *RoomView) NewMessage(id, sender, text string, timestamp time.Time) *
return view.content.NewMessage(id, sender, text, timestamp)
}
-func (view *RoomView) AddMessage(message *types.Message, direction int) {
+func (view *RoomView) AddMessage(message *types.Message, direction MessageDirection) {
view.content.AddMessage(message, direction)
}