fix(members): fix member count not updating correctly on join (#16680)

* fix(members): fix member count not updating correctly on join

Fixes #16672

The issue was that the requests to join were not handled in time for when the community update came in, so when we udpated the section, we got both the normal member and the pending member still and they clashed and the pending one came on top, meaning that the joined member was not counted.
On a restart it would fix itself.
To fix it, I reordered the parsing of communities and requests, so that the request is updated first, ie deleted because it is now accepted.
I also fixed the function that handles request to that the state gets updated at all times. Before, it would only get updated if it was not accepted, pending or waiting for address.
Finally, there was a weird scenario where as a TM, I saw myself as pending even if I was joined, so I fixed it by removing duplicates.

* chore(@e2e): remove xfail mark from pin messages test

---------

Co-authored-by: Anastasiya Semenkevich <anastasija.ig@gmail.com>
This commit is contained in:
Jonathan Rainville 2024-11-01 09:45:09 -04:00 committed by GitHub
parent 893fe604e8
commit 36f2bb79a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 12 deletions

View File

@ -390,6 +390,12 @@ proc createCommunitySectionItem[T](self: Module[T], communityDetails: CommunityD
memberItems = concat(memberItems, pendingMembers, declinedMemberItems, bannedMembers)
# Remove duplicates, this can happen when the requests to join have not updated in time
var finalMembers: Table[string, MemberItem]
for memberItem in memberItems:
if not finalMembers.contains(memberItem.pubKey):
finalMembers[memberItem.pubKey] = memberItem
result = initItem(
communityDetails.id,
sectionType = SectionType.Community,
@ -417,7 +423,7 @@ proc createCommunitySectionItem[T](self: Module[T], communityDetails: CommunityD
communityDetails.permissions.access,
communityDetails.permissions.ensOnly,
communityDetails.muted,
memberItems,
finalMembers.values.toSeq(),
communityDetails.settings.historyArchiveSupportEnabled,
communityDetails.adminSettings.pinMessageAllMembersEnabled,
communityDetails.encrypted,

View File

@ -337,6 +337,10 @@ QtObject:
self.events.on(SignalType.Message.event) do(e: Args):
var receivedData = MessageSignal(e)
# Handling membership requests
if(receivedData.membershipRequests.len > 0):
self.handleCommunitiesRequestsToJoin(receivedData.membershipRequests)
# Handling community updates
if (receivedData.communities.len > 0):
# Channel added removed is notified in the chats param
@ -345,10 +349,6 @@ QtObject:
if (receivedData.communitiesSettings.len > 0):
self.handleCommunitiesSettingsUpdates(receivedData.communitiesSettings)
# Handling membership requests
if(receivedData.membershipRequests.len > 0):
self.handleCommunitiesRequestsToJoin(receivedData.membershipRequests)
self.events.on(SignalType.DiscordCategoriesAndChannelsExtracted.event) do(e: Args):
var receivedData = DiscordCategoriesAndChannelsExtractedSignal(e)
self.events.emit(SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED, DiscordCategoriesAndChannelsArgs(
@ -788,7 +788,7 @@ QtObject:
# Request was accepted, update the member's airdrop address
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY_ACCEPTED,
CommunityRequestArgs(communityRequest: membershipRequest))
else:
try:
self.updateMembershipRequestToNewState(membershipRequest.communityId, membershipRequest.id, self.communities[membershipRequest.communityId],
requestToJoinState)

View File

@ -22,7 +22,6 @@ pytestmark = marks
'Edit chat - Remove pinned message (when any member can pin is disabled)')
@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/703510', 'Join community via owner invite')
@pytest.mark.case(703255, 703256, 703510)
@pytest.mark.xfail(reason='https://github.com/status-im/status-desktop/issues/16672')
def test_join_community_and_pin_unpin_message(multiple_instances):
user_one: UserAccount = RandomUser()
user_two: UserAccount = RandomUser()