2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Support generic dice media display.

This commit is contained in:
John Preston
2020-04-19 16:17:53 +04:00
parent fb8a9a930c
commit e118972d5c
6 changed files with 75 additions and 22 deletions

View File

@@ -35,11 +35,11 @@ DocumentData *DicePack::lookup(int value) {
if (!_requestId) {
load();
}
if (!value) {
ensureZeroGenerated();
return _zero;
}
const auto i = _map.find(value);
//if (!value) {
// ensureZeroGenerated();
// return _zero;
//}
return (i != end(_map)) ? i->second.get() : nullptr;
}
@@ -59,14 +59,33 @@ void DicePack::load() {
}
void DicePack::applySet(const MTPDmessages_stickerSet &data) {
auto index = 0;
_map.clear();
auto documents = base::flat_map<DocumentId, not_null<DocumentData*>>();
for (const auto &sticker : data.vdocuments().v) {
const auto document = _session->data().processDocument(
sticker);
if (document->sticker()) {
_map.emplace(++index, document);
documents.emplace(document->id, document);
}
}
for (const auto pack : data.vpacks().v) {
pack.match([&](const MTPDstickerPack &data) {
const auto emoji = qs(data.vemoticon());
if (emoji.isEmpty()) {
return;
}
const auto ch = int(emoji[0].unicode());
const auto index = (ch == '#') ? 0 : (ch + 1 - '1');
if (index < 0 || index > 6) {
return;
}
for (const auto id : data.vdocuments().v) {
if (const auto document = documents.take(id.v)) {
_map.emplace(index, *document);
}
}
});
}
}
void DicePack::ensureZeroGenerated() {

View File

@@ -1,4 +1,5 @@
/*
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.