Skip to content

Commit

Permalink
fix(discord): Process delete channel & restart import button
Browse files Browse the repository at this point in the history
Fixes: #12684
  • Loading branch information
borismelnik committed Nov 10, 2023
1 parent a3ef9d6 commit 122a403
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
self.runSignFlow(pin, path, finalDataToSign)

proc removeCommunityChat*(self: Controller, communityId: string, channelId: string) =
self.communityService.deleteCommunityChat(communityId, channelId)
5 changes: 4 additions & 1 deletion src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down Expand Up @@ -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")
8 changes: 6 additions & 2 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ QtObject:
discordImportChannelId: string
discordImportChannelName: string
discordImportCommunityImage: string
discordImportedChannelId: string
discordImportedChannelCommunityId: string
discordImportHasCommunityImage: bool
downloadingCommunityHistoryArchives: bool
checkingPermissionsInProgress: bool
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -499,6 +515,8 @@ QtObject:
self.setDiscordImportCommunityName("")
self.discordImportChannelId = ""
self.discordImportChannelName = ""
self.discordImportedChannelId = ""
self.discordImportedChannelCommunityId = ""
self.setDiscordImportCommunityImage("")
self.setDiscordImportHasCommunityImage(false)
self.setDiscordImportInProgress(false)
Expand Down Expand Up @@ -634,6 +652,11 @@ QtObject:
self.delegate.requestCancelDiscordChannelImport(discordChannelId)
self.resetDiscordImport(true)

proc removeImportedDiscordChannel*(self: View) {.slot.} =
echo "LALALA ", self.discordImportedChannelCommunityId, " " , self.discordImportedChannelId
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)
Expand Down Expand Up @@ -662,6 +685,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 %1 will be deleted and all information entered will be lost.").arg(root.importingSingleChannel ? qsTr("channel") : qsTr("community"))
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()
}
}
}
}
4 changes: 4 additions & 0 deletions ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ QtObject {
root.communitiesModuleInst.requestCancelDiscordChannelImport(id)
}

function removeImportedDiscordChannel() {
root.communitiesModuleInst.removeImportedDiscordChannel()
}

function resetDiscordImport() {
root.communitiesModuleInst.resetDiscordImport(false)
}
Expand Down

0 comments on commit 122a403

Please sign in to comment.