fix(messenger)_: make sure chats have an unread count of 0 for channels you can't view (#5062)
Fixes https://github.com/status-im/status-desktop/issues/14421 The problem is that you can receive messages to a channel, then later, before marking them as read, a permission 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. And I make sure we update the counts when we are removed from a channel
This commit is contained in:
parent
bf56cb7ee2
commit
5ca1cb0a0f
|
@ -183,6 +183,7 @@ func evaluateCommunityChangesByDescription(origin, modified *protobuf.CommunityD
|
|||
if _, ok := origin.Chats[chatID]; !ok {
|
||||
changes.ChatsAdded[chatID] = chat
|
||||
} else {
|
||||
|
||||
// Check for members added
|
||||
for pk, member := range modified.Chats[chatID].Members {
|
||||
if _, ok := origin.Chats[chatID].Members[pk]; !ok {
|
||||
|
@ -192,7 +193,6 @@ func evaluateCommunityChangesByDescription(origin, modified *protobuf.CommunityD
|
|||
MembersRemoved: make(map[string]*protobuf.CommunityMember),
|
||||
}
|
||||
}
|
||||
|
||||
changes.ChatsModified[chatID].MembersAdded[pk] = member
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,6 @@ func evaluateCommunityChangesByDescription(origin, modified *protobuf.CommunityD
|
|||
MembersRemoved: make(map[string]*protobuf.CommunityMember),
|
||||
}
|
||||
}
|
||||
|
||||
changes.ChatsModified[chatID].MembersRemoved[pk] = member
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1758,9 +1758,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
|
||||
}
|
||||
|
||||
|
@ -1784,6 +1783,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()
|
||||
|
@ -1802,6 +1812,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.
|
||||
|
|
|
@ -3173,7 +3173,7 @@ func (m *Messenger) handleCommunityResponse(state *ReceivedMessageState, communi
|
|||
|
||||
removedChatIDs := make([]string, 0)
|
||||
for id := range communityResponse.Changes.ChatsRemoved {
|
||||
chatID := community.IDString() + id
|
||||
chatID := community.ChatID(id)
|
||||
_, ok := state.AllChats.Load(chatID)
|
||||
if ok {
|
||||
removedChatIDs = append(removedChatIDs, chatID)
|
||||
|
@ -3185,6 +3185,24 @@ func (m *Messenger) handleCommunityResponse(state *ReceivedMessageState, communi
|
|||
}
|
||||
}
|
||||
|
||||
// Check if we have been removed from a chat (ie no longer have access)
|
||||
for channelID, changes := range communityResponse.Changes.ChatsModified {
|
||||
if _, ok := changes.MembersRemoved[common.PubkeyToHex(&m.identity.PublicKey)]; ok {
|
||||
chatID := community.ChatID(channelID)
|
||||
|
||||
if chat, ok := state.AllChats.Load(chatID); ok {
|
||||
// Reset the chat's message counts
|
||||
chat.UnviewedMessagesCount = 0
|
||||
chat.UnviewedMentionsCount = 0
|
||||
err := m.saveChat(chat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.Response.AddChat(chat)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update relevant chats names and add new ones
|
||||
// Currently removal is not supported
|
||||
chats := CreateCommunityChats(community, state.Timesource)
|
||||
|
|
Loading…
Reference in New Issue