fix(discord): Process `delete channel & restart import` button

Fixes: #12684
This commit is contained in:
Boris Melnik 2023-11-10 16:24:35 +03:00
parent b50dfc99c3
commit 69783e173b
6 changed files with 75 additions and 7 deletions

View File

@ -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)
@ -481,3 +481,6 @@ proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataTo
self.silentSigningPath = path
self.silentSigningPin = pin
self.runSignFlow(pin, path, finalDataToSign)
proc removeCommunityChat*(self: Controller, communityId: string, channelId: string) =
self.communityService.deleteCommunityChat(communityId, channelId)

View File

@ -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")

View File

@ -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)

View File

@ -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)
@ -663,6 +685,10 @@ QtObject:
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
self.discordImportChannelId = id

View File

@ -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()
}
}
}
}

View File

@ -195,6 +195,10 @@ QtObject {
root.communitiesModuleInst.requestCancelDiscordChannelImport(id)
}
function removeImportedDiscordChannel() {
root.communitiesModuleInst.removeImportedDiscordChannel()
}
function resetDiscordImport() {
root.communitiesModuleInst.resetDiscordImport(false)
}