mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Optimize emoji / stickers update requests.
This commit is contained in:
parent
4f7aa15416
commit
4cf4b6a368
15 changed files with 96 additions and 59 deletions
|
@ -2336,7 +2336,11 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
stickers.setsOrderRef() = std::move(result);
|
||||
session().local().writeInstalledStickers();
|
||||
}
|
||||
stickers.notifyUpdated();
|
||||
stickers.notifyUpdated(isEmoji
|
||||
? Data::StickersType::Emoji
|
||||
: isMasks
|
||||
? Data::StickersType::Masks
|
||||
: Data::StickersType::Stickers);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
|
@ -1679,7 +1679,7 @@ void ApiWrap::saveStickerSets(
|
|||
if (writeFaved) {
|
||||
storage.writeFavedStickers();
|
||||
}
|
||||
_session->data().stickers().notifyUpdated();
|
||||
_session->data().stickers().notifyUpdated(type);
|
||||
|
||||
if (setDisenableRequests.empty()) {
|
||||
stickersSaveOrder();
|
||||
|
@ -2555,7 +2555,7 @@ void ApiWrap::setGroupStickerSet(
|
|||
megagroup->inputChannel,
|
||||
Data::InputStickerSet(set)
|
||||
)).send();
|
||||
_session->data().stickers().notifyUpdated();
|
||||
_session->data().stickers().notifyUpdated(Data::StickersType::Stickers);
|
||||
}
|
||||
|
||||
std::vector<not_null<DocumentData*>> *ApiWrap::stickersByEmoji(
|
||||
|
@ -2595,7 +2595,8 @@ std::vector<not_null<DocumentData*>> *ApiWrap::stickersByEmoji(
|
|||
}
|
||||
entry.hash = data.vhash().v;
|
||||
entry.received = crl::now();
|
||||
_session->data().stickers().notifyUpdated();
|
||||
_session->data().stickers().notifyUpdated(
|
||||
Data::StickersType::Stickers);
|
||||
}).send();
|
||||
}
|
||||
if (it == _stickersByEmoji.end()) {
|
||||
|
@ -2864,7 +2865,8 @@ void ApiWrap::readFeaturedSets() {
|
|||
MTP_vector<MTPlong>(wrappedIds));
|
||||
request(std::move(requestData)).done([=] {
|
||||
local().writeFeaturedStickers();
|
||||
_session->data().stickers().notifyUpdated();
|
||||
_session->data().stickers().notifyUpdated(
|
||||
Data::StickersType::Stickers);
|
||||
}).send();
|
||||
|
||||
_session->data().stickers().setFeaturedSetsUnreadCount(count);
|
||||
|
|
|
@ -301,6 +301,7 @@ void StickerSetBox::prepare() {
|
|||
object_ptr<Inner>(this, _controller, _set, _type),
|
||||
st::stickersScroll);
|
||||
_controller->session().data().stickers().updated(
|
||||
_type
|
||||
) | rpl::start_with_next([=] {
|
||||
updateButtons();
|
||||
}, lifetime());
|
||||
|
@ -369,7 +370,7 @@ void StickerSetBox::prepare() {
|
|||
}
|
||||
}
|
||||
|
||||
_controller->session().data().stickers().notifyUpdated();
|
||||
_controller->session().data().stickers().notifyUpdated(type);
|
||||
|
||||
closeBox();
|
||||
}, lifetime());
|
||||
|
@ -785,7 +786,7 @@ void StickerSetBox::Inner::installDone(
|
|||
} else {
|
||||
storage.writeInstalledStickers();
|
||||
}
|
||||
stickers.notifyUpdated();
|
||||
stickers.notifyUpdated(type);
|
||||
}
|
||||
_setInstalled.fire_copy(_setId);
|
||||
}
|
||||
|
|
|
@ -619,9 +619,10 @@ void StickersBox::prepare() {
|
|||
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
||||
|
||||
session().data().stickers().updated(
|
||||
) | rpl::start_with_next(
|
||||
[this] { handleStickersUpdated(); },
|
||||
lifetime());
|
||||
_isMasks ? Data::StickersType::Masks : Data::StickersType::Stickers
|
||||
) | rpl::start_with_next([=] {
|
||||
handleStickersUpdated();
|
||||
}, lifetime());
|
||||
session().api().updateStickers();
|
||||
session().api().updateMasks();
|
||||
|
||||
|
@ -871,7 +872,8 @@ void StickersBox::installSet(uint64 setId) {
|
|||
}
|
||||
}
|
||||
|
||||
void StickersBox::installDone(const MTPmessages_StickerSetInstallResult &result) {
|
||||
void StickersBox::installDone(
|
||||
const MTPmessages_StickerSetInstallResult &result) {
|
||||
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
||||
session().data().stickers().applyArchivedResult(
|
||||
result.c_messages_stickerSetInstallResultArchive());
|
||||
|
|
|
@ -393,6 +393,7 @@ EmojiListWidget::EmojiListWidget(
|
|||
}, lifetime());
|
||||
|
||||
controller->session().data().stickers().updated(
|
||||
Data::StickersType::Emoji
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshCustom();
|
||||
resizeToWidth(width());
|
||||
|
@ -1372,6 +1373,7 @@ void EmojiListWidget::refreshCustom() {
|
|||
|
||||
_footer->refreshIcons(
|
||||
fillIcons(),
|
||||
currentSet(getVisibleTop()),
|
||||
nullptr,
|
||||
ValidateIconAnimations::None);
|
||||
update();
|
||||
|
|
|
@ -643,7 +643,7 @@ void StickersListFooter::resizeEvent(QResizeEvent *e) {
|
|||
if (_searchField) {
|
||||
resizeSearchControls();
|
||||
}
|
||||
refreshIconsGeometry(ValidateIconAnimations::None);
|
||||
refreshIconsGeometry(_activeByScrollId, ValidateIconAnimations::None);
|
||||
}
|
||||
|
||||
void StickersListFooter::resizeSearchControls() {
|
||||
|
@ -929,6 +929,7 @@ auto StickersListFooter::getLottieRenderer()
|
|||
|
||||
void StickersListFooter::refreshIcons(
|
||||
std::vector<StickerIcon> icons,
|
||||
uint64 activeSetId,
|
||||
Fn<std::shared_ptr<Lottie::FrameRenderer>()> renderer,
|
||||
ValidateIconAnimations animations) {
|
||||
_renderer = renderer
|
||||
|
@ -955,7 +956,7 @@ void StickersListFooter::refreshIcons(
|
|||
}
|
||||
|
||||
_icons = std::move(icons);
|
||||
refreshIconsGeometry(animations);
|
||||
refreshIconsGeometry(activeSetId, animations);
|
||||
}
|
||||
|
||||
void StickersListFooter::refreshScrollableDimensions() {
|
||||
|
@ -969,6 +970,7 @@ void StickersListFooter::refreshScrollableDimensions() {
|
|||
}
|
||||
|
||||
void StickersListFooter::refreshIconsGeometry(
|
||||
uint64 activeSetId,
|
||||
ValidateIconAnimations animations) {
|
||||
_selected = _pressed = SpecialOver::None;
|
||||
_iconState.x.finish();
|
||||
|
@ -990,11 +992,14 @@ void StickersListFooter::refreshIconsGeometry(
|
|||
refreshScrollableDimensions();
|
||||
refreshSubiconsGeometry();
|
||||
_iconState.selected = _subiconState.selected = -1;
|
||||
validateSelectedIcon(_activeByScrollId, animations);
|
||||
validateSelectedIcon(activeSetId, animations);
|
||||
update();
|
||||
}
|
||||
|
||||
void StickersListFooter::refreshSubiconsGeometry() {
|
||||
if (_barSelection) {
|
||||
return;
|
||||
}
|
||||
using Section = Ui::Emoji::Section;
|
||||
_subiconState.x.finish();
|
||||
_subiconState.animationStart = 0;
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
ValidateIconAnimations animations);
|
||||
void refreshIcons(
|
||||
std::vector<StickerIcon> icons,
|
||||
uint64 activeSetId,
|
||||
Fn<std::shared_ptr<Lottie::FrameRenderer>()> renderer,
|
||||
ValidateIconAnimations animations);
|
||||
[[nodiscard]] bool hasOnlyFeaturedSets() const;
|
||||
|
@ -179,7 +180,9 @@ private:
|
|||
void validateIconWebmAnimation(const StickerIcon &icon);
|
||||
void validateIconAnimation(const StickerIcon &icon);
|
||||
|
||||
void refreshIconsGeometry(ValidateIconAnimations animations);
|
||||
void refreshIconsGeometry(
|
||||
uint64 activeSetId,
|
||||
ValidateIconAnimations animations);
|
||||
void refreshSubiconsGeometry();
|
||||
void refreshScrollableDimensions();
|
||||
void updateSelected();
|
||||
|
|
|
@ -209,11 +209,8 @@ StickersListWidget::StickersListWidget(
|
|||
}, lifetime());
|
||||
|
||||
session().data().stickers().recentUpdated(
|
||||
) | rpl::start_with_next([=](Data::Stickers::Recent recent) {
|
||||
const auto attached = (recent == Data::Stickers::Recent::Attached);
|
||||
if (attached != _isMasks) {
|
||||
return;
|
||||
}
|
||||
_isMasks ? Data::StickersType::Masks : Data::StickersType::Stickers
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshRecent();
|
||||
}, lifetime());
|
||||
|
||||
|
@ -2547,6 +2544,7 @@ void StickersListWidget::refreshIcons(ValidateIconAnimations animations) {
|
|||
if (_footer) {
|
||||
_footer->refreshIcons(
|
||||
fillIcons(),
|
||||
currentSet(getVisibleTop()),
|
||||
[=] { return getLottieRenderer(); },
|
||||
animations);
|
||||
}
|
||||
|
@ -2725,7 +2723,9 @@ object_ptr<Ui::BoxContent> MakeConfirmRemoveSetBox(
|
|||
if (removeIndex >= 0) {
|
||||
orderRef.removeAt(removeIndex);
|
||||
}
|
||||
if (set->flags & SetFlag::Masks) {
|
||||
if (set->type() == Data::StickersType::Emoji) {
|
||||
session->local().writeInstalledCustomEmoji();
|
||||
} else if (set->type() == Data::StickersType::Masks) {
|
||||
session->local().writeInstalledMasks();
|
||||
} else {
|
||||
session->local().writeInstalledStickers();
|
||||
|
@ -2733,7 +2733,7 @@ object_ptr<Ui::BoxContent> MakeConfirmRemoveSetBox(
|
|||
if (writeRecent) {
|
||||
session->saveSettings();
|
||||
}
|
||||
session->data().stickers().notifyUpdated();
|
||||
session->data().stickers().notifyUpdated(set->type());
|
||||
}
|
||||
},
|
||||
.cancelled = [=](Fn<void()> &&close) {
|
||||
|
|
|
@ -399,7 +399,9 @@ TabbedSelector::TabbedSelector(
|
|||
|
||||
rpl::merge(
|
||||
session().premiumPossibleValue() | rpl::to_empty,
|
||||
session().data().stickers().updated()
|
||||
session().data().stickers().updated(hasMasksTab()
|
||||
? Data::StickersType::Masks
|
||||
: Data::StickersType::Stickers)
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshStickers();
|
||||
}, lifetime());
|
||||
|
|
|
@ -146,22 +146,32 @@ Main::Session &Stickers::session() const {
|
|||
return _owner->session();
|
||||
}
|
||||
|
||||
void Stickers::notifyUpdated() {
|
||||
_updated.fire({});
|
||||
void Stickers::notifyUpdated(StickersType type) {
|
||||
_updated.fire_copy(type);
|
||||
}
|
||||
|
||||
rpl::producer<> Stickers::updated() const {
|
||||
rpl::producer<StickersType> Stickers::updated() const {
|
||||
return _updated.events();
|
||||
}
|
||||
|
||||
void Stickers::notifyRecentUpdated(Recent recent) {
|
||||
_recentUpdated.fire(std::move(recent));
|
||||
rpl::producer<> Stickers::updated(StickersType type) const {
|
||||
using namespace rpl::mappers;
|
||||
return updated() | rpl::filter(_1 == type) | rpl::to_empty;
|
||||
}
|
||||
|
||||
rpl::producer<Stickers::Recent> Stickers::recentUpdated() const {
|
||||
void Stickers::notifyRecentUpdated(StickersType type) {
|
||||
_recentUpdated.fire_copy(type);
|
||||
}
|
||||
|
||||
rpl::producer<StickersType> Stickers::recentUpdated() const {
|
||||
return _recentUpdated.events();
|
||||
}
|
||||
|
||||
rpl::producer<> Stickers::recentUpdated(StickersType type) const {
|
||||
using namespace rpl::mappers;
|
||||
return recentUpdated() | rpl::filter(_1 == type) | rpl::to_empty;
|
||||
}
|
||||
|
||||
void Stickers::notifySavedGifsUpdated() {
|
||||
_savedGifsUpdated.fire({});
|
||||
}
|
||||
|
@ -297,7 +307,7 @@ void Stickers::incrementSticker(not_null<DocumentData*> document) {
|
|||
if (writeRecentStickers) {
|
||||
session().local().writeRecentStickers();
|
||||
}
|
||||
notifyRecentUpdated();
|
||||
notifyRecentUpdated(StickersType::Stickers);
|
||||
}
|
||||
|
||||
void Stickers::addSavedGif(
|
||||
|
@ -392,8 +402,12 @@ void Stickers::applyArchivedResult(
|
|||
//Ui::show(
|
||||
// Box<StickersBox>(archived, &session()),
|
||||
// Ui::LayerOption::KeepOther);
|
||||
|
||||
notifyUpdated();
|
||||
if (stickersCount) {
|
||||
notifyUpdated(StickersType::Stickers);
|
||||
}
|
||||
if (masksCount) {
|
||||
notifyUpdated(StickersType::Masks);
|
||||
}
|
||||
}
|
||||
|
||||
void Stickers::installLocally(uint64 setId) {
|
||||
|
@ -458,7 +472,7 @@ void Stickers::installLocally(uint64 setId) {
|
|||
}
|
||||
}
|
||||
}
|
||||
notifyUpdated();
|
||||
notifyUpdated(set->type());
|
||||
}
|
||||
|
||||
void Stickers::undoInstallLocally(uint64 setId) {
|
||||
|
@ -479,7 +493,7 @@ void Stickers::undoInstallLocally(uint64 setId) {
|
|||
}
|
||||
|
||||
session().local().writeInstalledStickers();
|
||||
notifyUpdated();
|
||||
notifyUpdated(set->type());
|
||||
|
||||
Ui::show(
|
||||
Ui::MakeInformBox(tr::lng_stickers_not_found()),
|
||||
|
@ -592,7 +606,7 @@ void Stickers::setIsFaved(
|
|||
return;
|
||||
}
|
||||
session().local().writeFavedStickers();
|
||||
notifyUpdated();
|
||||
notifyUpdated(StickersType::Stickers);
|
||||
notifyStickerSetInstalled(FavedSetId);
|
||||
}
|
||||
|
||||
|
@ -642,13 +656,13 @@ void Stickers::requestSetToPushFaved(
|
|||
void Stickers::removeFromRecentSet(not_null<DocumentData*> document) {
|
||||
RemoveFromSet(setsRef(), document, CloudRecentSetId);
|
||||
session().local().writeRecentStickers();
|
||||
notifyRecentUpdated();
|
||||
notifyRecentUpdated(StickersType::Stickers);
|
||||
}
|
||||
|
||||
void Stickers::setIsNotFaved(not_null<DocumentData*> document) {
|
||||
RemoveFromSet(setsRef(), document, FavedSetId);
|
||||
session().local().writeFavedStickers();
|
||||
notifyUpdated();
|
||||
notifyUpdated(StickersType::Stickers);
|
||||
}
|
||||
|
||||
void Stickers::setFaved(
|
||||
|
@ -772,7 +786,7 @@ void Stickers::somethingReceived(
|
|||
).arg(counted));
|
||||
}
|
||||
|
||||
notifyUpdated();
|
||||
notifyUpdated(type);
|
||||
}
|
||||
|
||||
void Stickers::setPackAndEmoji(
|
||||
|
@ -925,7 +939,9 @@ void Stickers::specialSetReceived(
|
|||
default: Unexpected("setId in SpecialSetReceived()");
|
||||
}
|
||||
|
||||
notifyUpdated();
|
||||
notifyUpdated((setId == CloudRecentAttachedSetId)
|
||||
? StickersType::Masks
|
||||
: StickersType::Stickers);
|
||||
}
|
||||
|
||||
void Stickers::featuredSetsReceived(
|
||||
|
@ -1079,7 +1095,7 @@ void Stickers::featuredReceived(
|
|||
session().local().writeFeaturedStickers();
|
||||
}
|
||||
|
||||
notifyUpdated();
|
||||
notifyUpdated(type);
|
||||
}
|
||||
|
||||
void Stickers::gifsReceived(const QVector<MTPDocument> &items, uint64 hash) {
|
||||
|
@ -1501,7 +1517,7 @@ void Stickers::feedSetStickers(
|
|||
session().local().writeArchivedStickers();
|
||||
}
|
||||
}
|
||||
notifyUpdated();
|
||||
notifyUpdated(set->type());
|
||||
}
|
||||
|
||||
void Stickers::feedSetCovers(
|
||||
|
|
|
@ -60,15 +60,12 @@ public:
|
|||
// For setting up megagroup sticker set.
|
||||
static constexpr auto MegagroupSetId = 0xFFFFFFFFFFFFFFEFULL;
|
||||
|
||||
enum Recent {
|
||||
Regular,
|
||||
Attached,
|
||||
};
|
||||
|
||||
void notifyUpdated();
|
||||
[[nodiscard]] rpl::producer<> updated() const;
|
||||
void notifyRecentUpdated(Recent recent = Recent::Regular);
|
||||
[[nodiscard]] rpl::producer<Recent> recentUpdated() const;
|
||||
void notifyUpdated(StickersType type);
|
||||
[[nodiscard]] rpl::producer<StickersType> updated() const;
|
||||
[[nodiscard]] rpl::producer<> updated(StickersType type) const;
|
||||
void notifyRecentUpdated(StickersType type);
|
||||
[[nodiscard]] rpl::producer<StickersType> recentUpdated() const;
|
||||
[[nodiscard]] rpl::producer<> recentUpdated(StickersType type) const;
|
||||
void notifySavedGifsUpdated();
|
||||
[[nodiscard]] rpl::producer<> savedGifsUpdated() const;
|
||||
void notifyStickerSetInstalled(uint64 setId);
|
||||
|
@ -89,7 +86,7 @@ public:
|
|||
}
|
||||
void setLastRecentUpdate(crl::time update) {
|
||||
if (update) {
|
||||
notifyRecentUpdated();
|
||||
notifyRecentUpdated(StickersType::Stickers);
|
||||
}
|
||||
_lastRecentUpdate = update;
|
||||
}
|
||||
|
@ -110,7 +107,7 @@ public:
|
|||
}
|
||||
void setLastRecentAttachedUpdate(crl::time update) {
|
||||
if (update) {
|
||||
notifyRecentUpdated(Recent::Attached);
|
||||
notifyRecentUpdated(StickersType::Masks);
|
||||
}
|
||||
_lastRecentAttachedUpdate = update;
|
||||
}
|
||||
|
@ -293,8 +290,8 @@ private:
|
|||
StickersType type);
|
||||
|
||||
const not_null<Session*> _owner;
|
||||
rpl::event_stream<> _updated;
|
||||
rpl::event_stream<Recent> _recentUpdated;
|
||||
rpl::event_stream<StickersType> _updated;
|
||||
rpl::event_stream<StickersType> _recentUpdated;
|
||||
rpl::event_stream<> _savedGifsUpdated;
|
||||
rpl::event_stream<uint64> _stickerSetInstalled;
|
||||
rpl::event_stream<uint64> _emojiSetInstalled;
|
||||
|
|
|
@ -1335,6 +1335,7 @@ int HistoryWidget::itemTopForHighlight(
|
|||
|
||||
void HistoryWidget::start() {
|
||||
session().data().stickers().updated(
|
||||
Data::StickersType::Stickers
|
||||
) | rpl::start_with_next([=] {
|
||||
updateStickersByEmoji();
|
||||
}, lifetime());
|
||||
|
|
|
@ -1531,6 +1531,7 @@ void ComposeControls::initAutocomplete() {
|
|||
}, _autocomplete->lifetime());
|
||||
|
||||
_window->session().data().stickers().updated(
|
||||
Data::StickersType::Stickers
|
||||
) | rpl::start_with_next([=] {
|
||||
updateStickersByEmoji();
|
||||
}, _autocomplete->lifetime());
|
||||
|
|
|
@ -164,7 +164,9 @@ Session::Session(
|
|||
local().readRecentMasks();
|
||||
local().readFavedStickers();
|
||||
local().readSavedGifs();
|
||||
data().stickers().notifyUpdated();
|
||||
data().stickers().notifyUpdated(Data::StickersType::Stickers);
|
||||
data().stickers().notifyUpdated(Data::StickersType::Masks);
|
||||
data().stickers().notifyUpdated(Data::StickersType::Emoji);
|
||||
data().stickers().notifySavedGifsUpdated();
|
||||
});
|
||||
|
||||
|
|
|
@ -577,11 +577,10 @@ void AppendEmojiPacks(
|
|||
|
||||
rpl::merge(
|
||||
rpl::merge(
|
||||
_session->data().stickers().updated(),
|
||||
_session->data().stickers().updated(
|
||||
Data::StickersType::Stickers),
|
||||
_session->data().stickers().recentUpdated(
|
||||
) | rpl::filter([](Data::Stickers::Recent recent) {
|
||||
return (recent != Data::Stickers::Recent::Attached);
|
||||
}) | rpl::to_empty
|
||||
Data::StickersType::Stickers)
|
||||
) | rpl::map_to(ScrubberItemType::Sticker),
|
||||
rpl::merge(
|
||||
Core::App().settings().recentEmojiUpdated(),
|
||||
|
|
Loading…
Add table
Reference in a new issue