Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/invitation bubble #7395

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ proc init*(self: Controller) =
let args = CommunityMutedArgs(e)
self.delegate.communityMuted(args.communityId, args.muted)

self.events.on(SIGNAL_COMMUNITY_MY_REQUEST_ADDED) do(e:Args):
let args = CommunityRequestArgs(e)
self.delegate.communityAccessRequested(args.communityRequest.communityId)

self.events.on(SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED) do(e:Args):
let args = DiscordCategoriesAndChannelsArgs(e)
self.delegate.discordCategoriesAndChannelsExtracted(args.categories, args.channels, args.oldestMessageTimestamp, args.errors, args.errorsCount)
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method communityMuted*(self: AccessInterface, communityId: string, muted: bool) {.base.} =
raise newException(ValueError, "No implementation available")

method communityAccessRequested*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestExtractDiscordChannelsAndCategories*(self: AccessInterface, filesToImport: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ method reorderCommunityCategories*(self: Module, communityId: string, categoryId
method communityMuted*(self: Module, communityId: string, muted: bool) =
self.view.model().setMuted(communityId, muted)

method communityAccessRequested*(self: Module, communityId: string) =
self.view.communityAccessRequested(communityId)

method discordCategoriesAndChannelsExtracted*(self: Module, categories: seq[DiscordCategoryDto], channels: seq[DiscordChannelDto], oldestMessageTimestamp: int, errors: Table[string, DiscordImportError], errorsCount: int) =

for filePath in errors.keys:
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ QtObject:
proc communityChanged*(self: View, communityId: string) {.signal.}
proc discordOldestMessageTimestampChanged*(self: View) {.signal.}
proc discordImportErrorsCountChanged*(self: View) {.signal.}
proc communityAccessRequested*(self: View, communityId: string) {.signal.}

proc setCommunityTags*(self: View, communityTags: string) =
self.communityTags = newQVariant(communityTags)
Expand Down
2 changes: 1 addition & 1 deletion src/app_service/service/community/dto/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CommunityMembershipRequestDto* = object
chatId*: string
communityId*: string
state*: int
our*: string
our*: string #FIXME: should be bool

type CommunitySettingsDto* = object
id*: string
Expand Down
25 changes: 19 additions & 6 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NimQml, Tables, json, sequtils, std/algorithm, strformat, strutils, chronicles, json_serialization
import NimQml, Tables, json, sequtils, std/algorithm, strformat, strutils, chronicles, json_serialization, sugar

import ./dto/community as community_dto

Expand Down Expand Up @@ -265,6 +265,7 @@ QtObject:
if(not self.joinedCommunities.hasKey(community.id)):
if (community.joined and community.isMember):
self.joinedCommunities[community.id] = community
keepIf(self.myCommunityRequests, request => request.communityId != community.id)
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))
return

Expand Down Expand Up @@ -516,6 +517,17 @@ QtObject:
return false
return self.allCommunities[communityId].canJoin

proc processRequestsToJoinCommunity(self: Service, responseResult: JsonNode): bool =
if responseResult{"requestsToJoinCommunity"} == nil or responseResult{"requestsToJoinCommunity"}.kind == JNull:
return false

for jsonCommunityReqest in responseResult["requestsToJoinCommunity"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))

return true

proc joinCommunity*(self: Service, communityId: string): string =
result = ""
try:
Expand All @@ -540,6 +552,9 @@ QtObject:
error "error: ", procName="joinCommunity", errDesription = "no 'communitiesSettings' key in response"
return

if not self.processRequestsToJoinCommunity(response.result):
error "error: ", procName="joinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"

var updatedCommunity = response.result["communities"][0].toCommunityDto()
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()

Expand Down Expand Up @@ -569,11 +584,9 @@ QtObject:
try:
let response = status_go.requestToJoinCommunity(communityId, ensName)

if response.result{"requestsToJoinCommunity"} != nil and response.result{"requestsToJoinCommunity"}.kind != JNull:
for jsonCommunityReqest in response.result["requestsToJoinCommunity"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))
if not self.processRequestsToJoinCommunity(response.result):
error "error: ", procName="requestToJoinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"

except Exception as e:
error "Error requesting to join the community", msg = e.msg, communityId, ensName

Expand Down
Loading