Add banner that indicates history archive downloads are in progress

This needs: https://github.com/status-im/status-go/pull/2995
This commit is contained in:
Pascal Precht 2022-12-01 16:10:51 +01:00 committed by r4bbit.eth
parent 9ded9d4ffa
commit d5db1e6356
11 changed files with 82 additions and 2 deletions

View File

@ -125,6 +125,11 @@ proc historyArchiveDownloadedFromEvent*(T: type HistoryArchivesSignal, event: Js
result = HistoryArchivesSignal.createFromEvent(event) result = HistoryArchivesSignal.createFromEvent(event)
result.signalType = SignalType.HistoryArchiveDownloaded result.signalType = SignalType.HistoryArchiveDownloaded
proc downloadingHistoryArchivesStartedFromEvent*(T: type HistoryArchivesSignal, event: JsonNode): HistoryArchivesSignal =
result = HistoryArchivesSignal()
result.communityId = event["event"]{"communityId"}.getStr()
result.signalType = SignalType.DownloadingHistoryArchivesStarted
proc downloadingHistoryArchivesFinishedFromEvent*(T: type HistoryArchivesSignal, event: JsonNode): HistoryArchivesSignal = proc downloadingHistoryArchivesFinishedFromEvent*(T: type HistoryArchivesSignal, event: JsonNode): HistoryArchivesSignal =
result = HistoryArchivesSignal() result = HistoryArchivesSignal()
result.communityId = event["event"]{"communityId"}.getStr() result.communityId = event["event"]{"communityId"}.getStr()

View File

@ -39,6 +39,7 @@ type SignalType* {.pure.} = enum
HistoryArchivesSeeding = "community.historyArchivesSeeding" HistoryArchivesSeeding = "community.historyArchivesSeeding"
HistoryArchivesUnseeded = "community.historyArchivesUnseeded" HistoryArchivesUnseeded = "community.historyArchivesUnseeded"
HistoryArchiveDownloaded = "community.historyArchiveDownloaded" HistoryArchiveDownloaded = "community.historyArchiveDownloaded"
DownloadingHistoryArchivesStarted = "community.downloadingHistoryArchivesStarted"
DownloadingHistoryArchivesFinished = "community.downloadingHistoryArchivesFinished" DownloadingHistoryArchivesFinished = "community.downloadingHistoryArchivesFinished"
UpdateAvailable = "update.available" UpdateAvailable = "update.available"
DiscordCategoriesAndChannelsExtracted = "community.discordCategoriesAndChannelsExtracted" DiscordCategoriesAndChannelsExtracted = "community.discordCategoriesAndChannelsExtracted"

View File

@ -93,6 +93,7 @@ QtObject:
of SignalType.HistoryArchivesSeeding: HistoryArchivesSignal.historyArchivesSeedingFromEvent(jsonSignal) of SignalType.HistoryArchivesSeeding: HistoryArchivesSignal.historyArchivesSeedingFromEvent(jsonSignal)
of SignalType.HistoryArchivesUnseeded: HistoryArchivesSignal.historyArchivesUnseededFromEvent(jsonSignal) of SignalType.HistoryArchivesUnseeded: HistoryArchivesSignal.historyArchivesUnseededFromEvent(jsonSignal)
of SignalType.HistoryArchiveDownloaded: HistoryArchivesSignal.historyArchiveDownloadedFromEvent(jsonSignal) of SignalType.HistoryArchiveDownloaded: HistoryArchivesSignal.historyArchiveDownloadedFromEvent(jsonSignal)
of SignalType.DownloadingHistoryArchivesStarted: HistoryArchivesSignal.downloadingHistoryArchivesStartedFromEvent(jsonSignal)
of SignalType.DownloadingHistoryArchivesFinished: HistoryArchivesSignal.downloadingHistoryArchivesFinishedFromEvent(jsonSignal) of SignalType.DownloadingHistoryArchivesFinished: HistoryArchivesSignal.downloadingHistoryArchivesFinishedFromEvent(jsonSignal)
of SignalType.UpdateAvailable: UpdateAvailableSignal.fromEvent(jsonSignal) of SignalType.UpdateAvailable: UpdateAvailableSignal.fromEvent(jsonSignal)
of SignalType.DiscordCategoriesAndChannelsExtracted: DiscordCategoriesAndChannelsExtractedSignal.fromEvent(jsonSignal) of SignalType.DiscordCategoriesAndChannelsExtracted: DiscordCategoriesAndChannelsExtractedSignal.fromEvent(jsonSignal)

View File

@ -74,6 +74,14 @@ proc init*(self: Controller) =
let args = DiscordImportProgressArgs(e) 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)
self.events.on(SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_STARTED) do(e:Args):
let args = CommunityIdArgs(e)
self.delegate.communityHistoryArchivesDownloadStarted(args.communityId)
self.events.on(SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_FINISHED) do(e:Args):
let args = CommunityIdArgs(e)
self.delegate.communityHistoryArchivesDownloadFinished(args.communityId)
proc getCommunityTags*(self: Controller): string = proc getCommunityTags*(self: Controller): string =
result = self.communityService.getCommunityTags() result = self.communityService.getCommunityTags()

