Optimized counter increment logic for 1-1 chat messages (#3845)
* Optimized counter increment logic for 1-1 chat messages * Fix * Style fix * Bugfix
This commit is contained in:
parent
9896ec817b
commit
e762cf4b9e
|
@ -39,6 +39,13 @@ 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")
|
||||
|
@ -396,7 +403,7 @@ func (m *Messenger) handleCommandMessage(state *ReceivedMessageState, message *c
|
|||
|
||||
// Increase unviewed count
|
||||
if !common.IsPubKeyEqual(message.SigPubKey, &m.identity.PublicKey) {
|
||||
m.updateUnviewedCounts(chat, message.Mentioned || message.Replied)
|
||||
m.updateUnviewedCounts(chat, message)
|
||||
message.OutgoingStatus = ""
|
||||
} else {
|
||||
// Our own message, mark as sent
|
||||
|
@ -2045,7 +2052,7 @@ func (m *Messenger) handleChatMessage(state *ReceivedMessageState, forceSeen boo
|
|||
}
|
||||
}
|
||||
if !skipUpdateUnviewedCountForAlbums {
|
||||
m.updateUnviewedCounts(chat, receivedMessage.Mentioned || receivedMessage.Replied)
|
||||
m.updateUnviewedCounts(chat, receivedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2996,9 +3003,14 @@ func (m *Messenger) isMessageAllowedFrom(publicKey string, chat *Chat) (bool, er
|
|||
return contact.added(), nil
|
||||
}
|
||||
|
||||
func (m *Messenger) updateUnviewedCounts(chat *Chat, mentionedOrReplied bool) {
|
||||
chat.UnviewedMessagesCount++
|
||||
if mentionedOrReplied {
|
||||
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 {
|
||||
chat.UnviewedMentionsCount++
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue