Skip to content

Commit

Permalink
Adjust import tool front-end to latest refactor
Browse files Browse the repository at this point in the history
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: status-im/status-go#3134

Closes #9262 #9261
  • Loading branch information
0x-r4bbit committed Jan 30, 2023
1 parent 470200a commit b00f0a8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/app/core/signals/remote_signals/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] = @[]

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

Expand Down
30 changes: 30 additions & 0 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ QtObject:
discordImportInProgress: bool
discordImportCancelled: bool
discordImportProgressStopped: bool
discordImportProgressTotalChunksCount: int
discordImportProgressCurrentChunk: int
discordImportTasksModel: DiscordImportTasksModel
discordImportTasksModelVariant: QVariant
discordDataExtractionInProgress: bool
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b00f0a8

Please sign in to comment.