fix(communities): handle removed community chats properly

We were ignoring the `removedChats` in the messenger response and
therefore never processed deleted community chats in the client.

This commit adds `removedChats` to `handleCommunityUpdates()` and
ensures that the community channel's ID is used when emitting a signal
to the app.

This needs: https://github.com/status-im/status-go/pull/2973

Closes #8000
This commit is contained in:
Pascal Precht 2022-11-23 14:50:00 +01:00 committed by r4bbit.eth
parent c1fd4cc680
commit d8bda2490a
3 changed files with 11 additions and 6 deletions

View File

@ -26,6 +26,7 @@ type MessageSignal* = ref object of Signal
activityCenterNotifications*: seq[ActivityCenterNotificationDto]
statusUpdates*: seq[StatusUpdateDto]
deletedMessages*: seq[RemovedMessageDto]
removedChats*: seq[string]
currentStatus*: seq[StatusUpdateDto]
settings*: seq[SettingsFieldDto]
clearedHistories*: seq[ClearedHistoryDto]
@ -105,6 +106,10 @@ proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
for jsonRemovedMessage in event["event"]["removedMessages"]:
signal.deletedMessages.add(jsonRemovedMessage.toRemovedMessageDto())
if event["event"]{"removedChats"} != nil:
for removedChatID in event["event"]["removedChats"]:
signal.removedChats.add(removedChatID.getStr())
if event["event"]{"activityCenterNotifications"} != nil:
for jsonNotification in event["event"]["activityCenterNotifications"]:
signal.activityCenterNotifications.add(jsonNotification.toActivityCenterNotificationDto())

View File

@ -146,7 +146,7 @@ QtObject:
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto]
proc loadMyPendingRequestsToJoin*(self: Service)
proc loadMyCanceledRequestsToJoin*(self: Service)
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto])
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string])
proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto])
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
@ -192,7 +192,7 @@ QtObject:
# Handling community updates
if (receivedData.communities.len > 0):
# Channel added removed is notified in the chats param
self.handleCommunityUpdates(receivedData.communities, receivedData.chats)
self.handleCommunityUpdates(receivedData.communities, receivedData.chats, receivedData.removedChats)
if (receivedData.communitiesSettings.len > 0):
self.handleCommunitiesSettingsUpdates(receivedData.communitiesSettings)
@ -304,7 +304,7 @@ QtObject:
self.joinedCommunities[settings.id].settings = settings
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[settings.id]))
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) =
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string]) =
var community = communities[0]
if(not self.allCommunities.hasKey(community.id)):
self.allCommunities[community.id] = community
@ -377,11 +377,11 @@ QtObject:
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
# channel was removed
elif(community.chats.len < prev_community.chats.len):
elif((community.chats.len-removedChats.len) < prev_community.chats.len):
for prv_chat in prev_community.chats:
if findIndexById(prv_chat.id, community.chats) == -1:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(communityId: community.id,
chatId: community.id&prv_chat.id))
chatId: prv_chat.id))
# some property has changed
else:
for chat in community.chats:

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit d41fcaf8a9d95fe8d820c1928736a7a36d783032
Subproject commit 019d520e28f36b63959772f99a8ae79d654bdc90