fix(@desktop/chat): filter paid stickers if the wallet is not enabled

Fixes: #5923
This commit is contained in:
Sale Djenic 2022-06-21 10:56:12 +02:00 committed by Iuri Matias
parent b83f45c68b
commit 8f4e9bb3da
3 changed files with 185 additions and 137 deletions

View File

@ -52,9 +52,16 @@ QtObject:
self.stickers.insert(sticker, 0)
self.endInsertRows()
proc findIndexByPackId(self: StickerList, packId: string): int =
for i in 0 ..< self.stickers.len:
if(self.stickers[i].getPackId() == packId):
return i
return -1
proc removeStickersFromList*(self: StickerList, packId: string) =
if not self.stickers.anyIt(it.getPackId == packId):
let idx = self.findIndexByPackId(packId)
if idx == -1:
return
self.beginRemoveRows(newQModelIndex(), 0, 0)
self.stickers.keepItIf(it.getPackId != packId)
self.beginRemoveRows(newQModelIndex(), idx, idx)
self.stickers.delete(idx)
self.endRemoveRows()

View File

@ -105,21 +105,19 @@ QtObject:
proc removeStickerPackFromList*(self: StickerPackList, packId: string) =
let idx = self.findIndexById(packId)
self.beginRemoveRows(newQModelIndex(), idx, idx)
self.packs.keepItIf(it.pack.id != packId)
self.packs.delete(idx)
self.endRemoveRows()
proc updateStickerPackInList*(self: StickerPackList, packId: string, installed: bool, pending: bool) =
if not self.hasKey(packId):
let idx = self.findIndexById(packId)
if idx == -1:
return
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.packs.len, 0, nil)
let index = self.createIndex(idx, 0, nil)
self.packs.apply(proc(it: var StickerPackView) =
if it.pack.id == packId:
it.installed = installed
it.pending = pending)
self.dataChanged(topLeft, bottomRight, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
proc getStickers*(self: StickerPackList): QVariant {.slot.} =
let packInfo = self.packs[self.packIdToRetrieve]

View File

@ -2,6 +2,7 @@ import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import QtQml.Models 2.13
import utils 1.0
import shared 1.0
@ -39,9 +40,50 @@ Item {
anchors.topMargin: Style.current.padding
cellWidth: parent.width - (Style.current.padding * 2)
cellHeight: height - 72
model: stickerPacks
focus: true
clip: true
model: DelegateModel {
id: delegateModel
function update() {
if (items.count > 0) {
items.setGroups(0, items.count, "items");
}
var visible = [];
for (var i = 0; i < items.count; ++i) {
var item = items.get(i);
if (delegateModel.walletEnabled ||
!delegateModel.walletEnabled && item.model.price == 0) {
visible.push(item);
}
}
for (i = 0; i < visible.length; ++i) {
item = visible[i];
item.inVisible = true;
if (item.visibleIndex !== i) {
visibleItems.move(item.visibleIndex, i, 1);
}
}
}
readonly property bool walletEnabled: localAccountSensitiveSettings.isWalletEnabled
onWalletEnabledChanged: {
update()
}
model: stickerPacks
items.onChanged: update()
filterOnGroup: "visible"
groups: DelegateModelGroup {
id: visibleItems
name: "visible"
includeByDefault: false
}
delegate: Item {
width: availableStickerPacks.cellWidth
height: availableStickerPacks.cellHeight
@ -184,6 +226,7 @@ Item {
}
}
}
}
Item {
id: footer