From cfcf6469d6cb72855b297dbf1dcb6a1ab93e3a08 Mon Sep 17 00:00:00 2001 From: erroneousboat Date: Sat, 15 Jun 2019 12:45:01 +0200 Subject: [PATCH] Check for parent id when receiving replies Reference #193 --- components/chat.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/chat.go b/components/chat.go index 58581ba..6dc28e5 100644 --- a/components/chat.go +++ b/components/chat.go @@ -185,8 +185,14 @@ func (c *Chat) AddMessage(message Message) { // AddReply adds a single reply to a parent thread, it also sets // the thread separator func (c *Chat) AddReply(parentID string, message Message) { - message.Thread = " " - c.Messages[parentID].Messages[message.ID] = message + // It is possible that a message is received but the parent is not + // present in the chat view + if _, ok := c.Messages[parentID]; ok { + message.Thread = " " + c.Messages[parentID].Messages[message.ID] = message + } else { + c.AddMessage(message) + } } // ClearMessages clear the c.Messages