Skip to content

Commit

Permalink
Revert "Optimized counter increment logic for 1-1 chat messages (#3845)"
Browse files Browse the repository at this point in the history
This reverts commit e762cf4.
  • Loading branch information
cammellos committed Aug 11, 2023
1 parent daa9ad4 commit abcab23
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions protocol/messenger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ const (
requestAddressForTransactionDeclinedMessage = "Request address for transaction declined"
)

const (
// IncreaseUnviewedMessagesCountTimeout
// this timeout indicates how long the time between received messages should be
// for a new message to increase the unviewed messages counter
IncreaseUnviewedMessagesCountTimeout = 1000 * 60 * 2
)

var (
ErrMessageNotAllowed = errors.New("message from a non-contact")
ErrMessageForWrongChatType = errors.New("message for the wrong chat type")
Expand Down Expand Up @@ -403,7 +396,7 @@ func (m *Messenger) handleCommandMessage(state *ReceivedMessageState, message *c

// Increase unviewed count
if !common.IsPubKeyEqual(message.SigPubKey, &m.identity.PublicKey) {
m.updateUnviewedCounts(chat, message)
m.updateUnviewedCounts(chat, message.Mentioned || message.Replied)
message.OutgoingStatus = ""
} else {
// Our own message, mark as sent
Expand Down Expand Up @@ -2052,7 +2045,7 @@ func (m *Messenger) handleChatMessage(state *ReceivedMessageState, forceSeen boo
}
}
if !skipUpdateUnviewedCountForAlbums {
m.updateUnviewedCounts(chat, receivedMessage)
m.updateUnviewedCounts(chat, receivedMessage.Mentioned || receivedMessage.Replied)
}
}

Expand Down Expand Up @@ -3003,14 +2996,9 @@ func (m *Messenger) isMessageAllowedFrom(publicKey string, chat *Chat) (bool, er
return contact.added(), nil
}

func (m *Messenger) updateUnviewedCounts(chat *Chat, message *common.Message) {
if chat == nil {
return
}
if chat.LastMessage == nil || message.Timestamp > chat.LastMessage.Timestamp+IncreaseUnviewedMessagesCountTimeout {
chat.UnviewedMessagesCount++
}
if message.Mentioned || message.Replied {
func (m *Messenger) updateUnviewedCounts(chat *Chat, mentionedOrReplied bool) {
chat.UnviewedMessagesCount++
if mentionedOrReplied {
chat.UnviewedMentionsCount++
}
}
Expand Down

0 comments on commit abcab23

Please sign in to comment.