View File

@ -136,3 +136,10 @@ method discordImportProgressUpdated*(self: AccessInterface, communityId: string,
method requestCancelDiscordCommunityImport*(self: AccessInterface, id: string) {.base.} = method requestCancelDiscordCommunityImport*(self: AccessInterface, id: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method communityHistoryArchivesDownloadStarted*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method communityHistoryArchivesDownloadFinished*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -252,6 +252,12 @@ method communityMuted*(self: Module, communityId: string, muted: bool) =
method communityAccessRequested*(self: Module, communityId: string) = method communityAccessRequested*(self: Module, communityId: string) =
self.view.communityAccessRequested(communityId) self.view.communityAccessRequested(communityId)
method communityHistoryArchivesDownloadStarted*(self: Module, communityId: string) =
self.view.setDownloadingCommunityHistoryArchives(true)
method communityHistoryArchivesDownloadFinished*(self: Module, communityId: string) =
self.view.setDownloadingCommunityHistoryArchives(false)
method discordCategoriesAndChannelsExtracted*(self: Module, categories: seq[DiscordCategoryDto], channels: seq[DiscordChannelDto], oldestMessageTimestamp: int, errors: Table[string, DiscordImportError], errorsCount: int) = method discordCategoriesAndChannelsExtracted*(self: Module, categories: seq[DiscordCategoryDto], channels: seq[DiscordChannelDto], oldestMessageTimestamp: int, errors: Table[string, DiscordImportError], errorsCount: int) =
for filePath in errors.keys: for filePath in errors.keys:

View File

@ -45,6 +45,7 @@ QtObject:
discordImportCommunityName: string discordImportCommunityName: string
discordImportCommunityImage: string discordImportCommunityImage: string
discordImportHasCommunityImage: bool discordImportHasCommunityImage: bool
downloadingCommunityHistoryArchives: bool
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
@ -89,6 +90,7 @@ QtObject:
result.discordImportTasksModel = newDiscordDiscordImportTasksModel() result.discordImportTasksModel = newDiscordDiscordImportTasksModel()
result.discordImportTasksModelVariant = newQVariant(result.discordImportTasksModel) result.discordImportTasksModelVariant = newQVariant(result.discordImportTasksModel)
result.observedItem = newActiveSection() result.observedItem = newActiveSection()
result.downloadingCommunityHistoryArchives = false
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
@ -114,6 +116,20 @@ QtObject:
read = getDiscordOldestMessageTimestamp read = getDiscordOldestMessageTimestamp
notify = discordOldestMessageTimestampChanged notify = discordOldestMessageTimestampChanged
proc downloadingCommunityHistoryArchivesChanged*(self: View) {.signal.}
proc setDownloadingCommunityHistoryArchives*(self: View, flag: bool) {.slot.} =
if (self.downloadingCommunityHistoryArchives == flag): return
self.downloadingCommunityHistoryArchives = flag
self.downloadingCommunityHistoryArchivesChanged()
proc getDownloadingCommunityHistoryArchives*(self: View): bool {.slot.} =
return self.downloadingCommunityHistoryArchives
QtProperty[bool] downloadingCommunityHistoryArchives:
read = getDownloadingCommunityHistoryArchives
notify = downloadingCommunityHistoryArchivesChanged
proc discordImportHasCommunityImageChanged*(self: View) {.signal.} proc discordImportHasCommunityImageChanged*(self: View) {.signal.}
proc setDiscordImportHasCommunityImage*(self: View, hasImage: bool) {.slot.} = proc setDiscordImportHasCommunityImage*(self: View, hasImage: bool) {.slot.} =

View File

@ -1,4 +1,4 @@
import NimQml, Tables, json, sequtils, std/algorithm, strformat, strutils, chronicles, json_serialization, sugar import NimQml, Tables, json, sequtils, std/sets, std/algorithm, strformat, strutils, chronicles, json_serialization, sugar
import ./dto/community as community_dto import ./dto/community as community_dto
@ -119,6 +119,8 @@ const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound"
const SIGNAL_COMMUNITY_MUTED* = "communityMuted" const SIGNAL_COMMUNITY_MUTED* = "communityMuted"
const SIGNAL_CATEGORY_MUTED* = "categoryMuted" const SIGNAL_CATEGORY_MUTED* = "categoryMuted"
const SIGNAL_CATEGORY_UNMUTED* = "categoryUnmuted" const SIGNAL_CATEGORY_UNMUTED* = "categoryUnmuted"
const SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_STARTED* = "communityHistoryArchivesDownloadStarted"
const SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_FINISHED* = "communityHistoryArchivesDownloadFinished"
const SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED* = "discordCategoriesAndChannelsExtracted" const SIGNAL_DISCORD_CATEGORIES_AND_CHANNELS_EXTRACTED* = "discordCategoriesAndChannelsExtracted"
const SIGNAL_DISCORD_COMMUNITY_IMPORT_FINISHED* = "discordCommunityImportFinished" const SIGNAL_DISCORD_COMMUNITY_IMPORT_FINISHED* = "discordCommunityImportFinished"
@ -136,6 +138,7 @@ QtObject:
curatedCommunities: Table[string, CuratedCommunity] # [community_id, CuratedCommunity] curatedCommunities: Table[string, CuratedCommunity] # [community_id, CuratedCommunity]
allCommunities: Table[string, CommunityDto] # [community_id, CommunityDto] allCommunities: Table[string, CommunityDto] # [community_id, CommunityDto]
myCommunityRequests*: seq[CommunityMembershipRequestDto] myCommunityRequests*: seq[CommunityMembershipRequestDto]
historyArchiveDownloadTaskCommunityIds*: HashSet[string]
# Forward declaration # Forward declaration
proc loadCommunityTags(self: Service): string proc loadCommunityTags(self: Service): string
@ -172,6 +175,7 @@ QtObject:
result.curatedCommunities = initTable[string, CuratedCommunity]() result.curatedCommunities = initTable[string, CuratedCommunity]()
result.allCommunities = initTable[string, CommunityDto]() result.allCommunities = initTable[string, CommunityDto]()
result.myCommunityRequests = @[] result.myCommunityRequests = @[]
result.historyArchiveDownloadTaskCommunityIds = initHashSet[string]()
proc doConnect(self: Service) = proc doConnect(self: Service) =
self.events.on(SignalType.CommunityFound.event) do(e: Args): self.events.on(SignalType.CommunityFound.event) do(e: Args):
@ -250,6 +254,28 @@ QtObject:
stopped: receivedData.stopped stopped: receivedData.stopped
)) ))
self.events.on(SignalType.DownloadingHistoryArchivesStarted.event) do(e: Args):
var receivedData = HistoryArchivesSignal(e)
if receivedData.communityId notin self.historyArchiveDownloadTaskCommunityIds:
self.historyArchiveDownloadTaskCommunityIds.incl(receivedData.communityId)
self.events.emit(SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_STARTED, CommunityIdArgs(communityId: receivedData.communityId))
self.events.on(SignalType.DownloadingHistoryArchivesFinished.event) do(e: Args):
var receivedData = HistoryArchivesSignal(e)
if receivedData.communityId in self.historyArchiveDownloadTaskCommunityIds:
self.historyArchiveDownloadTaskCommunityIds.excl(receivedData.communityId)
if self.historyArchiveDownloadTaskCommunityIds.len == 0:
# Right now we're only emitting this signal when all download tasks have been marked as finished
# so passing the `CommunityIdArgs` is not very useful because it'll always emit the latest community
# id that has finished. We'll handle signals related to individual communities in the future
# once we've figured out what this should look like in the UI
#
# TODO(pascal):
# Don't just emit this signal when all communities are done downloading history data,
# but implement a solution for individual updates
self.events.emit(SIGNAL_COMMUNITY_HISTORY_ARCHIVES_DOWNLOAD_FINISHED, CommunityIdArgs(communityId: receivedData.communityId))
proc updateMissingFields(chatDto: var ChatDto, chat: ChatDto) = proc updateMissingFields(chatDto: var ChatDto, chat: ChatDto) =
# This proc sets fields of `chatDto` which are available only for community channels. # This proc sets fields of `chatDto` which are available only for community channels.
chatDto.position = chat.position chatDto.position = chat.position

