fix(@desktop/general): UI for fetching backed up data improved (empty items removed)
This commit is contained in:
parent
be1b30f2df
commit
365973eef0
|
@ -74,7 +74,9 @@ QtObject:
|
|||
return -1
|
||||
|
||||
proc init*(self: Model, entities: seq[tuple[entity: string, icon: string]]) =
|
||||
self.allTotalsSet = false
|
||||
self.beginResetModel()
|
||||
self.items = @[]
|
||||
for e in entities:
|
||||
self.items.add(newItem(e.entity, e.icon))
|
||||
self.endResetModel()
|
||||
|
@ -88,15 +90,18 @@ QtObject:
|
|||
let index = self.createIndex(ind, 0, nil)
|
||||
self.dataChanged(index, index, @[ModelRole.LoadedMessages.int])
|
||||
|
||||
proc checkLastKnownClockAndResetTotalsIfNeeded*(self: Model, backedUpMsgClock: uint64) =
|
||||
proc checkLastKnownClockAndReinitModel*(self: Model, backedUpMsgClock: uint64, entities: seq[tuple[entity: string, icon: string]]) =
|
||||
if self.lastKnownBackedUpMsgClock >= backedUpMsgClock:
|
||||
return
|
||||
self.init(entities)
|
||||
self.lastKnownBackedUpMsgClock = backedUpMsgClock
|
||||
self.allTotalsSet = false
|
||||
for i in 0..< self.items.len:
|
||||
self.items[i].resetItem()
|
||||
let index = self.createIndex(i, 0, nil)
|
||||
self.dataChanged(index, index, @[ModelRole.TotalMessages.int, ModelRole.LoadedMessages.int])
|
||||
|
||||
proc reevaluateAllTotals(self: Model) =
|
||||
self.allTotalsSet = true
|
||||
for it in self.items:
|
||||
if it.loadedMessages != it.totalMessages:
|
||||
self.allTotalsSet = false
|
||||
return
|
||||
|
||||
proc updateTotalMessages*(self: Model, entity: string, totalMessages: int) =
|
||||
if self.allTotalsSet:
|
||||
|
@ -105,16 +110,24 @@ QtObject:
|
|||
if(ind == -1):
|
||||
return
|
||||
self.items[ind].totalMessages = totalMessages
|
||||
|
||||
self.allTotalsSet = true
|
||||
for it in self.items:
|
||||
if it.totalMessages == 0:
|
||||
self.allTotalsSet = false
|
||||
break
|
||||
|
||||
self.reevaluateAllTotals()
|
||||
let index = self.createIndex(ind, 0, nil)
|
||||
self.dataChanged(index, index, @[ModelRole.TotalMessages.int, ModelRole.LoadedMessages.int])
|
||||
|
||||
proc removeSection*(self: Model, entity: string) =
|
||||
if self.allTotalsSet:
|
||||
return
|
||||
let ind = self.findIndexForEntity(entity)
|
||||
if(ind == -1):
|
||||
return
|
||||
let parentModelIndex = newQModelIndex()
|
||||
defer: parentModelIndex.delete
|
||||
self.beginRemoveRows(parentModelIndex, ind, ind)
|
||||
self.items.delete(ind)
|
||||
self.endRemoveRows()
|
||||
self.countChanged()
|
||||
self.reevaluateAllTotals()
|
||||
|
||||
proc allMessagesLoaded*(self: Model): bool =
|
||||
if not self.allTotalsSet:
|
||||
return false
|
||||
|
|
|
@ -38,6 +38,15 @@ const FetchingFromWakuKeypairsIcon = "wallet"
|
|||
const FetchingFromWakuWatchOnlyAccounts = "watchOnlyAccounts"
|
||||
const FetchingFromWakuWatchOnlyAccountsIcon = "wallet"
|
||||
|
||||
const listOfEntitiesWeExpectToBeSynced = @[
|
||||
(FetchingFromWakuProfile, FetchingFromWakuProfileIcon),
|
||||
(FetchingFromWakuContacts, FetchingFromWakuContactsIcon),
|
||||
(FetchingFromWakuCommunities, FetchingFromWakuCommunitiesIcon),
|
||||
(FetchingFromWakuSettings, FetchingFromWakuSettingsIcon),
|
||||
(FetchingFromWakuKeypairs, FetchingFromWakuKeypairsIcon),
|
||||
(FetchingFromWakuWatchOnlyAccounts, FetchingFromWakuWatchOnlyAccountsIcon)
|
||||
]
|
||||
|
||||
type
|
||||
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
|
||||
delegate: T
|
||||
|
@ -325,9 +334,10 @@ method checkFetchingStatusAndProceedWithAppLoading*[T](self: Module[T]) =
|
|||
return
|
||||
self.view.setCurrentStartupState(newProfileFetchingAnnouncementState(currStateObj.flowType(), nil))
|
||||
|
||||
method onFetchingFromWakuMessageReceived*[T](self: Module[T], backedUpMsgClock: uint64, section: string,
|
||||
method onFetchingFromWakuMessageReceived*[T](self: Module[T], backedUpMsgClock: uint64, section: string,
|
||||
totalMessages: int, receivedMessageAtPosition: int) =
|
||||
self.view.fetchingDataModel().checkLastKnownClockAndResetTotalsIfNeeded(backedUpMsgClock)
|
||||
echo "onFetchingFromWakuMessageReceived: ", backedUpMsgClock, " section: ", section, " tm: ", totalMessages, " recAtPos: ", receivedMessageAtPosition
|
||||
self.view.fetchingDataModel().checkLastKnownClockAndReinitModel(backedUpMsgClock, listOfEntitiesWeExpectToBeSynced)
|
||||
if self.view.fetchingDataModel().allMessagesLoaded():
|
||||
return
|
||||
let currStateObj = self.view.currentStartupStateObj()
|
||||
|
@ -340,6 +350,8 @@ method onFetchingFromWakuMessageReceived*[T](self: Module[T], backedUpMsgClock:
|
|||
return
|
||||
if totalMessages > 0:
|
||||
self.view.fetchingDataModel().updateTotalMessages(section, totalMessages)
|
||||
else:
|
||||
self.view.fetchingDataModel().removeSection(section)
|
||||
if receivedMessageAtPosition > 0:
|
||||
self.view.fetchingDataModel().receivedMessageAtPosition(section, receivedMessageAtPosition)
|
||||
if self.view.fetchingDataModel().allMessagesLoaded():
|
||||
|
@ -347,14 +359,6 @@ method onFetchingFromWakuMessageReceived*[T](self: Module[T], backedUpMsgClock:
|
|||
|
||||
proc prepareAndInitFetchingData[T](self: Module[T]) =
|
||||
# fetching data from waku starts when messenger starts
|
||||
const listOfEntitiesWeExpectToBeSynced = @[
|
||||
(FetchingFromWakuProfile, FetchingFromWakuProfileIcon),
|
||||
(FetchingFromWakuContacts, FetchingFromWakuContactsIcon),
|
||||
(FetchingFromWakuCommunities, FetchingFromWakuCommunitiesIcon),
|
||||
(FetchingFromWakuSettings, FetchingFromWakuSettingsIcon),
|
||||
(FetchingFromWakuKeypairs, FetchingFromWakuKeypairsIcon),
|
||||
(FetchingFromWakuWatchOnlyAccounts, FetchingFromWakuWatchOnlyAccountsIcon)
|
||||
]
|
||||
self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced)
|
||||
|
||||
proc delayStartingApp[T](self: Module[T]) =
|
||||
|
|
Loading…
Reference in New Issue