void StickerSetInner::installDone(const MTPBool &result) { StickerSets &sets(cRefStickerSets()); sets.insert(_setId, StickerSet(_setId, _setAccess, _setTitle, _setShortName)).value().stickers = _pack; int32 index = cStickerSetsOrder().indexOf(_setId); if (index > 0) { cRefStickerSetsOrder().removeAt(index); cRefStickerSetsOrder().push_front(_setId); } else if (index < 0) { cRefStickerSetsOrder().push_front(_setId); } StickerSets::iterator custom = sets.find(CustomStickerSetId); if (custom != sets.cend()) { for (int32 i = 0, l = _pack.size(); i < l; ++i) { custom->stickers.removeOne(_pack.at(i)); } if (custom->stickers.isEmpty()) { sets.erase(custom); } } cSetStickersHash(QByteArray()); Local::writeStickers(); emit installed(_setId); App::wnd()->hideLayer(); }
void StickerSetInner::installDone(const MTPBool &result) { StickerSets &sets(cRefStickerSets()); sets.insert(_setId, StickerSet(_setId, _setAccess, _setTitle, _setShortName, _setCount, _setHash, _setFlags)).value().stickers = _pack; int32 insertAtIndex = 0; StickerSetsOrder &order(cRefStickerSetsOrder()); for (int32 s = order.size(); insertAtIndex < s; ++insertAtIndex) { StickerSets::const_iterator i = sets.constFind(order.at(insertAtIndex)); if (i == sets.cend() || !(i->flags & MTPDstickerSet_flag_official)) { break; } } int32 currentIndex = cStickerSetsOrder().indexOf(_setId); if (currentIndex != insertAtIndex) { if (currentIndex > 0) { order.removeAt(currentIndex); if (currentIndex < insertAtIndex) { --insertAtIndex; } } order.insert(insertAtIndex, _setId); } StickerSets::iterator custom = sets.find(CustomStickerSetId); if (custom != sets.cend()) { for (int32 i = 0, l = _pack.size(); i < l; ++i) { custom->stickers.removeOne(_pack.at(i)); } if (custom->stickers.isEmpty()) { sets.erase(custom); } } cSetStickersHash(QByteArray()); Local::writeStickers(); emit installed(_setId); App::wnd()->hideLayer(); }
void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result) { _stickerSetRequests.remove(setId); if (result.type() != mtpc_messages_stickerSet) return; const MTPDmessages_stickerSet &d(result.c_messages_stickerSet()); if (d.vset.type() != mtpc_stickerSet) return; const MTPDstickerSet &s(d.vset.c_stickerSet()); StickerSets &sets(cRefStickerSets()); StickerSets::iterator it = sets.find(setId); if (it == sets.cend()) return; it->access = s.vaccess_hash.v; it->hash = s.vhash.v; it->shortName = qs(s.vshort_name); it->title = stickerSetTitle(s); it->flags = s.vflags.v; const QVector<MTPDocument> &d_docs(d.vdocuments.c_vector().v); StickerSets::iterator custom = sets.find(CustomStickerSetId); StickerPack pack; pack.reserve(d_docs.size()); for (int32 i = 0, l = d_docs.size(); i != l; ++i) { DocumentData *doc = App::feedDocument(d_docs.at(i)); if (!doc || !doc->sticker()) continue; pack.push_back(doc); if (custom != sets.cend()) { int32 index = custom->stickers.indexOf(doc); if (index >= 0) { custom->stickers.removeAt(index); } } } if (custom != sets.cend() && custom->stickers.isEmpty()) { sets.erase(custom); custom = sets.end(); } bool writeRecent = false; RecentStickerPack &recent(cGetRecentStickers()); for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.indexOf(i->first) >= 0 && pack.indexOf(i->first) < 0) { i = recent.erase(i); writeRecent = true; } else { ++i; } } if (pack.isEmpty()) { int32 removeIndex = cStickerSetsOrder().indexOf(setId); if (removeIndex >= 0) cRefStickerSetsOrder().removeAt(removeIndex); sets.erase(it); } else { it->stickers = pack; } if (writeRecent) { Local::writeUserSettings(); } Local::writeStickers(); if (App::main()) emit App::main()->stickersUpdated(); }
void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result) { _stickerSetRequests.remove(setId); if (result.type() != mtpc_messages_stickerSet) return; const MTPDmessages_stickerSet &d(result.c_messages_stickerSet()); if (d.vset.type() != mtpc_stickerSet) return; const MTPDstickerSet &s(d.vset.c_stickerSet()); StickerSets &sets(cRefStickerSets()); StickerSets::iterator it = sets.find(setId); if (it == sets.cend()) return; it->access = s.vaccess_hash.v; it->hash = s.vhash.v; it->shortName = qs(s.vshort_name); QString title = qs(s.vtitle); if ((it->flags & MTPDstickerSet_flag_official) && !title.compare(qstr("Great Minds"), Qt::CaseInsensitive)) { title = lang(lng_stickers_default_set); } it->title = title; it->flags = s.vflags.v; const QVector<MTPDocument> &d_docs(d.vdocuments.c_vector().v); StickerSets::iterator custom = sets.find(CustomStickerSetId); QSet<DocumentData*> found; int32 wasCount = -1; for (int32 i = 0, l = d_docs.size(); i != l; ++i) { DocumentData *doc = App::feedDocument(d_docs.at(i)); if (!doc || !doc->sticker) continue; if (wasCount < 0) wasCount = it->stickers.size(); if (it->stickers.indexOf(doc) < 0) { it->stickers.push_back(doc); } else { found.insert(doc); } if (custom != sets.cend()) { int32 index = custom->stickers.indexOf(doc); if (index >= 0) { custom->stickers.removeAt(index); } } } if (custom != sets.cend() && custom->stickers.isEmpty()) { sets.erase(custom); custom = sets.end(); } bool writeRecent = false; RecentStickerPack &recent(cGetRecentStickers()); if (wasCount < 0) { // no stickers received for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.indexOf(i->first) >= 0) { i = recent.erase(i); writeRecent = true; } else { ++i; } } cRefStickerSetsOrder().removeOne(setId); sets.erase(it); } else { for (int32 j = 0, l = wasCount; j < l;) { if (found.contains(it->stickers.at(j))) { ++j; } else { for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.at(j) == i->first) { i = recent.erase(i); writeRecent = true; } else { ++i; } } it->stickers.removeAt(j); --l; } } if (it->stickers.isEmpty()) { cRefStickerSetsOrder().removeOne(setId); sets.erase(it); } } if (writeRecent) { Local::writeUserSettings(); } Local::writeStickers(); if (App::main()) emit App::main()->stickersUpdated(); }