From b00f0a80b5f743ba90d144a8468f39c31f14eb25 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+0x-r4bbit@users.noreply.github.com> Date: Thu, 26 Jan 2023 15:32:23 +0100 Subject: [PATCH] Adjust import tool front-end to latest refactor This adjust the front-end for the import tool by handling new properties that have been added to the discord import progress signals. Namely, the import is now done in chunks, so the progress signal contains information about how many chunks have been processed. This needs: https://github.com/status-im/status-go/pull/3134 Closes #9262 #9261 --- .../core/signals/remote_signals/community.nim | 4 +++ .../modules/main/communities/controller.nim | 2 +- .../modules/main/communities/io_interface.nim | 2 +- src/app/modules/main/communities/module.nim | 4 ++- src/app/modules/main/communities/view.nim | 30 +++++++++++++++++++ src/app_service/service/community/service.nim | 6 +++- .../popups/DiscordImportProgressContents.qml | 6 ++-- .../stores/CommunitiesStore.qml | 2 ++ vendor/status-go | 2 +- 9 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/app/core/signals/remote_signals/community.nim b/src/app/core/signals/remote_signals/community.nim index 43fb606296..8262d7e316 100644 --- a/src/app/core/signals/remote_signals/community.nim +++ b/src/app/core/signals/remote_signals/community.nim @@ -29,6 +29,8 @@ type DiscordCommunityImportProgressSignal* = ref object of Signal errorsCount*: int warningsCount*: int stopped*: bool + totalChunksCount*: int + currentChunk*: int type DiscordCommunityImportFinishedSignal* = ref object of Signal communityId*: string @@ -74,6 +76,8 @@ proc fromEvent*(T: type DiscordCommunityImportProgressSignal, event: JsonNode): result.errorsCount = importProgressObj{"errorsCount"}.getInt() result.warningsCount = importProgressObj{"warningsCount"}.getInt() result.stopped = importProgressObj{"stopped"}.getBool() + result.totalChunksCount = importProgressObj{"totalChunksCount"}.getInt() + result.currentChunk = importProgressObj{"currentChunk"}.getInt() if importProgressObj["communityImages"].kind == JObject: result.communityImages = chat.toImages(importProgressObj["communityImages"]) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 5e25939102..76b8636ee9 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -76,7 +76,7 @@ proc init*(self: Controller) = self.events.on(SIGNAL_DISCORD_COMMUNITY_IMPORT_PROGRESS) do(e:Args): let args = DiscordImportProgressArgs(e) - self.delegate.discordImportProgressUpdated(args.communityId, args.communityName, args.communityImage, args.tasks, args.progress, args.errorsCount, args.warningsCount, args.stopped) + self.delegate.discordImportProgressUpdated(args.communityId, args.communityName, args.communityImage, args.tasks, args.progress, args.errorsCount, args.warningsCount, args.stopped, args.totalChunksCount, args.currentChunk) self.events.on(SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_STARTED) do(e:Args): let args = CommunityIdArgs(e) diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index 7162970c5b..f740e548d7 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -134,7 +134,7 @@ method requestExtractDiscordChannelsAndCategories*(self: AccessInterface, filesT method discordCategoriesAndChannelsExtracted*(self: AccessInterface, categories: seq[DiscordCategoryDto], channels: seq[DiscordChannelDto], oldestMessageTimestamp: int, errors: Table[string, DiscordImportError], errorsCount: int) {.base.} = raise newException(ValueError, "No implementation available") -method discordImportProgressUpdated*(self: AccessInterface, communityId: string, communityName: string, communityImage: string, tasks: seq[DiscordImportTaskProgress], progress: float, errorsCount: int, warningsCount: int, stopped: bool) {.base.} = +method discordImportProgressUpdated*(self: AccessInterface, communityId: string, communityName: string, communityImage: string, tasks: seq[DiscordImportTaskProgress], progress: float, errorsCount: int, warningsCount: int, stopped: bool, totalChunksCount: int, currentChunk: int) {.base.} = raise newException(ValueError, "No implementation available") method requestCancelDiscordCommunityImport*(self: AccessInterface, id: string) {.base.} = diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index c9ff35484c..2bb8b66aba 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -335,7 +335,7 @@ method getDiscordImportTaskItem(self: Module, t: DiscordImportTaskProgress): Dis t.errorsCount, t.warningsCount) -method discordImportProgressUpdated*(self: Module, communityId: string, communityName: string, communityImage: string, tasks: seq[DiscordImportTaskProgress], progress: float, errorsCount: int, warningsCount: int, stopped: bool) = +method discordImportProgressUpdated*(self: Module, communityId: string, communityName: string, communityImage: string, tasks: seq[DiscordImportTaskProgress], progress: float, errorsCount: int, warningsCount: int, stopped: bool, totalChunksCount: int, currentChunk: int) = var taskItems: seq[DiscordImportTaskItem] = @[] @@ -355,6 +355,8 @@ method discordImportProgressUpdated*(self: Module, communityId: string, communit # That's why we pass it as integer instead. self.view.setDiscordImportProgress((progress*100).int) self.view.setDiscordImportProgressStopped(stopped) + self.view.setDiscordImportProgressTotalChunksCount(totalChunksCount) + self.view.setDiscordImportProgressCurrentChunk(currentChunk) if stopped or progress.int >= 1: self.view.setDiscordImportInProgress(false) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index d0692d230d..5e6b4d6e63 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -38,6 +38,8 @@ QtObject: discordImportInProgress: bool discordImportCancelled: bool discordImportProgressStopped: bool + discordImportProgressTotalChunksCount: int + discordImportProgressCurrentChunk: int discordImportTasksModel: DiscordImportTasksModel discordImportTasksModelVariant: QVariant discordDataExtractionInProgress: bool @@ -226,6 +228,34 @@ QtObject: read = getDiscordImportProgressStopped notify = discordImportProgressStoppedChanged + proc discordImportProgressTotalChunksCountChanged*(self: View) {.signal.} + + proc setDiscordImportProgressTotalChunksCount*(self: View, count: int) {.slot.} = + if (self.discordImportProgressTotalChunksCount == count): return + self.discordImportProgressTotalChunksCount = count + self.discordImportProgressTotalChunksCountChanged() + + proc getDiscordImportProgressTotalChunksCount*(self: View): int {.slot.} = + return self.discordImportProgressTotalChunksCount + + QtProperty[int] discordImportProgressTotalChunksCount: + read = getDiscordImportProgressTotalChunksCount + notify = discordImportProgressTotalChunksCountChanged + + proc discordImportProgressCurrentChunkChanged*(self: View) {.signal.} + + proc setDiscordImportProgressCurrentChunk*(self: View, count: int) {.slot.} = + if (self.discordImportProgressCurrentChunk == count): return + self.discordImportProgressCurrentChunk = count + self.discordImportProgressCurrentChunkChanged() + + proc getDiscordImportProgressCurrentChunk*(self: View): int {.slot.} = + return self.discordImportProgressCurrentChunk + + QtProperty[int] discordImportProgressCurrentChunk: + read = getDiscordImportProgressCurrentChunk + notify = discordImportProgressCurrentChunkChanged + proc addItem*(self: View, item: SectionItem) = self.model.addItem(item) self.communityAdded(item.id) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 3d89e45560..5e5f057ffe 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -91,6 +91,8 @@ type errorsCount*: int warningsCount*: int stopped*: bool + totalChunksCount*: int + currentChunk*: int # Signals which may be emitted by this service: const SIGNAL_COMMUNITY_JOINED* = "communityJoined" @@ -257,7 +259,9 @@ QtObject: progress: receivedData.progress, errorsCount: receivedData.errorsCount, warningsCount: receivedData.warningsCount, - stopped: receivedData.stopped + stopped: receivedData.stopped, + totalChunksCount: receivedData.totalChunksCount, + currentChunk: receivedData.currentChunk, )) self.events.on(SignalType.ImportingHistoryArchiveMessages.event) do(e: Args): diff --git a/ui/app/AppLayouts/CommunitiesPortal/popups/DiscordImportProgressContents.qml b/ui/app/AppLayouts/CommunitiesPortal/popups/DiscordImportProgressContents.qml index 3d04f4f944..eb05aa1f91 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/popups/DiscordImportProgressContents.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/popups/DiscordImportProgressContents.qml @@ -110,6 +110,8 @@ StatusScrollView { readonly property bool importStopped: root.store.discordImportProgressStopped readonly property bool hasErrors: root.store.discordImportErrorsCount readonly property bool hasWarnings: root.store.discordImportWarningsCount + readonly property int totalChunksCount: root.store.discordImportProgressTotalChunksCount + readonly property int currentChunk: root.store.discordImportProgressCurrentChunk readonly property int status: { if (importStopped) { @@ -137,9 +139,7 @@ StatusScrollView { if (progress <= 0.0) return qsTr("Pending...") - return state === "import.taskState.saving" ? - qsTr("Saving... This can take a moment, almost done!") : - qsTr("Working...") + return qsTr("Importing from file %1 of %2...").arg(currentChunk).arg(totalChunksCount) } } diff --git a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml index 811d5812e9..ced36f237e 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml @@ -22,6 +22,8 @@ QtObject { property bool discordImportInProgress: root.communitiesModuleInst.discordImportInProgress property bool discordImportCancelled: root.communitiesModuleInst.discordImportCancelled property bool discordImportProgressStopped: root.communitiesModuleInst.discordImportProgressStopped + property int discordImportProgressTotalChunksCount: root.communitiesModuleInst.discordImportProgressTotalChunksCount + property int discordImportProgressCurrentChunk: root.communitiesModuleInst.discordImportProgressCurrentChunk property string discordImportCommunityId: root.communitiesModuleInst.discordImportCommunityId property string discordImportCommunityName: root.communitiesModuleInst.discordImportCommunityName property url discordImportCommunityImage: root.communitiesModuleInst.discordImportCommunityImage diff --git a/vendor/status-go b/vendor/status-go index ee9f8edfcf..f31e40264e 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit ee9f8edfcf66eb0df752489d8558edf4ce3bf5ae +Subproject commit f31e40264e5d225bc02c4a2e6c8a532c43f0ff8e