Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Optimized counter increment logic for 1-1 chat messages" #4059

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions protocol/common/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,6 @@ 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) {
Expand Down
25 changes: 5 additions & 20 deletions protocol/messenger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,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 @@ -420,7 +413,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 @@ -2127,7 +2120,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 @@ -3082,17 +3075,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 ||
chat.LastMessage.IsSystemMessage() ||
!chat.LastMessage.New ||
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