mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Apply faved stickers limit when faving.
This commit is contained in:
parent
a72453fb1b
commit
81fb32504b
3 changed files with 96 additions and 79 deletions
|
@ -207,7 +207,38 @@ void CheckFavedLimit(Set &set) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetIsFaved(gsl::not_null<DocumentData*> document, const std::vector<gsl::not_null<EmojiPtr>> *emojiList = nullptr) {
|
void PushFavedToFront(
|
||||||
|
Set &set,
|
||||||
|
gsl::not_null<DocumentData*> document,
|
||||||
|
const std::vector<gsl::not_null<EmojiPtr>> &emojiList) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestSetToPushFaved(gsl::not_null<DocumentData*> document);
|
||||||
|
|
||||||
|
void SetIsFaved(gsl::not_null<DocumentData*> document, base::optional<std::vector<gsl::not_null<EmojiPtr>>> emojiList = base::none) {
|
||||||
auto &sets = Global::RefStickerSets();
|
auto &sets = Global::RefStickerSets();
|
||||||
auto it = sets.find(FavedSetId);
|
auto it = sets.find(FavedSetId);
|
||||||
if (it == sets.end()) {
|
if (it == sets.end()) {
|
||||||
|
@ -218,28 +249,21 @@ void SetIsFaved(gsl::not_null<DocumentData*> document, const std::vector<gsl::no
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
// Push this sticker to the front.
|
MoveFavedToFront(*it, index);
|
||||||
while (index-- != 0) {
|
|
||||||
it->stickers[index + 1] = it->stickers[index];
|
|
||||||
}
|
|
||||||
it->stickers[0] = document;
|
|
||||||
for (auto &list : it->emoji) {
|
|
||||||
auto index = list.indexOf(document);
|
|
||||||
if (index > 0) {
|
|
||||||
while (index-- != 0) {
|
|
||||||
list[index + 1] = list[index];
|
|
||||||
}
|
|
||||||
list[0] = document;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (emojiList) {
|
} else if (emojiList) {
|
||||||
it->stickers.push_front(document);
|
PushFavedToFront(*it, document, *emojiList);
|
||||||
for (auto emoji : *emojiList) {
|
} else if (auto list = GetEmojiListFromSet(document)) {
|
||||||
it->emoji[emoji].push_front(document);
|
PushFavedToFront(*it, document, *list);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto list = GetEmojiListFromSet(document);
|
RequestSetToPushFaved(document);
|
||||||
if (list.empty()) {
|
return;
|
||||||
|
}
|
||||||
|
Local::writeFavedStickers();
|
||||||
|
Auth().data().stickersUpdated().notify(true);
|
||||||
|
App::main()->onStickersInstalled(FavedSetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestSetToPushFaved(gsl::not_null<DocumentData*> document) {
|
||||||
auto addAnyway = [document](std::vector<gsl::not_null<EmojiPtr>> list) {
|
auto addAnyway = [document](std::vector<gsl::not_null<EmojiPtr>> list) {
|
||||||
if (list.empty()) {
|
if (list.empty()) {
|
||||||
if (auto sticker = document->sticker()) {
|
if (auto sticker = document->sticker()) {
|
||||||
|
@ -248,7 +272,7 @@ void SetIsFaved(gsl::not_null<DocumentData*> document, const std::vector<gsl::no
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetIsFaved(document, &list);
|
SetIsFaved(document, std::move(list));
|
||||||
};
|
};
|
||||||
MTP::send(MTPmessages_GetStickerSet(document->sticker()->set), rpcDone([document, addAnyway](const MTPmessages_StickerSet &result) {
|
MTP::send(MTPmessages_GetStickerSet(document->sticker()->set), rpcDone([document, addAnyway](const MTPmessages_StickerSet &result) {
|
||||||
Expects(result.type() == mtpc_messages_stickerSet);
|
Expects(result.type() == mtpc_messages_stickerSet);
|
||||||
|
@ -272,20 +296,9 @@ void SetIsFaved(gsl::not_null<DocumentData*> document, const std::vector<gsl::no
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Perhaps this is a deleted sticker pack. Add anyway.
|
// Perhaps this is a deleted sticker pack. Add anyway.
|
||||||
addAnyway(std::vector<gsl::not_null<EmojiPtr>>());
|
addAnyway({});
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
return;
|
|
||||||
}
|
|
||||||
it->stickers.push_front(document);
|
|
||||||
for (auto emoji : list) {
|
|
||||||
it->emoji[emoji].push_front(document);
|
|
||||||
}
|
|
||||||
CheckFavedLimit(*it);
|
|
||||||
}
|
|
||||||
Local::writeFavedStickers();
|
|
||||||
Auth().data().stickersUpdated().notify(true);
|
|
||||||
App::main()->onStickersInstalled(FavedSetId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetIsNotFaved(gsl::not_null<DocumentData*> document) {
|
void SetIsNotFaved(gsl::not_null<DocumentData*> document) {
|
||||||
|
@ -660,25 +673,30 @@ StickerPack GetListByEmoji(gsl::not_null<EmojiPtr> emoji) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<gsl::not_null<EmojiPtr>> GetEmojiListFromSet(gsl::not_null<DocumentData*> document) {
|
base::optional<std::vector<gsl::not_null<EmojiPtr>>> GetEmojiListFromSet(
|
||||||
auto result = std::vector<gsl::not_null<EmojiPtr>>();
|
gsl::not_null<DocumentData*> document) {
|
||||||
if (auto sticker = document->sticker()) {
|
if (auto sticker = document->sticker()) {
|
||||||
auto &inputSet = sticker->set;
|
auto &inputSet = sticker->set;
|
||||||
if (inputSet.type() != mtpc_inputStickerSetID) {
|
if (inputSet.type() != mtpc_inputStickerSetID) {
|
||||||
return result;
|
return base::none;
|
||||||
}
|
}
|
||||||
auto &sets = Global::StickerSets();
|
auto &sets = Global::StickerSets();
|
||||||
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
|
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
|
||||||
if (it == sets.cend()) {
|
if (it == sets.cend()) {
|
||||||
return result;
|
return base::none;
|
||||||
}
|
}
|
||||||
|
auto result = std::vector<gsl::not_null<EmojiPtr>>();
|
||||||
for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) {
|
for (auto i = it->emoji.cbegin(), e = it->emoji.cend(); i != e; ++i) {
|
||||||
if (i->contains(document)) {
|
if (i->contains(document)) {
|
||||||
result.push_back(i.key());
|
result.push_back(i.key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (result.empty()) {
|
||||||
|
return base::none;
|
||||||
}
|
}
|
||||||
return result;
|
return std::move(result);
|
||||||
|
}
|
||||||
|
return base::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set *FeedSet(const MTPDstickerSet &set) {
|
Set *FeedSet(const MTPDstickerSet &set) {
|
||||||
|
|
|
@ -40,7 +40,8 @@ void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVect
|
||||||
void GifsReceived(const QVector<MTPDocument> &items, int32 hash);
|
void GifsReceived(const QVector<MTPDocument> &items, int32 hash);
|
||||||
|
|
||||||
StickerPack GetListByEmoji(gsl::not_null<EmojiPtr> emoji);
|
StickerPack GetListByEmoji(gsl::not_null<EmojiPtr> emoji);
|
||||||
std::vector<gsl::not_null<EmojiPtr>> GetEmojiListFromSet(gsl::not_null<DocumentData*> document);
|
base::optional<std::vector<gsl::not_null<EmojiPtr>>> GetEmojiListFromSet(
|
||||||
|
gsl::not_null<DocumentData*> document);
|
||||||
|
|
||||||
Set *FeedSet(const MTPDstickerSet &data);
|
Set *FeedSet(const MTPDstickerSet &data);
|
||||||
Set *FeedSetFull(const MTPmessages_StickerSet &data);
|
Set *FeedSetFull(const MTPmessages_StickerSet &data);
|
||||||
|
|
|
@ -826,21 +826,19 @@ void MediaPreviewWidget::hidePreview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaPreviewWidget::fillEmojiString() {
|
void MediaPreviewWidget::fillEmojiString() {
|
||||||
if (_photo) {
|
|
||||||
_emojiList.clear();
|
_emojiList.clear();
|
||||||
} else if (auto sticker = _document->sticker()) {
|
if (_photo) {
|
||||||
_emojiList = Stickers::GetEmojiListFromSet(_document);
|
return;
|
||||||
if (_emojiList.empty()) {
|
|
||||||
if (auto emoji = Ui::Emoji::Find(sticker->alt)) {
|
|
||||||
_emojiList.push_back(emoji);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (auto sticker = _document->sticker()) {
|
||||||
|
if (auto list = Stickers::GetEmojiListFromSet(_document)) {
|
||||||
|
_emojiList = std::move(*list);
|
||||||
while (_emojiList.size() > kStickerPreviewEmojiLimit) {
|
while (_emojiList.size() > kStickerPreviewEmojiLimit) {
|
||||||
_emojiList.pop_back();
|
_emojiList.pop_back();
|
||||||
}
|
}
|
||||||
|
} else if (auto emoji = Ui::Emoji::Find(sticker->alt)) {
|
||||||
|
_emojiList.push_back(emoji);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_emojiList.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue