diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 797b88d6d7..5e25939102 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -35,13 +35,12 @@ proc init*(self: Controller) = self.events.on(SIGNAL_COMMUNITY_DATA_IMPORTED) do(e:Args): let args = CommunityArgs(e) - self.delegate.communityImported(args.community) + self.delegate.communityDataImported(args.community) self.events.on(SIGNAL_COMMUNITY_LOAD_DATA_FAILED) do(e: Args): let args = CommunityArgs(e) self.delegate.onImportCommunityErrorOccured(args.community.id, args.error) - self.events.on(SIGNAL_CURATED_COMMUNITY_FOUND) do(e:Args): let args = CuratedCommunityArgs(e) self.delegate.curatedCommunityAdded(args.curatedCommunity) @@ -191,8 +190,8 @@ proc deleteCommunityCategory*( categoryId: string) = self.communityService.deleteCommunityCategory(communityId, categoryId) -proc requestCommunityInfo*(self: Controller, communityId: string) = - self.communityService.requestCommunityInfo(communityId) +proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) = + self.communityService.requestCommunityInfo(communityId, importing) proc importCommunity*(self: Controller, communityKey: string) = self.communityService.importCommunity(communityKey) diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index 119678b613..7162970c5b 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -68,7 +68,7 @@ method cancelRequestToJoinCommunity*(self: AccessInterface, communityId: string) method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} = raise newException(ValueError, "No implementation available") -method requestCommunityInfo*(self: AccessInterface, communityId: string) {.base.} = +method requestCommunityInfo*(self: AccessInterface, communityId: string, importing: bool) {.base.} = raise newException(ValueError, "No implementation available") method deleteCommunityChat*(self: AccessInterface, communityId: string, channelId: string) {.base.} = @@ -113,6 +113,9 @@ method curatedCommunityEdited*(self: AccessInterface, community: CuratedCommunit method communityImported*(self: AccessInterface, community: CommunityDto) {.base.} = raise newException(ValueError, "No implementation available") +method communityDataImported*(self: AccessInterface, community: CommunityDto) {.base.} = + raise newException(ValueError, "No implementation available") + method onImportCommunityErrorOccured*(self: AccessInterface, communityId: string, error: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 04d7c3d75d..c9ff35484c 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -285,8 +285,8 @@ method cancelRequestToJoinCommunity*(self: Module, communityId: string) = method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) = self.controller.requestToJoinCommunity(communityId, ensName) -method requestCommunityInfo*(self: Module, communityId: string) = - self.controller.requestCommunityInfo(communityId) +method requestCommunityInfo*(self: Module, communityId: string, importing: bool) = + self.controller.requestCommunityInfo(communityId, importing) method isUserMemberOfCommunity*(self: Module, communityId: string): bool = self.controller.isUserMemberOfCommunity(communityId) @@ -302,11 +302,14 @@ method deleteCommunityChat*(self: Module, communityId: string, channelId: string method communityImported*(self: Module, community: CommunityDto) = self.view.addItem(self.getCommunityItem(community)) - self.view.emitImportingCommunityStateChangedSignal(community.id, ImportCommunityState.Imported.int, "") + self.view.emitImportingCommunityStateChangedSignal(community.id, ImportCommunityState.Imported.int, errorMsg = "") -method importCommunity*(self: Module, communityKey: string) = - self.view.emitImportingCommunityStateChangedSignal(communityKey, ImportCommunityState.ImportingInProgress.int, "") - self.controller.importCommunity(communityKey) +method communityDataImported*(self: Module, community: CommunityDto) = + self.view.addItem(self.getCommunityItem(community)) + +method importCommunity*(self: Module, communityId: string) = + self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingInProgress.int, errorMsg = "") + self.controller.importCommunity(communityId) method onImportCommunityErrorOccured*(self: Module, communityId: string, error: string) = self.view.emitImportingCommunityStateChangedSignal(communityId, ImportCommunityState.ImportingError.int, error) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index a5c12d2ccc..d0692d230d 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -440,8 +440,8 @@ QtObject: proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} = self.delegate.requestToJoinCommunity(communityId, ensName) - proc requestCommunityInfo*(self: View, communityId: string) {.slot.} = - self.delegate.requestCommunityInfo(communityId) + proc requestCommunityInfo*(self: View, communityId: string, importing: bool) {.slot.} = + self.delegate.requestCommunityInfo(communityId, importing) proc getCommunityDetails*(self: View, communityId: string): string {.slot.} = let communityItem = self.model.getItemById(communityId) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index a48b79eae7..62ed6869ec 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -937,7 +937,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun if item.isEmpty(): # request community info and then spectate self.statusUrlCommunityToSpectate = communityId - self.communitiesModule.requestCommunityInfo(communityId) + self.communitiesModule.requestCommunityInfo(communityId, importing = false) else: self.setActiveSection(item) @@ -956,7 +956,7 @@ method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, commun let communityIdToSpectate = getCommunityIdFromFullChatId(chatId) # request community info and then spectate self.statusUrlCommunityToSpectate = communityIdToSpectate - self.communitiesModule.requestCommunityInfo(communityIdToSpectate) + self.communitiesModule.requestCommunityInfo(communityIdToSpectate, importing = false) # enable after MVP #else(action == StatusUrlAction.OpenLinkInBrowser and singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()): diff --git a/src/app_service/service/community/async_tasks.nim b/src/app_service/service/community/async_tasks.nim index 77bf32c7e9..d29127c334 100644 --- a/src/app_service/service/community/async_tasks.nim +++ b/src/app_service/service/community/async_tasks.nim @@ -4,9 +4,10 @@ include ../../../app/core/tasks/common type AsyncRequestCommunityInfoTaskArg = ref object of QObjectTaskArg communityId: string + importing: bool const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded) let response = status_go.requestCommunityInfo(arg.communityId) - let tpl: tuple[communityId: string, response: RpcResponse[JsonNode]] = (arg.communityId, response) + let tpl: tuple[communityId: string, response: RpcResponse[JsonNode], importing: bool] = (arg.communityId, response, arg.importing) arg.finish(tpl) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 61a3b385dd..3d89e45560 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -538,7 +538,7 @@ QtObject: proc getCommunityById*(self: Service, communityId: string): CommunityDto = if(not self.joinedCommunities.hasKey(communityId)): - error "error: requested community doesn't exists" + error "error: requested community doesn't exists", communityId return return self.joinedCommunities[communityId] @@ -1189,21 +1189,29 @@ QtObject: return var community = rpcResponseObj{"response"}{"result"}.toCommunityDto() - if community.id != "": - self.allCommunities[community.id] = community - self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community)) - else: + + if community.id == "": community.id = rpcResponseObj{"response"}{"communityId"}.getStr() self.events.emit(SIGNAL_COMMUNITY_LOAD_DATA_FAILED, CommunityArgs(community: community, error: "Couldn't find community info")) + return + + self.allCommunities[community.id] = community + + if rpcResponseObj{"importing"}.getBool(): + self.events.emit(SIGNAL_COMMUNITY_IMPORTED, CommunityArgs(community: community)) + + self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community)) - proc requestCommunityInfo*(self: Service, communityId: string) = + proc requestCommunityInfo*(self: Service, communityId: string, importing = false) = + try: let arg = AsyncRequestCommunityInfoTaskArg( tptr: cast[ByteAddress](asyncRequestCommunityInfoTask), vptr: cast[ByteAddress](self.vptr), slot: "asyncCommunityInfoLoaded", - communityId: communityId + communityId: communityId, + importing: importing ) self.threadpool.start(arg) except Exception as e: diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index c3ad06f13a..8771733ca9 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -356,8 +356,8 @@ QtObject { return communitiesList.getSectionByIdJson(id) } - function requestCommunityInfo(id) { - communitiesModuleInst.requestCommunityInfo(id) + function requestCommunityInfo(id, importing = false) { + communitiesModuleInst.requestCommunityInfo(id, importing) } function getCommunityDetailsAsJson(id) { diff --git a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml index 9040461ca7..d827750daf 100644 --- a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml @@ -300,32 +300,34 @@ Item { Connections { target: root.store + function onImportingCommunityStateChanged(communityId, state, errorMsg) { + + const community = root.store.getCommunityDetailsAsJson(communityId) let title = "" + let subTitle = "" let loading = false - if (state === Constants.communityImported) - { - title = qsTr("Community imported") - } - else if (state === Constants.communityImportingInProgress) + switch (state) { + case Constants.communityImported: + title = qsTr("'%1' community imported").arg(community.name); + break + case Constants.communityImportingInProgress: title = qsTr("Importing community is in progress") loading = true - } - else if (state === Constants.communityImportingError) - { - title = errorMsg - } - - if(title == "") - { - console.error("unknown state while importing community: ", state) + break + case Constants.communityImportingError: + title = qsTr("Failed to import community '%1'").arg(community.name) + subTitle = errorMsg + break + default: + console.error("unknown state while importing community: %1").arg(state) return } Global.displayToastMessage(title, - "", + subTitle, "", loading, Constants.ephemeralNotificationType.normal, diff --git a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml index 01b0c9216c..811d5812e9 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml @@ -89,14 +89,12 @@ QtObject { root.communitiesModuleInst.importCommunity(communityKey); } - function requestCommunityInfo(communityKey) { - let publicKey = communityKey - if (Utils.isCompressedPubKey(communityKey)) { - publicKey = Utils.changeCommunityKeyCompression(communityKey) - } - + function requestCommunityInfo(communityKey, importing = false) { + const publicKey = Utils.isCompressedPubKey(communityKey) + ? Utils.changeCommunityKeyCompression(communityKey) + : communityKey root.mainModuleInst.setCommunityIdToSpectate(publicKey) - root.communitiesModuleInst.requestCommunityInfo(publicKey); + root.communitiesModuleInst.requestCommunityInfo(publicKey, importing) } function setActiveCommunity(communityId) { diff --git a/ui/imports/shared/popups/ImportCommunityPopup.qml b/ui/imports/shared/popups/ImportCommunityPopup.qml index 963bfb167b..f615e8de87 100644 --- a/ui/imports/shared/popups/ImportCommunityPopup.qml +++ b/ui/imports/shared/popups/ImportCommunityPopup.qml @@ -50,7 +50,8 @@ StatusDialog { } if (d.isPublicKey) { importButton.loading = true - root.store.requestCommunityInfo(communityKey) + root.store.requestCommunityInfo(communityKey, true) + root.close(); } } }