refactor(communities): refactor communities cache in service

Fixes #9570
This commit is contained in:
Jonathan Rainville 2023-03-02 13:11:52 -05:00
parent ce33c195cc
commit d8473f4d4f
3 changed files with 110 additions and 147 deletions

View File

@ -304,15 +304,12 @@ proc getMySectionId*(self: Controller): string =
proc isCommunity*(self: Controller): bool =
return self.isCommunitySection
proc getCommunityByIdFromAllCommunities*(self: Controller, communityId: string): CommunityDto =
return self.communityService.getCommunityByIdFromAllCommunities(communityId)
proc getMyCommunity*(self: Controller): CommunityDto =
return self.getCommunityByIdFromAllCommunities(self.sectionId)
proc getCommunityById*(self: Controller, communityId: string): CommunityDto =
return self.communityService.getCommunityById(communityId)
proc getMyCommunity*(self: Controller): CommunityDto =
return self.getCommunityById(self.sectionId)
proc getCategories*(self: Controller, communityId: string): seq[Category] =
return self.communityService.getCategories(communityId)

View File

@ -173,16 +173,14 @@ QtObject:
activityCenterService: activity_center_service.Service
messageService: message_service.Service
communityTags: string # JSON string contraining tags map
joinedCommunities: Table[string, CommunityDto] # [community_id, CommunityDto]
curatedCommunities: Table[string, CuratedCommunity] # [community_id, CuratedCommunity]
allCommunities: Table[string, CommunityDto] # [community_id, CommunityDto]
communities: Table[string, CommunityDto] # [community_id, CommunityDto]
myCommunityRequests*: seq[CommunityMembershipRequestDto]
historyArchiveDownloadTaskCommunityIds*: HashSet[string]
# Forward declaration
proc loadCommunityTags(self: Service): string
proc loadAllCommunities(self: Service): seq[CommunityDto]
proc loadJoinedComunities(self: Service): seq[CommunityDto]
proc asyncLoadCuratedCommunities*(self: Service)
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto]
proc loadMyPendingRequestsToJoin*(self: Service)
@ -212,16 +210,21 @@ QtObject:
result.activityCenterService = activityCenterService
result.messageService = messageService
result.communityTags = newString(0)
result.joinedCommunities = initTable[string, CommunityDto]()
result.curatedCommunities = initTable[string, CuratedCommunity]()
result.allCommunities = initTable[string, CommunityDto]()
result.communities = initTable[string, CommunityDto]()
result.myCommunityRequests = @[]
result.historyArchiveDownloadTaskCommunityIds = initHashSet[string]()
proc getFilteredJoinedCommunities(self: Service): Table[string, CommunityDto] =
result = initTable[string, CommunityDto]()
for communityId, community in self.communities.pairs:
if community.joined:
result[communityId] = community
proc doConnect(self: Service) =
self.events.on(SignalType.CommunityFound.event) do(e: Args):
var receivedData = CommunitySignal(e)
self.allCommunities[receivedData.community.id] = receivedData.community
self.communities[receivedData.community.id] = receivedData.community
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: receivedData.community))
if self.curatedCommunities.contains(receivedData.community.id) and not self.curatedCommunities[receivedData.community.id].available:
@ -244,15 +247,15 @@ QtObject:
# Handling membership requests
if(receivedData.membershipRequests.len > 0):
for membershipRequest in receivedData.membershipRequests:
if (not self.joinedCommunities.contains(membershipRequest.communityId)):
if (not self.communities.contains(membershipRequest.communityId)):
error "Received a membership request for an unknown community", communityId=membershipRequest.communityId
continue
var community = self.joinedCommunities[membershipRequest.communityId]
var community = self.communities[membershipRequest.communityId]
case RequestToJoinType(membershipRequest.state):
of RequestToJoinType.Pending:
community.pendingRequestsToJoin.add(membershipRequest)
self.joinedCommunities[membershipRequest.communityId] = community
self.communities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY, CommunityRequestArgs(communityRequest: membershipRequest))
@ -260,7 +263,7 @@ QtObject:
let indexPending = self.getPendingRequestIndex(membershipRequest.communityId, membershipRequest.id)
if (indexPending != -1):
community.pendingRequestsToJoin.delete(indexPending)
self.joinedCommunities[membershipRequest.communityId] = community
self.communities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
of RequestToJoinType.Declined:
@ -354,15 +357,15 @@ QtObject:
return idx
return -1
proc saveUpdatedJoinedCommunity(self: Service, community: var CommunityDto) =
proc saveUpdatedCommunity(self: Service, community: var CommunityDto) =
# Community data we get from the signals and responses don't contgain the pending requests
# therefore, we must keep the old one
community.pendingRequestsToJoin = self.joinedCommunities[community.id].pendingRequestsToJoin
community.declinedRequestsToJoin = self.joinedCommunities[community.id].declinedRequestsToJoin
community.canceledRequestsToJoin = self.joinedCommunities[community.id].canceledRequestsToJoin
community.pendingRequestsToJoin = self.communities[community.id].pendingRequestsToJoin
community.declinedRequestsToJoin = self.communities[community.id].declinedRequestsToJoin
community.canceledRequestsToJoin = self.communities[community.id].canceledRequestsToJoin
# Update the joinded community list with the new data
self.joinedCommunities[community.id] = community
self.communities[community.id] = community
proc getChatsInCategory(self: Service, community: var CommunityDto, categoryId: string): seq[ChatDto] =
result = @[]
@ -374,11 +377,10 @@ QtObject:
proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto]) =
for settings in communitiesSettings:
if self.allCommunities.hasKey(settings.id):
self.allCommunities[settings.id].settings = settings
if self.joinedCommunities.hasKey(settings.id):
self.joinedCommunities[settings.id].settings = settings
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[settings.id]))
if self.communities.hasKey(settings.id):
self.communities[settings.id].settings = settings
if self.communities[settings.id].joined:
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[settings.id]))
proc checkForCategoryPropertyUpdates(self: Service, community: CommunityDto, prev_community: CommunityDto) =
for category in community.categories:
@ -403,14 +405,14 @@ QtObject:
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string]) =
try:
var community = communities[0]
if(not self.allCommunities.hasKey(community.id)):
self.allCommunities[community.id] = community
if not self.communities.hasKey(community.id):
self.communities[community.id] = community
self.events.emit(SIGNAL_COMMUNITY_ADDED, CommunityArgs(community: community))
if(not self.joinedCommunities.hasKey(community.id)):
if (community.joined and community.isMember):
self.joinedCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))
# remove my pending requests
keepIf(self.myCommunityRequests, request => request.communityId != community.id)
return
@ -418,7 +420,7 @@ QtObject:
self.curatedCommunities[community.id].available = true
self.curatedCommunities[community.id].community = community
let prev_community = self.allCommunities[community.id]
let prev_community = self.communities[community.id]
# If there's settings without `id` it means the original
# signal didn't include actual communitySettings, hence we
@ -433,8 +435,7 @@ QtObject:
if(community.categories.len > prev_community.categories.len):
for category in community.categories:
if findIndexById(category.id, prev_community.categories) == -1:
self.allCommunities[community.id].categories.add(category)
self.joinedCommunities[community.id].categories.add(category)
self.communities[community.id].categories.add(category)
let chats = self.getChatsInCategory(community, category.id)
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_CREATED,
@ -511,14 +512,11 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_MEMBERS_CHANGED,
CommunityMembersArgs(communityId: community.id, members: community.members))
self.allCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))
# tokenPermission was added
if community.tokenPermissions.len > prev_community.tokenPermissions.len:
for id, tokenPermission in community.tokenPermissions:
if not prev_community.tokenPermissions.hasKey(id):
self.allCommunities[community.id].tokenPermissions[id] = tokenPermission
self.communities[community.id].tokenPermissions[id] = tokenPermission
self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATED,
CommunityTokenPermissionArgs(communityId: community.id, tokenPermission: tokenPermission))
@ -557,14 +555,15 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATED,
CommunityTokenPermissionArgs(communityId: community.id, tokenPermission: tokenPermission))
if(not self.joinedCommunities.hasKey(community.id)):
if (community.joined and community.isMember):
self.joinedCommunities[community.id] = community
let wasJoined = self.communities[community.id].joined
self.saveUpdatedCommunity(community)
# If the community was not joined before but is now, we signal it
if(not wasJoined and community.joined and community.isMember):
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))
# remove my pending requests
keepIf(self.myCommunityRequests, request => request.communityId != community.id)
else:
self.saveUpdatedJoinedCommunity(community)
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))
except Exception as e:
error "Error handling community updates", msg = e.msg, communities, updatedChats, removedChats
@ -572,24 +571,19 @@ QtObject:
proc init*(self: Service) =
self.doConnect()
self.communityTags = self.loadCommunityTags();
let joinedCommunities = self.loadJoinedComunities()
for community in joinedCommunities:
self.joinedCommunities[community.id] = community
if (community.admin):
self.joinedCommunities[community.id].pendingRequestsToJoin = self.pendingRequestsToJoinForCommunity(community.id)
self.joinedCommunities[community.id].declinedRequestsToJoin = self.declinedRequestsToJoinForCommunity(community.id)
self.joinedCommunities[community.id].canceledRequestsToJoin = self.canceledRequestsToJoinForCommunity(community.id)
let allCommunities = self.loadAllCommunities()
for community in allCommunities:
self.allCommunities[community.id] = community
let communities = self.loadAllCommunities()
for community in communities:
self.communities[community.id] = community
if (community.admin):
self.communities[community.id].pendingRequestsToJoin = self.pendingRequestsToJoinForCommunity(community.id)
self.communities[community.id].declinedRequestsToJoin = self.declinedRequestsToJoinForCommunity(community.id)
self.communities[community.id].canceledRequestsToJoin = self.canceledRequestsToJoinForCommunity(community.id)
let communitiesSettings = self.loadCommunitiesSettings()
for settings in communitiesSettings:
if self.allCommunities.hasKey(settings.id):
self.allCommunities[settings.id].settings = settings
if self.joinedCommunities.hasKey(settings.id):
self.joinedCommunities[settings.id].settings = settings
if self.communities.hasKey(settings.id):
self.communities[settings.id].settings = settings
self.loadMyPendingRequestsToJoin()
@ -608,15 +602,6 @@ QtObject:
error "error loading all communities: ", errDesription
return @[]
proc loadJoinedComunities(self: Service): seq[CommunityDto] =
try:
let response = status_go.getJoinedComunities()
return parseCommunities(response)
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
return @[]
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto] =
try:
let response = status_go.getCommunitiesSettings()
@ -630,30 +615,23 @@ QtObject:
return self.communityTags
proc getJoinedCommunities*(self: Service): seq[CommunityDto] =
return toSeq(self.joinedCommunities.values)
return toSeq(self.getFilteredJoinedCommunities().values)
proc getAllCommunities*(self: Service): seq[CommunityDto] =
return toSeq(self.allCommunities.values)
return toSeq(self.communities.values)
proc getCuratedCommunities*(self: Service): seq[CuratedCommunity] =
return toSeq(self.curatedCommunities.values)
proc getCommunityByIdFromAllCommunities*(self: Service, communityId: string): CommunityDto =
if(not self.allCommunities.hasKey(communityId)):
error "error: requested community doesn't exists", communityId
return
return self.allCommunities[communityId]
proc getCommunityById*(self: Service, communityId: string): CommunityDto =
if(not self.joinedCommunities.hasKey(communityId)):
if(not self.communities.hasKey(communityId)):
error "error: requested community doesn't exists", communityId
return
return self.joinedCommunities[communityId]
return self.communities[communityId]
proc getCommunityIds*(self: Service): seq[string] =
return toSeq(self.joinedCommunities.keys)
return toSeq(self.communities.keys)
proc sortAsc[T](t1, t2: T): int =
if(t1.position > t2.position):
@ -672,20 +650,20 @@ QtObject:
return 0
proc getCategoryById*(self: Service, communityId: string, categoryId: string): Category =
if(not self.joinedCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
error "trying to get community categories for an unexisting community id"
return
let categories = self.joinedCommunities[communityId].categories
let categories = self.communities[communityId].categories
let categoryIndex = findIndexById(categoryId, categories)
return categories[categoryIndex]
proc getCategories*(self: Service, communityId: string, order: SortOrder = SortOrder.Ascending): seq[Category] =
if(not self.joinedCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
error "trying to get community categories for an unexisting community id"
return
result = self.joinedCommunities[communityId].categories
result = self.communities[communityId].categories
if(order == SortOrder.Ascending):
result.sort(sortAsc[Category])
else:
@ -695,11 +673,11 @@ QtObject:
## By default returns chats which don't belong to any category, for passed `communityId`.
## If `categoryId` is set then only chats belonging to that category for passed `communityId` will be returned.
## Returned chats are sorted by position following set `order` parameter.
if(not self.joinedCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
error "trying to get community chats for an unexisting community id"
return
for chat in self.joinedCommunities[communityId].chats:
for chat in self.communities[communityId].chats:
if(chat.categoryId != categoryId):
continue
@ -713,11 +691,11 @@ QtObject:
proc getAllChats*(self: Service, communityId: string, order = SortOrder.Ascending): seq[ChatDto] =
## Returns all chats belonging to the community with passed `communityId`, sorted by position.
## Returned chats are sorted by position following set `order` parameter.
if(not self.joinedCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
error "trying to get all community chats for an unexisting community id"
return
result = self.joinedCommunities[communityId].chats
result = self.communities[communityId].chats
if(order == SortOrder.Ascending):
result.sort(sortAsc[ChatDto])
@ -725,19 +703,19 @@ QtObject:
result.sort(sortDesc[ChatDto])
proc isUserMemberOfCommunity*(self: Service, communityId: string): bool =
if(not self.allCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
return false
return self.allCommunities[communityId].joined and self.allCommunities[communityId].isMember
return self.communities[communityId].joined and self.communities[communityId].isMember
proc isUserSpectatingCommunity*(self: Service, communityId: string): bool =
if(not self.allCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
return false
return self.allCommunities[communityId].spectated
return self.communities[communityId].spectated
proc userCanJoin*(self: Service, communityId: string): bool =
if(not self.allCommunities.contains(communityId)):
if(not self.communities.contains(communityId)):
return false
return self.allCommunities[communityId].canJoin
return self.communities[communityId].canJoin
proc processRequestsToJoinCommunity(self: Service, responseResult: JsonNode): bool =
if responseResult{"requestsToJoinCommunity"} == nil or responseResult{"requestsToJoinCommunity"}.kind == JNull:
@ -778,7 +756,7 @@ QtObject:
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
updatedCommunity.settings = communitySettings
self.allCommunities[communityId] = updatedCommunity
self.communities[communityId] = updatedCommunity
self.chatService.loadChats()
for k, chat in updatedCommunity.chats:
@ -883,14 +861,12 @@ QtObject:
# Update community so that joined, member list and isMember are updated
let updatedCommunity = response.result["communities"][0].toCommunityDto()
self.allCommunities[communityId] = updatedCommunity
self.communities[communityId] = updatedCommunity
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[updatedCommunity]))
for chat in updatedCommunity.chats:
self.messageService.resetMessageCursor(chat.id)
# remove this from the joinedCommunities list
self.joinedCommunities.del(communityId)
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: communityId))
# remove related community requests
@ -991,8 +967,8 @@ QtObject:
community.settings = communitySettings
# add this to the joinedCommunities list and communitiesSettings
self.joinedCommunities[community.id] = community
# add this to the communities list and communitiesSettings
self.communities[community.id] = community
# add new community channel group and chats to chat service
self.chatService.updateOrAddChannelGroup(community.toChannelGroupDto())
for chat in community.chats:
@ -1052,7 +1028,7 @@ QtObject:
var communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
community.settings = communitySettings
self.saveUpdatedJoinedCommunity(community)
self.saveUpdatedCommunity(community)
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
except Exception as e:
error "Error editing community", msg = e.msg
@ -1087,7 +1063,7 @@ QtObject:
var chatDto = chatObj.toChatDto(communityId)
chatDto.position = maxPosition + 1
self.chatService.updateOrAddChat(chatDto)
self.joinedCommunities[communityId].chats.add(chatDto)
self.communities[communityId].chats.add(chatDto)
let data = CommunityChatArgs(chat: chatDto)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, data)
except Exception as e:
@ -1160,13 +1136,13 @@ QtObject:
let updatedCommunity = response.result["communities"][0].toCommunityDto()
for chat in updatedCommunity.chats:
let prev_chat_idx = findIndexById(chat.id, self.joinedCommunities[communityId].chats)
let prev_chat_idx = findIndexById(chat.id, self.communities[communityId].chats)
if prev_chat_idx > -1:
let prev_chat = self.joinedCommunities[communityId].chats[prev_chat_idx]
let prev_chat = self.communities[communityId].chats[prev_chat_idx]
if(chat.position != prev_chat.position and chat.categoryId == categoryId):
var chatDetails = self.chatService.getChatById(chat.id) # we are free to do this cause channel must be created before we add it to a category
self.joinedCommunities[communityId].chats[prev_chat_idx].position = chat.position
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[prev_chat_idx])
self.communities[communityId].chats[prev_chat_idx].position = chat.position
chatDetails.updateMissingFields(self.communities[communityId].chats[prev_chat_idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: updatedCommunity.id, chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
@ -1183,9 +1159,9 @@ QtObject:
if response.result.isNil or response.result.kind == JNull:
error "response is invalid", procName="deleteCommunityChat"
let idx = findIndexById(chatId, self.joinedCommunities[communityId].chats)
let idx = findIndexById(chatId, self.communities[communityId].chats)
if (idx != -1):
self.joinedCommunities[communityId].chats.delete(idx)
self.communities[communityId].chats.delete(idx)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(
communityId: communityId, chatId: chatId))
@ -1206,30 +1182,27 @@ QtObject:
if response.result != nil and response.result.kind != JNull:
self.checkForCategoryPropertyUpdates(
response.result["communityChanges"].getElems()[0]["community"].toCommunityDto,
self.joinedCommunities[communityId]
self.communities[communityId]
)
var chats: seq[ChatDto] = @[]
for chatId, v in response.result["communityChanges"].getElems()[0]["chatsModified"].pairs():
let fullChatId = communityId & chatId
let idx = findIndexById(fullChatId, self.joinedCommunities[communityId].chats)
let idx = findIndexById(fullChatId, self.communities[communityId].chats)
if idx > -1:
self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt()
if self.joinedCommunities[communityId].chats[idx].categoryId.len > 0:
self.communities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.communities[communityId].chats[idx].position = v["PositionModified"].getInt()
if self.communities[communityId].chats[idx].categoryId.len > 0:
var chatDetails = self.chatService.getChatById(fullChatId) # we are free to do this cause channel must be created before we add it to a category
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[idx])
chatDetails.updateMissingFields(self.communities[communityId].chats[idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.
chats.add(chatDetails)
for k, v in response.result["communityChanges"].getElems()[0]["categoriesAdded"].pairs():
let category = v.toCategory()
self.joinedCommunities[communityId].categories.add(category)
self.communities[communityId].categories.add(category)
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_CREATED,
CommunityCategoryArgs(communityId: communityId, category: category, chats: chats))
# Update `allCommunities` to the new `joinedCommunity` value
self.allCommunities[communityId] = self.joinedCommunities[communityId]
except Exception as e:
error "Error creating community category", msg = e.msg, communityId, name
@ -1249,13 +1222,13 @@ QtObject:
var chats: seq[ChatDto] = @[]
for chatId, v in response.result["communityChanges"].getElems()[0]["chatsModified"].pairs():
let fullChatId = communityId & chatId
let idx = findIndexById(fullChatId, self.joinedCommunities[communityId].chats)
let idx = findIndexById(fullChatId, self.communities[communityId].chats)
if idx > -1:
self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt()
self.communities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.communities[communityId].chats[idx].position = v["PositionModified"].getInt()
var chatDetails = self.chatService.getChatById(fullChatId) # we are free to do this cause channel must be created before we add it to a category
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[idx])
chatDetails.updateMissingFields(self.communities[communityId].chats[idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.
chats.add(chatDetails)
@ -1263,10 +1236,9 @@ QtObject:
let updatedCommunity = response.result["communities"][0].toCommunityDto
self.checkForCategoryPropertyUpdates(
updatedCommunity,
self.joinedCommunities[communityId]
self.communities[communityId]
)
self.joinedCommunities[communityId] = updatedCommunity
self.allCommunities[communityId] = updatedCommunity
self.communities[communityId] = updatedCommunity
for k, v in response.result["communityChanges"].getElems()[0]["categoriesModified"].pairs():
let category = v.toCategory()
@ -1289,10 +1261,9 @@ QtObject:
self.checkForCategoryPropertyUpdates(
updatedCommunity,
self.joinedCommunities[communityId]
self.communities[communityId]
)
self.joinedCommunities[communityId] = updatedCommunity
self.allCommunities[communityId] = updatedCommunity
self.communities[communityId] = updatedCommunity
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_DELETED,
CommunityCategoryArgs(
@ -1337,7 +1308,7 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_LOAD_DATA_FAILED, CommunityArgs(community: community, error: "Couldn't find community info"))
return
self.allCommunities[community.id] = community
self.communities[community.id] = community
if rpcResponseObj{"importing"}.getBool():
self.events.emit(SIGNAL_COMMUNITY_IMPORTED, CommunityArgs(community: community))
@ -1421,7 +1392,7 @@ QtObject:
let communitySettingsDto = communitiesSettingsJArr[0].toCommunitySettingsDto()
communityDto.settings = communitySettingsDto
self.joinedCommunities[communityDto.id] = communityDto
self.communities[communityDto.id] = communityDto
var chatsJArr: JsonNode
if(response.result.getProp("chats", chatsJArr)):
@ -1452,7 +1423,7 @@ QtObject:
error "Error exporting community", msg = e.msg
proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int =
let community = self.joinedCommunities[communityId]
let community = self.communities[communityId]
var i = 0
for pendingRequest in community.pendingRequestsToJoin:
if (pendingRequest.id == requestId):
@ -1461,7 +1432,7 @@ QtObject:
return -1
proc getDeclinedRequestIndex(self: Service, communityId: string, requestId: string): int =
let community = self.joinedCommunities[communityId]
let community = self.communities[communityId]
var i = 0
for declinedRequest in community.declinedRequestsToJoin:
if (declinedRequest.id == requestId):
@ -1476,7 +1447,7 @@ QtObject:
if (indexPending == -1 and indexDeclined == -1):
raise newException(RpcException, fmt"Community request not found: {requestId}")
var community = self.joinedCommunities[communityId]
var community = self.communities[communityId]
if (indexPending != -1):
result = community.pendingRequestsToJoin[indexPending].publicKey
@ -1485,20 +1456,20 @@ QtObject:
result = community.declinedRequestsToJoin[indexDeclined].publicKey
community.declinedRequestsToJoin.delete(indexDeclined)
self.joinedCommunities[communityId] = community
self.communities[communityId] = community
proc moveRequestToDeclined*(self: Service, communityId: string, requestId: string) =
let indexPending = self.getPendingRequestIndex(communityId, requestId)
if (indexPending == -1):
raise newException(RpcException, fmt"Community request not found: {requestId}")
var community = self.joinedCommunities[communityId]
var community = self.communities[communityId]
if (indexPending != -1):
let itemToMove = community.pendingRequestsToJoin[indexPending]
community.declinedRequestsToJoin.add(itemToMove)
community.pendingRequestsToJoin.delete(indexPending)
self.joinedCommunities[communityId] = community
self.communities[communityId] = community
proc cancelRequestToJoinCommunity*(self: Service, communityId: string) =
try:
@ -1542,7 +1513,7 @@ QtObject:
self.moveRequestToDeclined(communityId, requestId)
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[communityId]))
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[communityId]))
except Exception as e:
error "Error declining request to join community", msg = e.msg
@ -1652,8 +1623,7 @@ QtObject:
for permissionId, permission in response.result["communityChanges"].getElems()[0][changesField].pairs():
let p = permission.toCommunityTokenPermissionDto()
self.allCommunities[communityId].tokenPermissions[permissionId] = p
self.joinedCommunities[communityId].tokenPermissions[permissionId] = p
self.communities[communityId].tokenPermissions[permissionId] = p
var signal = SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATED
if editing:
@ -1675,8 +1645,8 @@ QtObject:
let response = status_go.deleteCommunityTokenPermission(communityId, permissionId)
if response.result != nil and response.result.kind != JNull:
for permissionId in response.result["communityChanges"].getElems()[0]["tokenPermissionsRemoved"].getElems():
if self.allCommunities[communityId].tokenPermissions.hasKey(permissionId.getStr()):
self.allCommunities[communityId].tokenPermissions.del(permissionId.getStr())
if self.communities[communityId].tokenPermissions.hasKey(permissionId.getStr()):
self.communities[communityId].tokenPermissions.del(permissionId.getStr())
self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED,
CommunityTokenPermissionRemovedArgs(communityId: communityId, permissionId: permissionId.getStr))
return

View File

@ -17,10 +17,6 @@ proc unmuteCategory*(communityId: string, categoryId: string): RpcResponse[JsonN
let payload = %* [communityId, categoryId]
result = callPrivateRPC("unmuteCommunityCategory".prefix, payload)
proc getJoinedComunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = callPrivateRPC("joinedCommunities".prefix, payload)
proc getCuratedCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = callPrivateRPC("curatedCommunities".prefix, payload)