View File

@ -24,6 +24,7 @@ QtObject {
property url discordImportCommunityImage: root.communitiesModuleInst.discordImportCommunityImage property url discordImportCommunityImage: root.communitiesModuleInst.discordImportCommunityImage
property bool discordImportHasCommunityImage: root.communitiesModuleInst.discordImportHasCommunityImage property bool discordImportHasCommunityImage: root.communitiesModuleInst.discordImportHasCommunityImage
property var discordImportTasks: root.communitiesModuleInst.discordImportTasks property var discordImportTasks: root.communitiesModuleInst.discordImportTasks
property bool downloadingCommunityHistoryArchives: root.communitiesModuleInst.downloadingCommunityHistoryArchives
property string locale: localAppSettings.language property string locale: localAppSettings.language
property var advancedModule: profileSectionModule.advancedModule property var advancedModule: profileSectionModule.advancedModule

View File

@ -652,6 +652,15 @@ Item {
} }
} }
ModuleWarning {
id: downloadingArchivesBanner
Layout.fillWidth: true
active: communitiesPortalLayoutContainer.communitiesStore.downloadingCommunityHistoryArchives
type: ModuleWarning.Danger
text: qsTr("Downloading message history archives, DO NOT CLOSE THE APP until this banner disappears.")
closeBtnVisible: false
}
Component { Component {
id: connectedBannerComponent id: connectedBannerComponent

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 4c29c97591f5a68cb6c8f63290db8d1f1b778398 Subproject commit 194f26f3b4503494702be4e8148a166f61730c4d