2016-09-09 15:52:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-09-09 15:52:46 +00:00
|
|
|
*/
|
2016-09-10 20:54:59 +00:00
|
|
|
#include "stickers.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "boxes/stickers_box.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
#include "apiwrap.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
#include "mainwidget.h"
|
2016-12-23 13:21:01 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui/toast/toast.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-09-09 15:52:46 +00:00
|
|
|
|
|
|
|
namespace Stickers {
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &v = d.vsets.v;
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &order = Auth().data().stickerSetsOrderRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
Order archived;
|
2016-09-09 15:52:46 +00:00
|
|
|
archived.reserve(v.size());
|
|
|
|
QMap<uint64, uint64> setsToRequest;
|
|
|
|
for_const (auto &stickerSet, v) {
|
|
|
|
const MTPDstickerSet *setData = nullptr;
|
|
|
|
switch (stickerSet.type()) {
|
|
|
|
case mtpc_stickerSetCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_stickerSetMultiCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetMultiCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (setData) {
|
2017-08-02 20:57:49 +00:00
|
|
|
auto set = FeedSet(*setData);
|
2016-09-09 15:52:46 +00:00
|
|
|
if (set->stickers.isEmpty()) {
|
|
|
|
setsToRequest.insert(set->id, set->access);
|
|
|
|
}
|
|
|
|
auto index = order.indexOf(set->id);
|
|
|
|
if (index >= 0) {
|
|
|
|
order.removeAt(index);
|
|
|
|
}
|
|
|
|
archived.push_back(set->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!setsToRequest.isEmpty()) {
|
|
|
|
for (auto i = setsToRequest.cbegin(), e = setsToRequest.cend(); i != e; ++i) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().scheduleStickerSetRequest(i.key(), i.value());
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestStickerSets();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
Local::writeArchivedStickers();
|
2016-12-23 13:21:01 +00:00
|
|
|
|
|
|
|
Ui::Toast::Config toast;
|
|
|
|
toast.text = lang(lng_stickers_packs_archived);
|
|
|
|
toast.maxWidth = st::stickersToastMaxWidth;
|
|
|
|
toast.padding = st::stickersToastPadding;
|
2017-02-03 20:07:26 +00:00
|
|
|
Ui::Toast::Show(toast);
|
2017-09-15 17:34:41 +00:00
|
|
|
// Ui::show(Box<StickersBox>(archived), LayerOption::KeepOther);
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
// For testing: Just apply random subset or your sticker sets as archived.
|
2017-08-02 20:57:49 +00:00
|
|
|
bool ApplyArchivedResultFake() {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto sets = QVector<MTPStickerSetCovered>();
|
2017-11-05 17:07:27 +00:00
|
|
|
for (auto &set : Auth().data().stickerSetsRef()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
if ((set.flags & MTPDstickerSet::Flag::f_installed) && !(set.flags & MTPDstickerSet_ClientFlag::f_special)) {
|
|
|
|
if (rand_value<uint32>() % 128 < 64) {
|
|
|
|
auto data = MTP_stickerSet(MTP_flags(set.flags | MTPDstickerSet::Flag::f_archived), MTP_long(set.id), MTP_long(set.access), MTP_string(set.title), MTP_string(set.shortName), MTP_int(set.count), MTP_int(set.hash));
|
|
|
|
sets.push_back(MTP_stickerSetCovered(data, MTP_documentEmpty(MTP_long(0))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sets.size() > 3) sets = sets.mid(0, 3);
|
|
|
|
auto fakeResult = MTP_messages_stickerSetInstallResultArchive(MTP_vector<MTPStickerSetCovered>(sets));
|
2017-08-02 20:57:49 +00:00
|
|
|
ApplyArchivedResult(fakeResult.c_messages_stickerSetInstallResultArchive());
|
2016-11-22 09:48:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
void InstallLocally(uint64 setId) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2016-09-09 15:52:46 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto flags = it->flags;
|
|
|
|
it->flags &= ~(MTPDstickerSet::Flag::f_archived | MTPDstickerSet_ClientFlag::f_unread);
|
|
|
|
it->flags |= MTPDstickerSet::Flag::f_installed;
|
|
|
|
auto changedFlags = flags ^ it->flags;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &order = Auth().data().stickerSetsOrderRef();
|
2016-09-09 15:52:46 +00:00
|
|
|
int insertAtIndex = 0, currentIndex = order.indexOf(setId);
|
|
|
|
if (currentIndex != insertAtIndex) {
|
|
|
|
if (currentIndex > 0) {
|
|
|
|
order.removeAt(currentIndex);
|
|
|
|
}
|
|
|
|
order.insert(insertAtIndex, setId);
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
auto custom = sets.find(CustomSetId);
|
2016-09-09 15:52:46 +00:00
|
|
|
if (custom != sets.cend()) {
|
|
|
|
for_const (auto sticker, it->stickers) {
|
|
|
|
int removeIndex = custom->stickers.indexOf(sticker);
|
|
|
|
if (removeIndex >= 0) custom->stickers.removeAt(removeIndex);
|
|
|
|
}
|
|
|
|
if (custom->stickers.isEmpty()) {
|
|
|
|
sets.erase(custom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
if (changedFlags & MTPDstickerSet_ClientFlag::f_unread) Local::writeFeaturedStickers();
|
|
|
|
if (changedFlags & MTPDstickerSet::Flag::f_archived) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto index = Auth().data().archivedStickerSetsOrderRef().indexOf(setId);
|
2016-09-09 15:52:46 +00:00
|
|
|
if (index >= 0) {
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().archivedStickerSetsOrderRef().removeAt(index);
|
2016-09-09 15:52:46 +00:00
|
|
|
Local::writeArchivedStickers();
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
void UndoInstallLocally(uint64 setId) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2016-09-09 15:52:46 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->flags &= ~MTPDstickerSet::Flag::f_installed;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &order = Auth().data().stickerSetsOrderRef();
|
2016-09-09 15:52:46 +00:00
|
|
|
int currentIndex = order.indexOf(setId);
|
|
|
|
if (currentIndex >= 0) {
|
|
|
|
order.removeAt(currentIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Local::writeInstalledStickers();
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2016-09-09 15:52:46 +00:00
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(lang(lng_stickers_not_found)),
|
|
|
|
LayerOption::KeepOther);
|
2016-09-09 15:52:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool IsFaved(not_null<DocumentData*> document) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto it = Auth().data().stickerSets().constFind(FavedSetId);
|
|
|
|
return (it != Auth().data().stickerSets().cend()) && it->stickers.contains(document);
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 11:57:23 +00:00
|
|
|
void CheckFavedLimit(Set &set) {
|
|
|
|
if (set.stickers.size() <= Global::StickersFavedLimit()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto removing = set.stickers.back();
|
|
|
|
set.stickers.pop_back();
|
|
|
|
for (auto i = set.emoji.begin(); i != set.emoji.end();) {
|
|
|
|
auto index = i->indexOf(removing);
|
|
|
|
if (index >= 0) {
|
|
|
|
i->removeAt(index);
|
|
|
|
if (i->empty()) {
|
|
|
|
i = set.emoji.erase(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:34:30 +00:00
|
|
|
void PushFavedToFront(
|
|
|
|
Set &set,
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const std::vector<not_null<EmojiPtr>> &emojiList) {
|
2017-08-15 14:34:30 +00:00
|
|
|
set.stickers.push_front(document);
|
|
|
|
for (auto emoji : emojiList) {
|
|
|
|
set.emoji[emoji].push_front(document);
|
|
|
|
}
|
|
|
|
CheckFavedLimit(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveFavedToFront(Set &set, int index) {
|
|
|
|
Expects(index > 0 && index < set.stickers.size());
|
|
|
|
auto document = set.stickers[index];
|
|
|
|
while (index-- != 0) {
|
|
|
|
set.stickers[index + 1] = set.stickers[index];
|
|
|
|
}
|
|
|
|
set.stickers[0] = document;
|
|
|
|
for (auto &list : set.emoji) {
|
|
|
|
auto index = list.indexOf(document);
|
|
|
|
if (index > 0) {
|
|
|
|
while (index-- != 0) {
|
|
|
|
list[index + 1] = list[index];
|
|
|
|
}
|
|
|
|
list[0] = document;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void RequestSetToPushFaved(not_null<DocumentData*> document);
|
2017-08-15 14:34:30 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not_null<EmojiPtr>>> emojiList = base::none) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
auto it = sets.find(FavedSetId);
|
2017-08-03 11:15:57 +00:00
|
|
|
if (it == sets.end()) {
|
2017-09-28 20:11:10 +00:00
|
|
|
it = sets.insert(FavedSetId, Set(FavedSetId, 0, Lang::Hard::FavedSetTitle(), QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0));
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
|
|
|
auto index = it->stickers.indexOf(document);
|
|
|
|
if (index == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (index > 0) {
|
2017-08-15 14:34:30 +00:00
|
|
|
MoveFavedToFront(*it, index);
|
2017-08-03 11:15:57 +00:00
|
|
|
} else if (emojiList) {
|
2017-08-15 14:34:30 +00:00
|
|
|
PushFavedToFront(*it, document, *emojiList);
|
|
|
|
} else if (auto list = GetEmojiListFromSet(document)) {
|
|
|
|
PushFavedToFront(*it, document, *list);
|
2017-08-03 11:15:57 +00:00
|
|
|
} else {
|
2017-08-15 14:34:30 +00:00
|
|
|
RequestSetToPushFaved(document);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Local::writeFavedStickers();
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-09-16 16:53:41 +00:00
|
|
|
Auth().api().stickerSetInstalled(FavedSetId);
|
2017-08-15 14:34:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void RequestSetToPushFaved(not_null<DocumentData*> document) {
|
|
|
|
auto addAnyway = [document](std::vector<not_null<EmojiPtr>> list) {
|
2017-08-03 11:15:57 +00:00
|
|
|
if (list.empty()) {
|
2017-08-15 14:34:30 +00:00
|
|
|
if (auto sticker = document->sticker()) {
|
|
|
|
if (auto emoji = Ui::Emoji::Find(sticker->alt)) {
|
|
|
|
list.push_back(emoji);
|
2017-08-05 12:38:59 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SetIsFaved(document, std::move(list));
|
|
|
|
};
|
|
|
|
MTP::send(MTPmessages_GetStickerSet(document->sticker()->set), rpcDone([document, addAnyway](const MTPmessages_StickerSet &result) {
|
|
|
|
Expects(result.type() == mtpc_messages_stickerSet);
|
2017-08-17 08:31:24 +00:00
|
|
|
auto list = std::vector<not_null<EmojiPtr>>();
|
2017-08-15 14:34:30 +00:00
|
|
|
auto &d = result.c_messages_stickerSet();
|
|
|
|
list.reserve(d.vpacks.v.size());
|
|
|
|
for_const (auto &mtpPack, d.vpacks.v) {
|
|
|
|
auto &pack = mtpPack.c_stickerPack();
|
|
|
|
for_const (auto &documentId, pack.vdocuments.v) {
|
|
|
|
if (documentId.v == document->id) {
|
|
|
|
if (auto emoji = Ui::Emoji::Find(qs(mtpPack.c_stickerPack().vemoticon))) {
|
|
|
|
list.push_back(emoji);
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
break;
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
}
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
addAnyway(std::move(list));
|
|
|
|
}), rpcFail([addAnyway](const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) {
|
|
|
|
return false;
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
// Perhaps this is a deleted sticker pack. Add anyway.
|
|
|
|
addAnyway({});
|
|
|
|
return true;
|
|
|
|
}));
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void SetIsNotFaved(not_null<DocumentData*> document) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-03 11:15:57 +00:00
|
|
|
auto it = sets.find(FavedSetId);
|
|
|
|
if (it == sets.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto index = it->stickers.indexOf(document);
|
|
|
|
if (index < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
it->stickers.removeAt(index);
|
|
|
|
for (auto i = it->emoji.begin(); i != it->emoji.end();) {
|
|
|
|
auto index = i->indexOf(document);
|
2017-08-02 20:57:49 +00:00
|
|
|
if (index >= 0) {
|
2017-08-03 11:15:57 +00:00
|
|
|
i->removeAt(index);
|
|
|
|
if (i->empty()) {
|
|
|
|
i = it->emoji.erase(i);
|
|
|
|
continue;
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 11:15:57 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (it->stickers.empty()) {
|
|
|
|
sets.erase(it);
|
|
|
|
}
|
|
|
|
Local::writeFavedStickers();
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void SetFaved(not_null<DocumentData*> document, bool faved) {
|
2017-08-03 11:15:57 +00:00
|
|
|
if (faved) {
|
|
|
|
SetIsFaved(document);
|
|
|
|
} else {
|
|
|
|
SetIsNotFaved(document);
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetsReceived(const QVector<MTPStickerSet> &data, int32 hash) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &setsOrder = Auth().data().stickerSetsOrderRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
setsOrder.clear();
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
QMap<uint64, uint64> setsToRequest;
|
|
|
|
for (auto &set : sets) {
|
|
|
|
if (!(set.flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
set.flags &= ~MTPDstickerSet::Flag::f_installed; // mark for removing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for_const (auto &setData, data) {
|
|
|
|
if (setData.type() == mtpc_stickerSet) {
|
|
|
|
auto set = FeedSet(setData.c_stickerSet());
|
|
|
|
if (!(set->flags & MTPDstickerSet::Flag::f_archived) || (set->flags & MTPDstickerSet::Flag::f_official)) {
|
|
|
|
setsOrder.push_back(set->id);
|
|
|
|
if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
setsToRequest.insert(set->id, set->access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto writeRecent = false;
|
|
|
|
auto &recent = cGetRecentStickers();
|
|
|
|
for (auto it = sets.begin(), e = sets.end(); it != e;) {
|
|
|
|
bool installed = (it->flags & MTPDstickerSet::Flag::f_installed);
|
|
|
|
bool featured = (it->flags & MTPDstickerSet_ClientFlag::f_featured);
|
|
|
|
bool special = (it->flags & MTPDstickerSet_ClientFlag::f_special);
|
|
|
|
bool archived = (it->flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (!installed) { // remove not mine sets from recent stickers
|
|
|
|
for (auto i = recent.begin(); i != recent.cend();) {
|
|
|
|
if (it->stickers.indexOf(i->first) >= 0) {
|
|
|
|
i = recent.erase(i);
|
|
|
|
writeRecent = true;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (installed || featured || special || archived) {
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
it = sets.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!setsToRequest.isEmpty()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
auto &api = Auth().api();
|
2017-08-02 20:57:49 +00:00
|
|
|
for (auto i = setsToRequest.cbegin(), e = setsToRequest.cend(); i != e; ++i) {
|
|
|
|
api.scheduleStickerSetRequest(i.key(), i.value());
|
|
|
|
}
|
|
|
|
api.requestStickerSets();
|
|
|
|
}
|
|
|
|
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
if (writeRecent) Local::writeUserSettings();
|
|
|
|
|
|
|
|
if (Local::countStickersHash() != hash) {
|
|
|
|
LOG(("API Error: received stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countStickersHash()));
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void SetPackAndEmoji(Set &set, Pack &&pack, const QVector<MTPStickerPack> &packs) {
|
2017-08-03 11:15:57 +00:00
|
|
|
set.stickers = std::move(pack);
|
|
|
|
set.emoji.clear();
|
|
|
|
for_const (auto &mtpPack, packs) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(mtpPack.type() == mtpc_stickerPack);
|
2017-08-03 11:15:57 +00:00
|
|
|
auto &pack = mtpPack.c_stickerPack();
|
|
|
|
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
|
|
|
|
emoji = emoji->original();
|
|
|
|
auto &stickers = pack.vdocuments.v;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto p = Pack();
|
2017-08-03 11:15:57 +00:00
|
|
|
p.reserve(stickers.size());
|
|
|
|
for (auto j = 0, c = stickers.size(); j != c; ++j) {
|
|
|
|
auto document = App::document(stickers[j].v);
|
|
|
|
if (!document || !document->sticker()) continue;
|
|
|
|
|
|
|
|
p.push_back(document);
|
|
|
|
}
|
|
|
|
set.emoji.insert(emoji, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTPDocument> &items, int32 hash, const QVector<MTPStickerPack> &packs) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
|
|
|
|
auto &d_docs = items;
|
|
|
|
if (d_docs.isEmpty()) {
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
sets.erase(it);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (it == sets.cend()) {
|
2017-08-31 16:28:58 +00:00
|
|
|
it = sets.insert(setId, Set(setId, 0, setTitle, QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0));
|
2017-08-02 20:57:49 +00:00
|
|
|
} else {
|
|
|
|
it->title = setTitle;
|
|
|
|
}
|
|
|
|
it->hash = hash;
|
|
|
|
|
|
|
|
auto custom = sets.find(CustomSetId);
|
2017-11-05 17:07:27 +00:00
|
|
|
auto pack = Pack();
|
2017-08-02 20:57:49 +00:00
|
|
|
pack.reserve(d_docs.size());
|
|
|
|
for_const (auto &mtpDocument, d_docs) {
|
|
|
|
auto document = App::feedDocument(mtpDocument);
|
|
|
|
if (!document || !document->sticker()) continue;
|
|
|
|
|
|
|
|
pack.push_back(document);
|
|
|
|
if (custom != sets.cend()) {
|
|
|
|
auto index = custom->stickers.indexOf(document);
|
|
|
|
if (index >= 0) {
|
|
|
|
custom->stickers.removeAt(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (custom != sets.cend() && custom->stickers.isEmpty()) {
|
|
|
|
sets.erase(custom);
|
|
|
|
custom = sets.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto writeRecent = false;
|
|
|
|
auto &recent = cGetRecentStickers();
|
|
|
|
for (auto 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()) {
|
|
|
|
sets.erase(it);
|
|
|
|
} else {
|
2017-08-03 11:15:57 +00:00
|
|
|
SetPackAndEmoji(*it, std::move(pack), packs);
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (writeRecent) {
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (setId) {
|
|
|
|
case CloudRecentSetId: {
|
|
|
|
if (Local::countRecentStickersHash() != hash) {
|
|
|
|
LOG(("API Error: received recent stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countRecentStickersHash()));
|
|
|
|
}
|
|
|
|
Local::writeRecentStickers();
|
|
|
|
} break;
|
|
|
|
case FavedSetId: {
|
|
|
|
if (Local::countFavedStickersHash() != hash) {
|
|
|
|
LOG(("API Error: received faved stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countFavedStickersHash()));
|
|
|
|
}
|
|
|
|
Local::writeFavedStickers();
|
|
|
|
} break;
|
|
|
|
default: Unexpected("setId in SpecialSetReceived()");
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVector<MTPlong> &unread, int32 hash) {
|
|
|
|
OrderedSet<uint64> unreadMap;
|
|
|
|
for_const (auto &unreadSetId, unread) {
|
|
|
|
unreadMap.insert(unreadSetId.v);
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &setsOrder = Auth().data().featuredStickerSetsOrderRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
setsOrder.clear();
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
QMap<uint64, uint64> setsToRequest;
|
|
|
|
for (auto &set : sets) {
|
|
|
|
set.flags &= ~MTPDstickerSet_ClientFlag::f_featured; // mark for removing
|
|
|
|
}
|
|
|
|
for (int i = 0, l = data.size(); i != l; ++i) {
|
|
|
|
auto &setData = data[i];
|
|
|
|
const MTPDstickerSet *set = nullptr;
|
|
|
|
switch (setData.type()) {
|
|
|
|
case mtpc_stickerSetCovered: {
|
|
|
|
auto &d = setData.c_stickerSetCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
set = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_stickerSetMultiCovered: {
|
|
|
|
auto &d = setData.c_stickerSetMultiCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
set = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
auto it = sets.find(set->vid.v);
|
2017-08-12 07:17:33 +00:00
|
|
|
auto title = GetSetTitle(*set);
|
2017-08-02 20:57:49 +00:00
|
|
|
if (it == sets.cend()) {
|
|
|
|
auto setClientFlags = MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_not_loaded;
|
|
|
|
if (unreadMap.contains(set->vid.v)) {
|
|
|
|
setClientFlags |= MTPDstickerSet_ClientFlag::f_unread;
|
|
|
|
}
|
|
|
|
it = sets.insert(set->vid.v, Set(set->vid.v, set->vaccess_hash.v, title, qs(set->vshort_name), set->vcount.v, set->vhash.v, set->vflags.v | setClientFlags));
|
|
|
|
} else {
|
|
|
|
it->access = set->vaccess_hash.v;
|
|
|
|
it->title = title;
|
|
|
|
it->shortName = qs(set->vshort_name);
|
|
|
|
auto clientFlags = it->flags & (MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_unread | MTPDstickerSet_ClientFlag::f_not_loaded | MTPDstickerSet_ClientFlag::f_special);
|
|
|
|
it->flags = set->vflags.v | clientFlags;
|
|
|
|
it->flags |= MTPDstickerSet_ClientFlag::f_featured;
|
|
|
|
if (unreadMap.contains(it->id)) {
|
|
|
|
it->flags |= MTPDstickerSet_ClientFlag::f_unread;
|
|
|
|
} else {
|
|
|
|
it->flags &= ~MTPDstickerSet_ClientFlag::f_unread;
|
|
|
|
}
|
|
|
|
if (it->count != set->vcount.v || it->hash != set->vhash.v || it->emoji.isEmpty()) {
|
|
|
|
it->count = set->vcount.v;
|
|
|
|
it->hash = set->vhash.v;
|
|
|
|
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded; // need to request this set
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setsOrder.push_back(set->vid.v);
|
|
|
|
if (it->stickers.isEmpty() || (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
setsToRequest.insert(set->vid.v, set->vaccess_hash.v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto unreadCount = 0;
|
|
|
|
for (auto it = sets.begin(), e = sets.end(); it != e;) {
|
|
|
|
bool installed = (it->flags & MTPDstickerSet::Flag::f_installed);
|
|
|
|
bool featured = (it->flags & MTPDstickerSet_ClientFlag::f_featured);
|
|
|
|
bool special = (it->flags & MTPDstickerSet_ClientFlag::f_special);
|
|
|
|
bool archived = (it->flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (installed || featured || special || archived) {
|
|
|
|
if (featured && (it->flags & MTPDstickerSet_ClientFlag::f_unread)) {
|
|
|
|
++unreadCount;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
it = sets.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().setFeaturedStickerSetsUnreadCount(unreadCount);
|
2017-08-02 20:57:49 +00:00
|
|
|
|
|
|
|
if (Local::countFeaturedStickersHash() != hash) {
|
|
|
|
LOG(("API Error: received featured stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countFeaturedStickersHash()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!setsToRequest.isEmpty()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
auto &api = Auth().api();
|
2017-08-02 20:57:49 +00:00
|
|
|
for (auto i = setsToRequest.cbegin(), e = setsToRequest.cend(); i != e; ++i) {
|
|
|
|
api.scheduleStickerSetRequest(i.key(), i.value());
|
|
|
|
}
|
|
|
|
api.requestStickerSets();
|
|
|
|
}
|
|
|
|
|
|
|
|
Local::writeFeaturedStickers();
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GifsReceived(const QVector<MTPDocument> &items, int32 hash) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &saved = Auth().data().savedGifsRef();
|
2017-08-02 20:57:49 +00:00
|
|
|
saved.clear();
|
|
|
|
|
|
|
|
saved.reserve(items.size());
|
|
|
|
for_const (auto &gif, items) {
|
|
|
|
auto document = App::feedDocument(gif);
|
|
|
|
if (!document || !document->isGifv()) {
|
|
|
|
LOG(("API Error: bad document returned in HistoryWidget::savedGifsGot!"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
saved.push_back(document);
|
|
|
|
}
|
|
|
|
if (Local::countSavedGifsHash() != hash) {
|
|
|
|
LOG(("API Error: received saved gifs hash %1 while counted hash is %2").arg(hash).arg(Local::countSavedGifsHash()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Local::writeSavedGifs();
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markSavedGifsUpdated();
|
2017-08-02 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Pack GetListByEmoji(not_null<EmojiPtr> emoji) {
|
2017-08-03 11:15:57 +00:00
|
|
|
auto original = emoji->original();
|
2017-11-05 17:07:27 +00:00
|
|
|
auto result = Pack();
|
2017-08-03 11:15:57 +00:00
|
|
|
auto setsToRequest = QMap<uint64, uint64>();
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-03 11:15:57 +00:00
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto faved = Pack();
|
2017-08-03 11:15:57 +00:00
|
|
|
auto favedIt = sets.find(Stickers::FavedSetId);
|
|
|
|
if (favedIt != sets.cend()) {
|
|
|
|
auto i = favedIt->emoji.constFind(original);
|
|
|
|
if (i != favedIt->emoji.cend()) {
|
|
|
|
faved = *i;
|
|
|
|
result = faved;
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &order = Auth().data().stickerSetsOrder();
|
2017-08-03 11:15:57 +00:00
|
|
|
for (auto i = 0, l = order.size(); i != l; ++i) {
|
|
|
|
auto it = sets.find(order[i]);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
if (it->emoji.isEmpty()) {
|
|
|
|
setsToRequest.insert(it->id, it->access);
|
|
|
|
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded;
|
|
|
|
} else if (!(it->flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
auto i = it->emoji.constFind(original);
|
|
|
|
if (i != it->emoji.cend()) {
|
|
|
|
result.reserve(result.size() + i->size());
|
|
|
|
for_const (auto sticker, *i) {
|
|
|
|
if (!faved.contains(sticker)) {
|
|
|
|
result.push_back(sticker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!setsToRequest.isEmpty()) {
|
|
|
|
for (auto i = setsToRequest.cbegin(), e = setsToRequest.cend(); i != e; ++i) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().scheduleStickerSetRequest(i.key(), i.value());
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestStickerSets();
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
|
|
|
|
not_null<DocumentData*> document) {
|
2017-08-03 11:15:57 +00:00
|
|
|
if (auto sticker = document->sticker()) {
|
|
|
|
auto &inputSet = sticker->set;
|
|
|
|
if (inputSet.type() != mtpc_inputStickerSetID) {
|
2017-08-15 14:34:30 +00:00
|
|
|
return base::none;
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSets();
|
2017-08-03 11:15:57 +00:00
|
|
|
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
|
|
|
|
if (it == sets.cend()) {
|
2017-08-15 14:34:30 +00:00
|
|
|
return base::none;
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
auto result = std::vector<not_null<EmojiPtr>>();
|
2017-08-03 11:15:57 +00:00
|
|
|
for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) {
|
|
|
|
if (i->contains(document)) {
|
|
|
|
result.push_back(i.key());
|
|
|
|
}
|
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
if (result.empty()) {
|
|
|
|
return base::none;
|
|
|
|
}
|
|
|
|
return std::move(result);
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
2017-08-15 14:34:30 +00:00
|
|
|
return base::none;
|
2017-08-03 11:15:57 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 12:52:56 +00:00
|
|
|
Set *FeedSet(const MTPDstickerSet &set) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-03 12:52:56 +00:00
|
|
|
auto it = sets.find(set.vid.v);
|
2017-08-12 07:17:33 +00:00
|
|
|
auto title = GetSetTitle(set);
|
2017-08-03 12:52:56 +00:00
|
|
|
auto flags = MTPDstickerSet::Flags(0);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
it = sets.insert(set.vid.v, Stickers::Set(set.vid.v, set.vaccess_hash.v, title, qs(set.vshort_name), set.vcount.v, set.vhash.v, set.vflags.v | MTPDstickerSet_ClientFlag::f_not_loaded));
|
|
|
|
} else {
|
|
|
|
it->access = set.vaccess_hash.v;
|
|
|
|
it->title = title;
|
|
|
|
it->shortName = qs(set.vshort_name);
|
|
|
|
flags = it->flags;
|
|
|
|
auto clientFlags = it->flags & (MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_unread | MTPDstickerSet_ClientFlag::f_not_loaded | MTPDstickerSet_ClientFlag::f_special);
|
|
|
|
it->flags = set.vflags.v | clientFlags;
|
|
|
|
if (it->count != set.vcount.v || it->hash != set.vhash.v || it->emoji.isEmpty()) {
|
|
|
|
it->count = set.vcount.v;
|
|
|
|
it->hash = set.vhash.v;
|
|
|
|
it->flags |= MTPDstickerSet_ClientFlag::f_not_loaded; // need to request this set
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto changedFlags = (flags ^ it->flags);
|
|
|
|
if (changedFlags & MTPDstickerSet::Flag::f_archived) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto index = Auth().data().archivedStickerSetsOrder().indexOf(it->id);
|
2017-08-03 12:52:56 +00:00
|
|
|
if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
|
|
|
if (index < 0) {
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().archivedStickerSetsOrderRef().push_front(it->id);
|
2017-08-03 12:52:56 +00:00
|
|
|
}
|
|
|
|
} else if (index >= 0) {
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().archivedStickerSetsOrderRef().removeAt(index);
|
2017-08-03 12:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return &it.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Set *FeedSetFull(const MTPmessages_StickerSet &data) {
|
|
|
|
Expects(data.type() == mtpc_messages_stickerSet);
|
|
|
|
Expects(data.c_messages_stickerSet().vset.type() == mtpc_stickerSet);
|
|
|
|
auto &d = data.c_messages_stickerSet();
|
|
|
|
auto set = FeedSet(d.vset.c_stickerSet());
|
|
|
|
|
|
|
|
set->flags &= ~MTPDstickerSet_ClientFlag::f_not_loaded;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2017-08-03 12:52:56 +00:00
|
|
|
auto &d_docs = d.vdocuments.v;
|
|
|
|
auto custom = sets.find(Stickers::CustomSetId);
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto pack = Pack();
|
2017-08-03 12:52:56 +00:00
|
|
|
pack.reserve(d_docs.size());
|
|
|
|
for (auto i = 0, l = d_docs.size(); i != l; ++i) {
|
|
|
|
auto doc = App::feedDocument(d_docs.at(i));
|
|
|
|
if (!doc || !doc->sticker()) continue;
|
|
|
|
|
|
|
|
pack.push_back(doc);
|
|
|
|
if (custom != sets.cend()) {
|
|
|
|
auto 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto writeRecent = false;
|
|
|
|
auto &recent = cGetRecentStickers();
|
|
|
|
for (auto i = recent.begin(); i != recent.cend();) {
|
|
|
|
if (set->stickers.indexOf(i->first) >= 0 && pack.indexOf(i->first) < 0) {
|
|
|
|
i = recent.erase(i);
|
|
|
|
writeRecent = true;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pack.isEmpty()) {
|
2017-11-05 17:07:27 +00:00
|
|
|
int removeIndex = Auth().data().stickerSetsOrder().indexOf(set->id);
|
|
|
|
if (removeIndex >= 0) Auth().data().stickerSetsOrderRef().removeAt(removeIndex);
|
2017-08-03 12:52:56 +00:00
|
|
|
sets.remove(set->id);
|
|
|
|
set = nullptr;
|
|
|
|
} else {
|
|
|
|
set->stickers = pack;
|
|
|
|
set->emoji.clear();
|
|
|
|
auto &v = d.vpacks.v;
|
|
|
|
for (auto i = 0, l = v.size(); i != l; ++i) {
|
|
|
|
if (v[i].type() != mtpc_stickerPack) continue;
|
|
|
|
|
|
|
|
auto &pack = v[i].c_stickerPack();
|
|
|
|
if (auto emoji = Ui::Emoji::Find(qs(pack.vemoticon))) {
|
|
|
|
emoji = emoji->original();
|
|
|
|
auto &stickers = pack.vdocuments.v;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Pack p;
|
2017-08-03 12:52:56 +00:00
|
|
|
p.reserve(stickers.size());
|
|
|
|
for (auto j = 0, c = stickers.size(); j != c; ++j) {
|
|
|
|
auto doc = App::document(stickers[j].v);
|
|
|
|
if (!doc || !doc->sticker()) continue;
|
|
|
|
|
|
|
|
p.push_back(doc);
|
|
|
|
}
|
|
|
|
set->emoji.insert(emoji, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (writeRecent) {
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
if (set->flags & MTPDstickerSet::Flag::f_installed) {
|
|
|
|
if (!(set->flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set->flags & MTPDstickerSet_ClientFlag::f_featured) {
|
|
|
|
Local::writeFeaturedStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().markStickersUpdated();
|
2017-08-03 12:52:56 +00:00
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2017-08-12 07:17:33 +00:00
|
|
|
QString GetSetTitle(const MTPDstickerSet &s) {
|
|
|
|
auto title = qs(s.vtitle);
|
|
|
|
if ((s.vflags.v & MTPDstickerSet::Flag::f_official) && !title.compare(qstr("Great Minds"), Qt::CaseInsensitive)) {
|
|
|
|
return lang(lng_stickers_default_set);
|
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:52:46 +00:00
|
|
|
} // namespace Stickers
|