fix(discord_import): fix community not cleaned up when it fails

Fixes #12724

The actual issue wasn't reproducible, even if I removed the guards against duplicate names.
But I did find that the community wasn't cleaned up correctly, so I fixed it in this PR. It should limit the confusion and possible issues that could arise.
This commit is contained in:
Jonathan Rainville 2024-02-08 11:44:49 -05:00
parent 568bf8e975
commit d41affabb9
9 changed files with 29 additions and 10 deletions

View File

@ -50,6 +50,9 @@ type DiscordChannelImportProgressSignal* = ref object of Signal
type DiscordCommunityImportCancelledSignal* = ref object of Signal
communityId*: string
type DiscordCommunityImportCleanedUpSignal* = ref object of Signal
communityId*: string
type DiscordCommunityImportFinishedSignal* = ref object of Signal
communityId*: string
@ -155,6 +158,11 @@ proc fromEvent*(T: type DiscordCommunityImportCancelledSignal, event: JsonNode):
result.signalType = SignalType.DiscordCommunityImportCancelled
result.communityId = event["event"]{"communityId"}.getStr()
proc fromEvent*(T: type DiscordCommunityImportCleanedUpSignal, event: JsonNode): DiscordCommunityImportCleanedUpSignal =
result = DiscordCommunityImportCleanedUpSignal()
result.signalType = SignalType.DiscordCommunityImportCleanedUp
result.communityId = event["event"]{"communityId"}.getStr()
proc fromEvent*(T: type DiscordChannelImportFinishedSignal, event: JsonNode): DiscordChannelImportFinishedSignal =
result = DiscordChannelImportFinishedSignal()
result.signalType = SignalType.DiscordChannelImportFinished

View File

@ -48,6 +48,7 @@ type SignalType* {.pure.} = enum
DiscordCommunityImportFinished = "community.discordCommunityImportFinished"
DiscordCommunityImportProgress = "community.discordCommunityImportProgress"
DiscordCommunityImportCancelled = "community.discordCommunityImportCancelled"
DiscordCommunityImportCleanedUp = "community.discordCommunityImportCleanedUp"
DiscordChannelImportFinished = "community.discordChannelImportFinished"
DiscordChannelImportProgress = "community.discordChannelImportProgress"
DiscordChannelImportCancelled = "community.discordChannelImportCancelled"

View File

@ -117,6 +117,7 @@ QtObject:
of SignalType.DiscordCommunityImportFinished: DiscordCommunityImportFinishedSignal.fromEvent(jsonSignal)
of SignalType.DiscordCommunityImportProgress: DiscordCommunityImportProgressSignal.fromEvent(jsonSignal)
of SignalType.DiscordCommunityImportCancelled: DiscordCommunityImportCancelledSignal.fromEvent(jsonSignal)
of SignalType.DiscordCommunityImportCleanedUp: DiscordCommunityImportCleanedUpSignal.fromEvent(jsonSignal)
of SignalType.DiscordChannelImportFinished: DiscordChannelImportFinishedSignal.fromEvent(jsonSignal)
of SignalType.DiscordChannelImportProgress: DiscordChannelImportProgressSignal.fromEvent(jsonSignal)
of SignalType.DiscordChannelImportCancelled: DiscordChannelImportCancelledSignal.fromEvent(jsonSignal)

View File

@ -655,6 +655,9 @@ QtObject:
self.delegate.removeCommunityChat(self.discordImportedChannelCommunityId, self.discordImportedChannelId)
self.resetDiscordImport(true)
proc resetImport*(self: View) {.slot.} =
self.resetDiscordImport(true)
proc toggleDiscordCategory*(self: View, id: string, selected: bool) {.slot.} =
if selected:
self.discordCategoriesModel.selectItem(id)

View File

@ -1062,8 +1062,6 @@ method communityLeft*[T](self: Module[T], communityId: string) =
echo "main-module, unexisting community key to leave: ", communityId
return
self.channelGroupModules.del(communityId)
self.view.model().removeItem(communityId)
singletonInstance.localAccountSensitiveSettings.removeSectionChatRecord(communityId)

View File

@ -358,6 +358,10 @@ QtObject:
var receivedData = DiscordCommunityImportCancelledSignal(e)
self.events.emit(SIGNAL_DISCORD_COMMUNITY_IMPORT_CANCELED, CommunityIdArgs(communityId: receivedData.communityId))
self.events.on(SignalType.DiscordCommunityImportCleanedUp.event) do(e: Args):
var receivedData = DiscordCommunityImportCleanedUpSignal(e)
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: receivedData.communityId))
self.events.on(SignalType.DiscordChannelImportFinished.event) do(e: Args):
var receivedData = DiscordChannelImportFinishedSignal(e)
self.events.emit(SIGNAL_DISCORD_CHANNEL_IMPORT_FINISHED, CommunityChatIdArgs(chatId: receivedData.channelId, communityId: receivedData.communityId))

View File

@ -38,12 +38,12 @@ StatusScrollView {
visible: d.status === DiscordImportProgressContents.ImportStatus.CompletedWithWarnings ||
d.status === DiscordImportProgressContents.ImportStatus.StoppedWithErrors
type: StatusButton.Danger
text: root.importingSingleChannel ? qsTr("Delete channel & restart import") : qsTr("Delete community & restart import")
text: root.importingSingleChannel ? qsTr("Delete channel & restart import") : qsTr("Close & restart import")
onClicked: {
if (root.importingSingleChannel) {
Global.openPopup(deleteAndRestartConfirmationPopupCmp)
Global.openPopup(deleteChannelAndRestartConfirmationPopupCmp)
} else {
// TODO do similar for community import
root.store.resetImport()
root.close()
}
}
@ -370,9 +370,9 @@ StatusScrollView {
}
Component {
id: deleteAndRestartConfirmationPopupCmp
id: deleteChannelAndRestartConfirmationPopupCmp
ConfirmationDialog {
id: deleteAndRestartConfirmationPopup
id: deleteChannelAndRestartConfirmationPopup
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
@ -381,11 +381,11 @@ StatusScrollView {
cancelButtonLabel: qsTr("Cancel")
onConfirmButtonClicked: {
root.store.removeImportedDiscordChannel()
deleteAndRestartConfirmationPopup.close()
deleteChannelAndRestartConfirmationPopup.close()
root.close()
}
onCancelButtonClicked: {
deleteAndRestartConfirmationPopup.close()
deleteChannelAndRestartConfirmationPopup.close()
}
onClosed: {
destroy()

View File

@ -193,6 +193,10 @@ QtObject {
root.communitiesModuleInst.requestCancelDiscordChannelImport(id)
}
function resetImport() {
root.communitiesModuleInst.resetImport()
}
function removeImportedDiscordChannel() {
root.communitiesModuleInst.removeImportedDiscordChannel()
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit af16669787f8f9078a1085e18076cc4dc1b946f4
Subproject commit 1c42c077603dbd37cb10ebc5cccb755925fc812b