From 69783e173b2d841432f148c755b033190edd01e1 Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Fri, 10 Nov 2023 16:24:35 +0300 Subject: [PATCH] fix(discord): Process `delete channel & restart import` button Fixes: #12684 --- .../modules/main/communities/controller.nim | 7 ++-- .../modules/main/communities/io_interface.nim | 5 ++- src/app/modules/main/communities/module.nim | 8 +++-- src/app/modules/main/communities/view.nim | 26 +++++++++++++++ .../popups/DiscordImportProgressContents.qml | 32 +++++++++++++++++-- .../Communities/stores/CommunitiesStore.qml | 4 +++ 6 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 8fe4b8ff03..0faf320e54 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -142,7 +142,7 @@ proc init*(self: Controller) = self.events.on(SIGNAL_DISCORD_CHANNEL_IMPORT_FINISHED) do(e:Args): let args = CommunityChatIdArgs(e) - self.delegate.discordImportChannelFinished(args.chatId) + self.delegate.discordImportChannelFinished(args.communityId, args.chatId) self.events.on(SIGNAL_DISCORD_CHANNEL_IMPORT_CANCELED) do(e:Args): let args = ChannelIdArgs(e) @@ -480,4 +480,7 @@ proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataTo self.silentSigningKeyUid = keyUid self.silentSigningPath = path self.silentSigningPin = pin - self.runSignFlow(pin, path, finalDataToSign) \ No newline at end of file + self.runSignFlow(pin, path, finalDataToSign) + +proc removeCommunityChat*(self: Controller, communityId: string, channelId: string) = + self.communityService.deleteCommunityChat(communityId, channelId) diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index f5963a583f..8bd95dae4a 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -160,7 +160,7 @@ method discordImportChannelProgressUpdated*( ) {.base.} = raise newException(ValueError, "No implementation available") -method discordImportChannelFinished*(self: AccessInterface, channelId: string) {.base.} = +method discordImportChannelFinished*(self: AccessInterface, communityId: string, channelId: string) {.base.} = raise newException(ValueError, "No implementation available") method discordImportChannelCanceled*(self: AccessInterface, channelId: string) {.base.} = @@ -255,3 +255,6 @@ method onCommunityMemberRevealedAccountsLoaded*(self: AccessInterface, community method onAllCommunityTokensLoaded*(self: AccessInterface, communityTokens: seq[CommunityTokenDto]) {.base.} = raise newException(ValueError, "No implementation available") + +method removeCommunityChat*(self: AccessInterface, communityId: string, channelId: 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 92c4bd3acb..8f60840b1d 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -475,8 +475,12 @@ method discordImportProgressUpdated*( if stopped or progress.int >= 1: self.view.setDiscordImportInProgress(false) -method discordImportChannelFinished*(self: Module, channelId: string) = - if self.view.getDiscordImportChannelId() == channelId: +method removeCommunityChat*(self: Module, communityId: string, channelId: string) = + self.controller.removeCommunityChat(communityId, channelId) + +method discordImportChannelFinished*(self: Module, communityId: string, channelId: string) = + self.view.setDiscordImportedChannelCommunityId(communityId) + self.view.setDiscordImportedChannelId(channelId) self.view.setDiscordImportProgress(100) self.view.setDiscordImportProgressStopped(true) self.view.setDiscordImportInProgress(false) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 02c60d0a4e..9900a1fe2f 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -50,6 +50,8 @@ QtObject: discordImportChannelId: string discordImportChannelName: string discordImportCommunityImage: string + discordImportedChannelId: string + discordImportedChannelCommunityId: string discordImportHasCommunityImage: bool downloadingCommunityHistoryArchives: bool checkingPermissionsInProgress: bool @@ -192,6 +194,20 @@ QtObject: read = getDiscordImportWarningsCount notify = discordImportWarningsCountChanged + proc discordImportedChannelIdChanged*(self: View) {.signal.} + + proc setDiscordImportedChannelId*(self: View, id: string) = + if (self.discordImportedChannelId == id): return + self.discordImportedChannelId = id + self.discordImportedChannelIdChanged() + + proc getDiscordImportedChannelId*(self: View): string {.slot.} = + return self.discordImportedChannelId + + QtProperty[int] discordImportedChannelId: + read = getDiscordImportedChannelIdCount + notify = discordImportedChannelIdChanged + proc setDiscordImportErrorsCount*(self: View, count: int) = if (self.discordImportErrorsCount == count): return self.discordImportErrorsCount = count @@ -499,6 +515,8 @@ QtObject: self.setDiscordImportCommunityName("") self.discordImportChannelId = "" self.discordImportChannelName = "" + self.discordImportedChannelId = "" + self.discordImportedChannelCommunityId = "" self.setDiscordImportCommunityImage("") self.setDiscordImportHasCommunityImage(false) self.setDiscordImportInProgress(false) @@ -634,6 +652,10 @@ QtObject: self.delegate.requestCancelDiscordChannelImport(discordChannelId) self.resetDiscordImport(true) + proc removeImportedDiscordChannel*(self: View) {.slot.} = + self.delegate.removeCommunityChat(self.discordImportedChannelCommunityId, self.discordImportedChannelId) + self.resetDiscordImport(true) + proc toggleDiscordCategory*(self: View, id: string, selected: bool) {.slot.} = if selected: self.discordCategoriesModel.selectItem(id) @@ -662,6 +684,10 @@ QtObject: self.discordImportChannelId = id self.discordImportChannelName = item.getName() self.discordImportChannelChanged() + + proc setDiscordImportedChannelCommunityId*(self: View, id: string) = + if (self.discordImportedChannelCommunityId == id): return + self.discordImportedChannelCommunityId = id proc setDiscordImportChannelId*(self: View, id: string) {.slot.} = if (self.discordImportChannelId == id): return diff --git a/ui/app/AppLayouts/Communities/popups/DiscordImportProgressContents.qml b/ui/app/AppLayouts/Communities/popups/DiscordImportProgressContents.qml index 6f68f79892..b0253c3ab1 100644 --- a/ui/app/AppLayouts/Communities/popups/DiscordImportProgressContents.qml +++ b/ui/app/AppLayouts/Communities/popups/DiscordImportProgressContents.qml @@ -40,8 +40,12 @@ StatusScrollView { type: StatusButton.Danger text: root.importingSingleChannel ? qsTr("Delete channel & restart import") : qsTr("Delete community & restart import") onClicked: { - // TODO display a confirmation and restart the whole flow - root.close() + if (root.importingSingleChannel) { + Global.openPopup(deleteAndRestartConfirmationPopupCmp) + } else { + // TODO do similar for community import + root.close() + } } }, StatusButton { @@ -364,4 +368,28 @@ StatusScrollView { } } } + + Component { + id: deleteAndRestartConfirmationPopupCmp + ConfirmationDialog { + id: deleteAndRestartConfirmationPopup + headerSettings.title: qsTr("Are you sure you want to delete the channel?") + confirmationText: qsTr("Your new Status channel will be deleted and all information entered will be lost.") + showCancelButton: true + cancelBtnType: "default" + confirmButtonLabel: qsTr("Delete channel & cancel import") + cancelButtonLabel: qsTr("Cancel") + onConfirmButtonClicked: { + root.store.removeImportedDiscordChannel() + deleteAndRestartConfirmationPopup.close() + root.close() + } + onCancelButtonClicked: { + deleteAndRestartConfirmationPopup.close() + } + onClosed: { + destroy() + } + } + } } diff --git a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml index f5a0595103..9258508624 100644 --- a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml @@ -195,6 +195,10 @@ QtObject { root.communitiesModuleInst.requestCancelDiscordChannelImport(id) } + function removeImportedDiscordChannel() { + root.communitiesModuleInst.removeImportedDiscordChannel() + } + function resetDiscordImport() { root.communitiesModuleInst.resetDiscordImport(false) }