fix(StatusStickersPopup): fix reloading views with online status changes

- hide the market and other stuff that can't be used while offline
- recent stickers and already installed packs can still be used; they
will be sent when we return online
- when we return online, reload the views instead of closing the popup
- fix an evil NIM typo that prevented reloading the already installed
sticker packs
- remove the NIM parts that haven't been ported to the async nature; just
`loadStickers()` on the QMl side does the trick
This commit is contained in:
Lukáš Tinkl 2023-04-17 23:53:55 +02:00 committed by Lukáš Tinkl
parent 7a5dbbd952
commit a2a6287537
4 changed files with 18 additions and 42 deletions

View File

@ -26,10 +26,6 @@ type
tokenService: token_service.Service
disconnected: bool
# Forward declaration
proc obtainMarketStickerPacks*(self: Controller)
proc getInstalledStickerPacks*(self: Controller): Table[string, StickerPackDto]
proc newController*(
delegate: io_interface.AccessInterface,
events: EventEmitter,
@ -54,20 +50,6 @@ proc delete*(self: Controller) =
proc init*(self: Controller) =
self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args):
self.disconnected = true
self.delegate.clearStickerPacks()
let installedStickerPacks = self.getInstalledStickerPacks()
self.delegate.populateInstalledStickerPacks(installedStickerPacks)
self.events.on(SIGNAL_NETWORK_CONNECTED) do(e: Args):
if self.disconnected:
let installedStickers = self.stickerService.getInstalledStickerPacks()
self.delegate.populateInstalledStickerPacks(installedStickers)
self.delegate.clearStickerPacks()
self.obtainMarketStickerPacks()
self.disconnected = false
self.events.on(SIGNAL_LOAD_RECENT_STICKERS_DONE) do(e: Args):
let args = StickersArgs(e)
for sticker in args.stickers:

View File

@ -105,7 +105,7 @@ QtObject:
self.installedStickerPacksLoaded = flag
proc getInstalledStickerPacksLoaded*(self: View): bool =
return self.installedStickerPacksloaded
return self.installedStickerPacksLoaded
proc uninstall*(self: View, packId: string) {.slot.} =
self.delegate.uninstallStickerPack(packId)

View File

@ -23,6 +23,7 @@ Item {
property var store
property var stickerPacks: StickerPackData {}
property string packId
property bool marketVisible
signal backClicked
signal uninstallClicked(string packId)
@ -43,6 +44,7 @@ Item {
anchors.topMargin: Style.current.padding
cellWidth: parent.width - (Style.current.padding * 2)
cellHeight: height - 72
visible: root.marketVisible
ScrollBar.vertical: StatusScrollBar {}

View File

@ -42,6 +42,12 @@ Popup {
function getInstalledStickerPacks() {
store.stickersModuleInst.getInstalledStickerPacks()
}
readonly property bool online: root.store.networkConnectionStore.isOnline
onOnlineChanged: {
if (online)
d.loadStickers()
}
}
enabled: !!d.recentStickers && !!d.stickerPackList
@ -77,13 +83,6 @@ Popup {
stickersContainer.visible = true
}
Connections {
target: mainModule
function onOnlineStatusChanged() {
root.close()
}
}
contentItem: ColumnLayout {
anchors.fill: parent
spacing: 0
@ -96,6 +95,7 @@ Popup {
store: root.store
stickerPacks: d.stickerPackList
packId: stickerPackListView.selectedPackId
marketVisible: d.stickerPacksLoaded && d.online
onInstallClicked: {
//starts async task
stickersModule.install(packId)
@ -135,7 +135,7 @@ Popup {
id: failedToLoadStickersInfo
anchors.centerIn: parent
visible: d.stickerPacksLoadFailed && d.installedPacksCount < 1
visible: d.stickerPacksLoadFailed || !d.online
StatusBaseText {
text: qsTr("Failed to load stickers")
@ -146,6 +146,7 @@ Popup {
objectName: "stickersPopupRetryButton"
Layout.alignment: Qt.AlignHCenter
text: qsTr("Try again")
enabled: d.online
onClicked: d.loadStickers()
}
@ -164,11 +165,10 @@ Popup {
Item {
id: noStickerPacks
anchors.fill: parent
visible: d.installedPacksCount == 0 || stickersModule.recent.rowCount() === 0
visible: d.installedPacksCount == 0 && stickersModule.recent.rowCount() === 0
Image {
id: imgNoStickers
visible: lblNoStickersYet.visible || lblNoRecentStickers.visible
width: 56
height: 56
anchors.horizontalCenter: parent.horizontalCenter
@ -186,20 +186,10 @@ Popup {
StyledText {
id: lblNoStickersYet
visible: d.installedPacksCount === 0
anchors.fill: parent
font.pixelSize: 15
text: qsTr("You don't have any stickers yet")
lineHeight: 22
horizontalAlignment: Text.AlignHCenter
}
StyledText {
id: lblNoRecentStickers
visible: !stickerPackListView.selectedPackId && stickersModule.recent.rowCount() === 0 && !lblNoStickersYet.visible
anchors.fill: parent
font.pixelSize: 15
text: qsTr("Recently used stickers will appear here")
text: d.installedPacksCount === 0 || !d.online ? qsTr("You don't have any stickers yet")
: qsTr("Recently used stickers will appear here")
lineHeight: 22
horizontalAlignment: Text.AlignHCenter
}
@ -207,8 +197,9 @@ Popup {
StatusButton {
objectName: "stickersPopupGetStickersButton"
visible: lblNoStickersYet.visible
visible: d.installedPacksCount === 0
text: qsTr("Get Stickers")
enabled: d.online
anchors.top: noStickersContainer.bottom
anchors.topMargin: Style.current.padding
anchors.horizontalCenter: parent.horizontalCenter
@ -219,6 +210,7 @@ Popup {
}
}
}
StatusStickerList {
id: stickerGrid
objectName: "statusStickerPopupStickerGrid"