diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-20 19:14:39 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-20 19:55:42 +0200 |
commit | 095b982603c26e250e61cf006157019e2b55be74 (patch) | |
tree | 080644e83572b0dff33e77fbad5e2301243fd5ab /ui/widget | |
parent | 59cd9003013aa62495d2a73c28f22fd7e64f861a (diff) |
Show messages in message view while sending
Diffstat (limited to 'ui/widget')
-rw-r--r-- | ui/widget/message-view.go | 24 | ||||
-rw-r--r-- | ui/widget/room-view.go | 2 |
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) } |