Skip to content

Commit

Permalink
fix(messenger): make sure chats have an unread count of 0 for channel…
Browse files Browse the repository at this point in the history
…s you can't view

Fixes status-im/status-desktop#14421

The problem is that you can receive messages to  a channel, then later, before marking them as read, a permisison is added to them, so you no longer have access.
Then, you can't even mark it as read if it's hidden.
Here, I fix it by setting the unread count on Init at 0 if the user doesn't have view access to it.
  • Loading branch information
jrainville committed Apr 16, 2024
1 parent d246699 commit 0e244ed
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,8 @@ func (m *Messenger) Init() error {
continue
}

m.allChats.Store(chat.ID, chat)

if !chat.Active || chat.Timeline() {
m.allChats.Store(chat.ID, chat)
continue
}

Expand All @@ -1847,6 +1846,17 @@ func (m *Messenger) Init() error {
communityInfo[chat.CommunityID] = community
}

if chat.UnviewedMessagesCount > 0 || chat.UnviewedMentionsCount > 0 {
// Make sure the unread count is 0 for the channels the user cannot view
// It's possible that the users received messages to a channel before permissions were added
canView := community.CanView(&m.identity.PublicKey, chat.CommunityChatID())

if !canView {
chat.UnviewedMessagesCount = 0
chat.UnviewedMentionsCount = 0
}
}

filtersToInit = append(filtersToInit, transport.FiltersToInitialize{ChatID: chat.ID, PubsubTopic: community.PubsubTopic()})
case ChatTypeOneToOne:
pk, err := chat.PublicKey()
Expand All @@ -1865,6 +1875,8 @@ func (m *Messenger) Init() error {
default:
return errors.New("invalid chat type")
}

m.allChats.Store(chat.ID, chat)
}

// Timeline and profile chats are deprecated.
Expand Down

0 comments on commit 0e244ed

Please sign in to comment.