mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Implement background emoji selector.
This commit is contained in:
@@ -510,40 +510,57 @@ void PeerPhoto::requestUserPhotos(
|
||||
_userPhotosRequests.emplace(user, requestId);
|
||||
}
|
||||
|
||||
auto PeerPhoto::emojiList(EmojiListType type) -> EmojiListData & {
|
||||
switch (type) {
|
||||
case EmojiListType::Profile: return _profileEmojiList;
|
||||
case EmojiListType::Group: return _groupEmojiList;
|
||||
case EmojiListType::Background: return _backgroundEmojiList;
|
||||
}
|
||||
Unexpected("Type in PeerPhoto::emojiList.");
|
||||
}
|
||||
|
||||
auto PeerPhoto::emojiList(EmojiListType type) const
|
||||
-> const EmojiListData & {
|
||||
return const_cast<PeerPhoto*>(this)->emojiList(type);
|
||||
}
|
||||
|
||||
void PeerPhoto::requestEmojiList(EmojiListType type) {
|
||||
if (_requestIdEmojiList) {
|
||||
auto &list = emojiList(type);
|
||||
if (list.requestId) {
|
||||
return;
|
||||
}
|
||||
const auto isGroup = (type == EmojiListType::Group);
|
||||
const auto d = [=](const MTPEmojiList &result) {
|
||||
_requestIdEmojiList = 0;
|
||||
result.match([](const MTPDemojiListNotModified &data) {
|
||||
}, [&](const MTPDemojiList &data) {
|
||||
auto &list = isGroup ? _profileEmojiList : _groupEmojiList;
|
||||
list = ranges::views::all(
|
||||
data.vdocument_id().v
|
||||
) | ranges::views::transform(&MTPlong::v) | ranges::to_vector;
|
||||
});
|
||||
const auto send = [&](auto &&request) {
|
||||
return _api.request(
|
||||
std::move(request)
|
||||
).done([=](const MTPEmojiList &result) {
|
||||
auto &list = emojiList(type);
|
||||
list.requestId = 0;
|
||||
result.match([](const MTPDemojiListNotModified &data) {
|
||||
}, [&](const MTPDemojiList &data) {
|
||||
list.list = ranges::views::all(
|
||||
data.vdocument_id().v
|
||||
) | ranges::views::transform(
|
||||
&MTPlong::v
|
||||
) | ranges::to_vector;
|
||||
});
|
||||
}).fail([=] {
|
||||
emojiList(type).requestId = 0;
|
||||
}).send();
|
||||
};
|
||||
const auto f = [=] { _requestIdEmojiList = 0; };
|
||||
_requestIdEmojiList = isGroup
|
||||
? _api.request(
|
||||
MTPaccount_GetDefaultGroupPhotoEmojis()
|
||||
).done(d).fail(f).send()
|
||||
: _api.request(
|
||||
MTPaccount_GetDefaultProfilePhotoEmojis()
|
||||
).done(d).fail(f).send();
|
||||
list.requestId = (type == EmojiListType::Profile)
|
||||
? send(MTPaccount_GetDefaultProfilePhotoEmojis())
|
||||
: (type == EmojiListType::Group)
|
||||
? send(MTPaccount_GetDefaultGroupPhotoEmojis())
|
||||
: send(MTPaccount_GetDefaultBackgroundEmojis());
|
||||
}
|
||||
|
||||
rpl::producer<PeerPhoto::EmojiList> PeerPhoto::emojiListValue(
|
||||
EmojiListType type) {
|
||||
auto &list = (type == EmojiListType::Group)
|
||||
? _profileEmojiList
|
||||
: _groupEmojiList;
|
||||
if (list.current().empty() && !_requestIdEmojiList) {
|
||||
auto &list = emojiList(type);
|
||||
if (list.list.current().empty() && !list.requestId) {
|
||||
requestEmojiList(type);
|
||||
}
|
||||
return list.value();
|
||||
return list.list.value();
|
||||
}
|
||||
|
||||
// Non-personal photo in case a personal photo is set.
|
||||
|
||||
Reference in New Issue
Block a user