Optimized counter increment logic for 1-1 chat messages (#3889)
* Optimized counter increment logic for 1-1 chat messages * Updated * Updated condition
This commit is contained in:
parent
5c7748dbf7
commit
717e0f9ba5
|
@ -632,6 +632,17 @@ func (m *Message) PrepareContent(identity string) error {
|
|||
return m.parseAudio()
|
||||
}
|
||||
|
||||
func (m *Message) IsSystemMessage() bool {
|
||||
return m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_CONTENT_PRIVATE_GROUP ||
|
||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_GAP ||
|
||||
m.ContentType == protobuf.ChatMessage_CONTACT_REQUEST ||
|
||||
m.ContentType == protobuf.ChatMessage_IDENTITY_VERIFICATION ||
|
||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_PINNED_MESSAGE ||
|
||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_MUTUAL_EVENT_SENT ||
|
||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_MUTUAL_EVENT_ACCEPTED ||
|
||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_MUTUAL_EVENT_REMOVED
|
||||
}
|
||||
|
||||
// GetSimplifiedText returns a the text stripped of all the markdown and with mentions
|
||||
// replaced by canonical names
|
||||
func (m *Message) GetSimplifiedText(identity string, canonicalNames map[string]string) (string, error) {
|
||||
|
|
|
@ -40,6 +40,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")
|
||||
|
@ -413,7 +420,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
|
||||
|
@ -2120,7 +2127,7 @@ func (m *Messenger) handleChatMessage(state *ReceivedMessageState, forceSeen boo
|
|||
}
|
||||
}
|
||||
if !skipUpdateUnviewedCountForAlbums {
|
||||
m.updateUnviewedCounts(chat, receivedMessage.Mentioned || receivedMessage.Replied)
|
||||
m.updateUnviewedCounts(chat, receivedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3075,9 +3082,17 @@ 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 ||
|
||||
chat.LastMessage.IsSystemMessage() ||
|
||||
!chat.LastMessage.New ||
|
||||
message.Timestamp > chat.LastMessage.Timestamp+IncreaseUnviewedMessagesCountTimeout {
|
||||
chat.UnviewedMessagesCount++
|
||||
}
|
||||
if message.Mentioned || message.Replied {
|
||||
chat.UnviewedMentionsCount++
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue