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