fix(edits): mark edits as Mentioned if the og message was not a mention

Marks Edit messages as Mentioned when the original message was not Mentioned and the Edit is, so that we increase the unviewed count only once
This commit is contained in:
Jonathan Rainville 2023-03-30 15:37:41 -04:00
parent 7c2b5a39b3
commit 4f013cc7af
1 changed files with 10 additions and 0 deletions

View File

@ -1469,6 +1469,8 @@ func (m *Messenger) HandleEditMessage(state *ReceivedMessageState, editMessage E
return m.persistence.SaveEdit(editMessage) return m.persistence.SaveEdit(editMessage)
} }
originalMessageMentioned := originalMessage.Mentioned
chat, ok := m.allChats.Load(originalMessage.LocalChatID) chat, ok := m.allChats.Load(originalMessage.LocalChatID)
if !ok { if !ok {
return errors.New("chat not found") return errors.New("chat not found")
@ -1507,6 +1509,14 @@ func (m *Messenger) HandleEditMessage(state *ReceivedMessageState, editMessage E
if err != nil { if err != nil {
return err return err
} }
editedMessageHasMentions := originalMessage.Mentioned
if editedMessageHasMentions && !originalMessageMentioned && !originalMessage.Seen {
// Increase unviewed count when the edited message has a mention and didn't have one before
m.updateUnviewedCounts(chat, originalMessage.Mentioned || originalMessage.Replied)
}
state.Response.AddMessage(originalMessage) state.Response.AddMessage(originalMessage)
state.Response.AddChat(chat) state.Response.AddChat(chat)