Optimize chatview, new messages don't cause a complete reparse of all messages anymore
MODIFY
internal/ui/chatview.go
internal/ui/chatview.go
@@ -69,11 +69,10 @@ func (chatView *ChatView) GetPrimitive() tview.Primitive {
return chatView.internalTextView
}
-// SetMessages defines all currently displayed messages. Parsing and
-// manipulation of single message elements happens in this function.
-func (chatView *ChatView) SetMessages(messages []*discordgo.Message) {
+//AddMessages adds additional messages to the ChatView.
+func (chatView *ChatView) AddMessages(messages []*discordgo.Message) {
wasScrolledToTheEnd := chatView.internalTextView.IsScrolledToEnd()
- chatView.data = messages
+ chatView.data = append(chatView.data, messages...)
newText := ""
@@ -218,10 +217,18 @@ func (chatView *ChatView) SetMessages(messages []*discordgo.Message) {
}
}
- chatView.internalTextView.SetText("")
fmt.Fprint(chatView.internalTextView, newText)
if wasScrolledToTheEnd {
chatView.internalTextView.ScrollToEnd()
}
}
+
+// SetMessages defines all currently displayed messages. Parsing and
+// manipulation of single message elements happens in this function.
+func (chatView *ChatView) SetMessages(messages []*discordgo.Message) {
+ chatView.data = make([]*discordgo.Message, 0)
+ chatView.internalTextView.SetText("")
+
+ chatView.AddMessages(messages)
+}

MODIFY
internal/ui/window.go
internal/ui/window.go
@@ -494,7 +494,7 @@ func NewWindow(discord *discordgo.Session) (*Window, error) {
case message := <-messageInputChan:
if message.ChannelID == window.selectedChannel.ID {
window.app.QueueUpdateDraw(func() {
- window.SetMessages(append(window.shownMessages, message))
+ window.AddMessages([]*discordgo.Message{message})
})
} else {
mentionsYou := false
@@ -873,7 +873,7 @@ func (window *Window) LoadChannel(channel *discordgo.Channel) error {
//AddMessages adds the passed array of messages to the chat.
func (window *Window) AddMessages(messages []*discordgo.Message) {
- window.SetMessages(append(window.shownMessages, messages...))
+ window.chatView.AddMessages(messages)
}
//SetMessages clears the current chat and adds the passed messages.s

Optimize chatview, new messages don't cause a complete reparse of all messages anymore