feat: up mention count for 1-1 messages each 2 min (#4035)
This commit is contained in:
parent
ba5cd9c1a4
commit
2afe5a269d
|
@ -27,6 +27,13 @@ var chatColors = []string{
|
||||||
"#d37ef4", // purple
|
"#d37ef4", // purple
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// IncreaseUnviewedMessagesCountTimeoutMs
|
||||||
|
// this timeout indicates how long the time between received messages should be
|
||||||
|
// for a new message to increase the unviewed messages counter
|
||||||
|
IncreaseUnviewedMessagesCountTimeoutMs = 1000 * 60 * 2
|
||||||
|
)
|
||||||
|
|
||||||
type ChatType int
|
type ChatType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -391,6 +398,14 @@ func (c *Chat) UpdateFromMessage(message *common.Message, timesource common.Time
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Chat) ShouldIncreaseMessageCount(message *common.Message) bool {
|
||||||
|
return c.LastMessage == nil ||
|
||||||
|
c.LastMessage.IsSystemMessage() ||
|
||||||
|
!c.LastMessage.New ||
|
||||||
|
c.LastMessage.Seen ||
|
||||||
|
message.Timestamp > c.LastMessage.Timestamp+IncreaseUnviewedMessagesCountTimeoutMs
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Chat) UpdateFirstMessageTimestamp(timestamp uint32) bool {
|
func (c *Chat) UpdateFirstMessageTimestamp(timestamp uint32) bool {
|
||||||
if timestamp == c.FirstMessageTimestamp {
|
if timestamp == c.FirstMessageTimestamp {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -635,8 +635,6 @@ func (m *Message) PrepareContent(identity string) error {
|
||||||
func (m *Message) IsSystemMessage() bool {
|
func (m *Message) IsSystemMessage() bool {
|
||||||
return m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_CONTENT_PRIVATE_GROUP ||
|
return m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_CONTENT_PRIVATE_GROUP ||
|
||||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_GAP ||
|
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_PINNED_MESSAGE ||
|
||||||
m.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_MUTUAL_EVENT_SENT ||
|
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_ACCEPTED ||
|
||||||
|
|
|
@ -4108,6 +4108,10 @@ func (m *Messenger) markAllRead(chatID string, clock uint64, shouldBeSynced bool
|
||||||
chat.UnviewedMessagesCount = 0
|
chat.UnviewedMessagesCount = 0
|
||||||
chat.UnviewedMentionsCount = 0
|
chat.UnviewedMentionsCount = 0
|
||||||
|
|
||||||
|
if chat.LastMessage != nil {
|
||||||
|
chat.LastMessage.Seen = true
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(samyoul) remove storing of an updated reference pointer?
|
// TODO(samyoul) remove storing of an updated reference pointer?
|
||||||
m.allChats.Store(chat.ID, chat)
|
m.allChats.Store(chat.ID, chat)
|
||||||
return m.persistence.SaveChats([]*Chat{chat})
|
return m.persistence.SaveChats([]*Chat{chat})
|
||||||
|
|
|
@ -367,10 +367,10 @@ func (s *MessengerEditMessageSuite) TestEditMessageWithMention() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(response.Chats(), 1)
|
s.Require().Len(response.Chats(), 1)
|
||||||
s.Require().Len(response.Messages(), 1)
|
s.Require().Len(response.Messages(), 1)
|
||||||
// Make sure there is no mention at first
|
// Make sure the message is not marked as Mentioned (chat still counts it because it's 1-1)
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1)
|
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 0)
|
|
||||||
s.Require().False(response.Messages()[0].Mentioned)
|
s.Require().False(response.Messages()[0].Mentioned)
|
||||||
|
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1)
|
||||||
|
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 1)
|
||||||
|
|
||||||
ogMessage := sendResponse.Messages()[0]
|
ogMessage := sendResponse.Messages()[0]
|
||||||
|
|
||||||
|
@ -407,9 +407,9 @@ func (s *MessengerEditMessageSuite) TestEditMessageWithMention() {
|
||||||
s.Require().NotEmpty(response.Messages()[0].EditedAt)
|
s.Require().NotEmpty(response.Messages()[0].EditedAt)
|
||||||
s.Require().False(response.Messages()[0].New)
|
s.Require().False(response.Messages()[0].New)
|
||||||
// Receiver (us) is now mentioned
|
// Receiver (us) is now mentioned
|
||||||
|
s.Require().True(response.Messages()[0].Mentioned)
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1)
|
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1)
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 1)
|
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 1)
|
||||||
s.Require().True(response.Messages()[0].Mentioned)
|
|
||||||
|
|
||||||
// Edit the message again but remove the mention
|
// Edit the message again but remove the mention
|
||||||
editedText = "edited text no mention"
|
editedText = "edited text no mention"
|
||||||
|
@ -441,9 +441,9 @@ func (s *MessengerEditMessageSuite) TestEditMessageWithMention() {
|
||||||
s.Require().NotEmpty(response.Messages()[0].EditedAt)
|
s.Require().NotEmpty(response.Messages()[0].EditedAt)
|
||||||
s.Require().False(response.Messages()[0].New)
|
s.Require().False(response.Messages()[0].New)
|
||||||
// Receiver (us) is no longer mentioned
|
// Receiver (us) is no longer mentioned
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1) // We still have an unread message though
|
|
||||||
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 0)
|
|
||||||
s.Require().False(response.Messages()[0].Mentioned)
|
s.Require().False(response.Messages()[0].Mentioned)
|
||||||
|
s.Require().Equal(int(response.Chats()[0].UnviewedMessagesCount), 1) // We still have an unread message though
|
||||||
|
s.Require().Equal(int(response.Chats()[0].UnviewedMentionsCount), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessengerEditMessageSuite) TestEditMessageWithLinkPreviews() {
|
func (s *MessengerEditMessageSuite) TestEditMessageWithLinkPreviews() {
|
||||||
|
|
|
@ -40,13 +40,6 @@ const (
|
||||||
requestAddressForTransactionDeclinedMessage = "Request address for transaction declined"
|
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 (
|
var (
|
||||||
ErrMessageNotAllowed = errors.New("message from a non-contact")
|
ErrMessageNotAllowed = errors.New("message from a non-contact")
|
||||||
ErrMessageForWrongChatType = errors.New("message for the wrong chat type")
|
ErrMessageForWrongChatType = errors.New("message for the wrong chat type")
|
||||||
|
@ -1728,15 +1721,19 @@ func (m *Messenger) handleEditMessage(state *ReceivedMessageState, editMessage E
|
||||||
|
|
||||||
editedMessageHasMentions := editedMessage.Mentioned
|
editedMessageHasMentions := editedMessage.Mentioned
|
||||||
|
|
||||||
if editedMessageHasMentions && !originalMessageMentioned && !editedMessage.Seen {
|
// Messages in OneToOne chats increase the UnviewedMentionsCount whether or not they include a Mention
|
||||||
// Increase unviewed count when the edited message has a mention and didn't have one before
|
if !chat.OneToOne() {
|
||||||
chat.UnviewedMentionsCount++
|
if editedMessageHasMentions && !originalMessageMentioned && !editedMessage.Seen {
|
||||||
needToSaveChat = true
|
// Increase unviewed count when the edited message has a mention and didn't have one before
|
||||||
} else if !editedMessageHasMentions && originalMessageMentioned && !editedMessage.Seen {
|
chat.UnviewedMentionsCount++
|
||||||
// Opposite of above, the message had a mention, but no longer does, so we reduce the count
|
needToSaveChat = true
|
||||||
chat.UnviewedMentionsCount--
|
} else if !editedMessageHasMentions && originalMessageMentioned && !editedMessage.Seen {
|
||||||
needToSaveChat = true
|
// Opposite of above, the message had a mention, but no longer does, so we reduce the count
|
||||||
|
chat.UnviewedMentionsCount--
|
||||||
|
needToSaveChat = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if needToSaveChat {
|
if needToSaveChat {
|
||||||
err := m.saveChat(chat)
|
err := m.saveChat(chat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3083,17 +3080,11 @@ func (m *Messenger) isMessageAllowedFrom(publicKey string, chat *Chat) (bool, er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) updateUnviewedCounts(chat *Chat, message *common.Message) {
|
func (m *Messenger) updateUnviewedCounts(chat *Chat, message *common.Message) {
|
||||||
if chat == nil {
|
if chat.ShouldIncreaseMessageCount(message) {
|
||||||
return
|
|
||||||
}
|
|
||||||
if chat.LastMessage == nil ||
|
|
||||||
chat.LastMessage.IsSystemMessage() ||
|
|
||||||
!chat.LastMessage.New ||
|
|
||||||
message.Timestamp > chat.LastMessage.Timestamp+IncreaseUnviewedMessagesCountTimeout {
|
|
||||||
chat.UnviewedMessagesCount++
|
chat.UnviewedMessagesCount++
|
||||||
}
|
if message.Mentioned || message.Replied || chat.OneToOne() {
|
||||||
if message.Mentioned || message.Replied {
|
chat.UnviewedMentionsCount++
|
||||||
chat.UnviewedMentionsCount++
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue