diff --git a/Telegram/SourceFiles/api/api_attached_stickers.cpp b/Telegram/SourceFiles/api/api_attached_stickers.cpp index 480e9674b..02076dabe 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.cpp +++ b/Telegram/SourceFiles/api/api_attached_stickers.cpp @@ -52,8 +52,10 @@ void AttachedStickers::request( }); const auto setId = (setData->vid().v && setData->vaccess_hash().v) - ? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) - : MTP_inputStickerSetShortName(setData->vshort_name()); + ? StickerSetIdentifier{ + .id = setData->vid().v, + .accessHash = setData->vaccess_hash().v } + : StickerSetIdentifier{ .shortName = qs(setData->vshort_name()) }; strongController->show( Box(strongController, setId), Ui::LayerOption::KeepOther); diff --git a/Telegram/SourceFiles/api/api_media.cpp b/Telegram/SourceFiles/api/api_media.cpp index f99848b0a..517389d13 100644 --- a/Telegram/SourceFiles/api/api_media.cpp +++ b/Telegram/SourceFiles/api/api_media.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_media.h" #include "data/data_document.h" +#include "data/stickers/data_stickers_set.h" #include "history/history_item.h" namespace Api { @@ -47,7 +48,7 @@ MTPVector ComposeSendingDocumentAttributes( attributes.push_back(MTP_documentAttributeSticker( MTP_flags(0), MTP_string(document->sticker()->alt), - document->sticker()->set, + Data::InputStickerSet(document->sticker()->set), MTPMaskCoords())); } else if (const auto song = document->song()) { const auto flags = MTPDdocumentAttributeAudio::Flag::f_title diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index cfa7589c0..9737bbd64 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3028,11 +3028,16 @@ void ApiWrap::requestRecentStickersForce(bool attached) { requestRecentStickersWithHash(0, attached); } -void ApiWrap::setGroupStickerSet(not_null megagroup, const MTPInputStickerSet &set) { +void ApiWrap::setGroupStickerSet( + not_null megagroup, + const StickerSetIdentifier &set) { Expects(megagroup->mgInfo != nullptr); megagroup->mgInfo->stickerSet = set; - request(MTPchannels_SetStickers(megagroup->inputChannel, set)).send(); + request(MTPchannels_SetStickers( + megagroup->inputChannel, + Data::InputStickerSet(set) + )).send(); _session->data().stickers().notifyUpdated(); } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 649033272..8b31f82f0 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -288,7 +288,7 @@ public: void requestRecentStickersForce(bool attached = false); void setGroupStickerSet( not_null megagroup, - const MTPInputStickerSet &set); + const StickerSetIdentifier &set); std::vector> *stickersByEmoji( not_null emoji); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index d824993de..9d88809c8 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -59,7 +59,7 @@ public: Inner( QWidget *parent, not_null controller, - const MTPInputStickerSet &set); + const StickerSetIdentifier &set); bool loaded() const; bool notInstalled() const; @@ -134,7 +134,7 @@ private: const std::unique_ptr _pathGradient; - MTPInputStickerSet _input; + StickerSetIdentifier _input; mtpRequestId _installRequest = 0; @@ -153,7 +153,7 @@ private: StickerSetBox::StickerSetBox( QWidget*, not_null controller, - const MTPInputStickerSet &set) + const StickerSetIdentifier &set) : _controller(controller) , _set(set) { } @@ -162,7 +162,7 @@ QPointer StickerSetBox::Show( not_null controller, not_null document) { if (const auto sticker = document->sticker()) { - if (sticker->set.type() != mtpc_inputStickerSetEmpty) { + if (sticker->set) { return controller->show( Box(controller, sticker->set), Ui::LayerOption::KeepOther).data(); @@ -344,28 +344,21 @@ void StickerSetBox::resizeEvent(QResizeEvent *e) { StickerSetBox::Inner::Inner( QWidget *parent, not_null controller, - const MTPInputStickerSet &set) + const StickerSetIdentifier &set) : RpWidget(parent) , _controller(controller) , _api(&_controller->session().mtp()) +, _setId(set.id) +, _setAccess(set.accessHash) +, _setShortName(set.shortName) , _pathGradient(std::make_unique( st::windowBgRipple, st::windowBgOver, [=] { update(); })) , _input(set) , _previewTimer([=] { showPreview(); }) { - set.match([&](const MTPDinputStickerSetID &data) { - _setId = data.vid().v; - _setAccess = data.vaccess_hash().v; - }, [&](const MTPDinputStickerSetShortName &data) { - _setShortName = qs(data.vshort_name()); - }, [](const MTPDinputStickerSetEmpty &) { - }, [](const MTPDinputStickerSetAnimatedEmoji &) { - }, [](const MTPDinputStickerSetDice &) { - }); - _api.request(MTPmessages_GetStickerSet( - _input + Data::InputStickerSet(_input) )).done([=](const MTPmessages_StickerSet &result) { gotSet(result); }).fail([=](const MTP::Error &error) { @@ -881,7 +874,7 @@ void StickerSetBox::Inner::install() { return; } _installRequest = _api.request(MTPmessages_InstallStickerSet( - _input, + Data::InputStickerSet(_input), MTP_bool(false) )).done([=](const MTPmessages_StickerSetInstallResult &result) { installDone(result); @@ -892,7 +885,7 @@ void StickerSetBox::Inner::install() { void StickerSetBox::Inner::archiveStickers() { _api.request(MTPmessages_InstallStickerSet( - _input, + Data::InputStickerSet(_input), MTP_boolTrue() )).done([=](const MTPmessages_StickerSetInstallResult &result) { if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 2bfe1633b..cdf06f4db 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -26,7 +26,7 @@ public: StickerSetBox( QWidget*, not_null controller, - const MTPInputStickerSet &set); + const StickerSetIdentifier &set); static QPointer Show( not_null controller, @@ -49,7 +49,7 @@ private: void handleError(Error error); const not_null _controller; - MTPInputStickerSet _set; + const StickerSetIdentifier _set; class Inner; QPointer _inner; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 5d6164832..8255a8f86 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -233,7 +233,7 @@ private: void rebuildMegagroupSet(); void fixupMegagroupSetAddress(); void handleMegagroupSetAddressChange(); - void setMegagroupSelectedSet(const MTPInputStickerSet &set); + void setMegagroupSelectedSet(const StickerSetIdentifier &set); int countMaxNameWidth() const; @@ -284,7 +284,7 @@ private: int _scrollbar = 0; ChannelData *_megagroupSet = nullptr; - MTPInputStickerSet _megagroupSetInput = MTP_inputStickerSetEmpty(); + StickerSetIdentifier _megagroupSetInput; std::unique_ptr _megagroupSelectedSet; object_ptr _megagroupSetField = { nullptr }; object_ptr _megagroupSelectedShadow = { nullptr }; @@ -1713,14 +1713,14 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { const auto showSetByRow = [&](const Row &row) { setSelected(SelectedRow()); _controller->show( - Box(_controller, row.set->mtpInput()), + Box(_controller, row.set->identifier()), Ui::LayerOption::KeepOther); }; if (selectedIndex >= 0 && !_inDragArea) { const auto row = _rows[selectedIndex].get(); if (!row->isRecentSet()) { if (_megagroupSet) { - setMegagroupSelectedSet(row->set->mtpInput()); + setMegagroupSelectedSet(row->set->identifier()); } else { showSetByRow(*row); } @@ -1735,12 +1735,8 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { void StickersBox::Inner::saveGroupSet() { Expects(_megagroupSet != nullptr); - auto oldId = (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) - ? _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v - : 0; - auto newId = (_megagroupSetInput.type() == mtpc_inputStickerSetID) - ? _megagroupSetInput.c_inputStickerSetID().vid().v - : 0; + auto oldId = _megagroupSet->mgInfo->stickerSet.id; + auto newId = _megagroupSetInput.id; if (newId != oldId) { session().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput); session().data().stickers().notifyStickerSetInstalled( @@ -1877,7 +1873,7 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { const auto &sets = session().data().stickers().sets(); const auto it = sets.find(_megagroupSelectedSet->set->id); if (it != sets.cend() && !it->second->shortName.isEmpty()) { - setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); + setMegagroupSelectedSet({}); } } } else if (!_megagroupSetRequestId) { @@ -1886,12 +1882,10 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { )).done([=](const MTPmessages_StickerSet &result) { _megagroupSetRequestId = 0; auto set = session().data().stickers().feedSetFull(result); - setMegagroupSelectedSet(MTP_inputStickerSetID( - MTP_long(set->id), - MTP_long(set->access))); + setMegagroupSelectedSet(set->identifier()); }).fail([=](const MTP::Error &error) { _megagroupSetRequestId = 0; - setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); + setMegagroupSelectedSet({}); }).send(); } else { _megagroupSetAddressChangedTimer.callOnce(kHandleMegagroupSetAddressChangeTimeout); @@ -1900,7 +1894,8 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { void StickersBox::Inner::rebuildMegagroupSet() { Expects(_megagroupSet != nullptr); - if (_megagroupSetInput.type() != mtpc_inputStickerSetID) { + + if (!_megagroupSetInput.id) { if (_megagroupSelectedSet) { _megagroupSetField->setText(QString()); _megagroupSetField->finishAnimating(); @@ -1910,15 +1905,14 @@ void StickersBox::Inner::rebuildMegagroupSet() { _megagroupSelectedShadow.destroy(); return; } - auto &inputId = _megagroupSetInput.c_inputStickerSetID(); - auto setId = inputId.vid().v; + auto setId = _megagroupSetInput.id; const auto &sets = session().data().stickers().sets(); auto it = sets.find(setId); if (it == sets.cend() || (it->second->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { session().api().scheduleStickerSetRequest( - inputId.vid().v, - inputId.vaccess_hash().v); + _megagroupSetInput.id, + _megagroupSetInput.accessHash); return; } @@ -1954,7 +1948,7 @@ void StickersBox::Inner::rebuildMegagroupSet() { _megagroupSelectedRemove.create(this, st::groupStickersRemove); _megagroupSelectedRemove->show(anim::type::instant); _megagroupSelectedRemove->setClickedCallback([this] { - setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); + setMegagroupSelectedSet({}); }); _megagroupSelectedShadow.create(this); updateControlsGeometry(); @@ -2025,7 +2019,7 @@ void StickersBox::Inner::rebuild(bool masks) { updateSize(); } -void StickersBox::Inner::setMegagroupSelectedSet(const MTPInputStickerSet &set) { +void StickersBox::Inner::setMegagroupSelectedSet(const StickerSetIdentifier &set) { _megagroupSetInput = set; rebuild(false); _scrollsToY.fire(0); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index bb6dbb599..6c19b6dc0 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -2134,8 +2134,7 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const { } void StickersListWidget::showStickerSetBox(not_null document) { - if (document->sticker() - && document->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + if (document->sticker() && document->sticker()->set) { _displayingSet = true; checkHideWithBox(StickerSetBox::Show(controller(), document)); } @@ -2714,7 +2713,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { auto isShownHere = [place](bool hidden) { return (hidden == (place == GroupStickersPlace::Hidden)); }; - if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) { + if (!_megagroupSet->mgInfo->stickerSet) { if (canEdit) { auto hidden = session().settings().isGroupStickersSectionHidden( _megagroupSet->id); @@ -2745,12 +2744,12 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { if (canEdit && hidden) { removeHiddenForGroup(); } - if (_megagroupSet->mgInfo->stickerSet.type() != mtpc_inputStickerSetID) { + const auto &set = _megagroupSet->mgInfo->stickerSet; + if (!set.id) { return; } - auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID(); const auto &sets = session().data().stickers().sets(); - const auto it = sets.find(set.vid().v); + const auto it = sets.find(set.id); if (it != sets.cend()) { const auto set = it->second.get(); auto isInstalled = (set->flags & MTPDstickerSet::Flag::f_installed_date) @@ -2771,13 +2770,12 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { PrepareStickers(set->stickers)); } return; - } else if (!isShownHere(hidden) - || _megagroupSetIdRequested == set.vid().v) { + } else if (!isShownHere(hidden) || _megagroupSetIdRequested == set.id) { return; } - _megagroupSetIdRequested = set.vid().v; + _megagroupSetIdRequested = set.id; _api.request(MTPmessages_GetStickerSet( - _megagroupSet->mgInfo->stickerSet + Data::InputStickerSet(set) )).done([=](const MTPmessages_StickerSet &result) { if (const auto set = session().data().stickers().feedSetFull(result)) { refreshStickers(); @@ -3083,8 +3081,8 @@ void StickersListWidget::displaySet(uint64 setId) { Box(controller(), _megagroupSet), Ui::LayerOption::KeepOther).data()); return; - } else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) { - setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v; + } else if (_megagroupSet->mgInfo->stickerSet.id) { + setId = _megagroupSet->mgInfo->stickerSet.id; } else { return; } @@ -3094,7 +3092,7 @@ void StickersListWidget::displaySet(uint64 setId) { if (it != sets.cend()) { _displayingSet = true; checkHideWithBox(controller()->show( - Box(controller(), it->second->mtpInput()), + Box(controller(), it->second->identifier()), Ui::LayerOption::KeepOther).data()); } } @@ -3160,8 +3158,8 @@ void StickersListWidget::removeMegagroupSet(bool locally) { controller()->show(Box(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] { Expects(group->mgInfo != nullptr); - if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) { - session().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty()); + if (group->mgInfo->stickerSet) { + session().api().setGroupStickerSet(group, {}); } Ui::hideLayer(); _removingSetId = 0; diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index ad5a8caa0..f8148f91a 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -70,7 +70,7 @@ bool ShowStickerSet( Core::App().hideMediaView(); controller->show(Box( controller, - MTP_inputStickerSetShortName(MTP_string(match->captured(1))))); + StickerSetIdentifier{ .shortName = match->captured(1) })); return true; } diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 7acad65d5..e3d3eacec 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -868,15 +868,14 @@ void ApplyChannelUpdate( const auto stickerSet = update.vstickerset(); const auto set = stickerSet ? &stickerSet->c_stickerSet() : nullptr; const auto newSetId = (set ? set->vid().v : 0); - const auto oldSetId = (channel->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) - ? channel->mgInfo->stickerSet.c_inputStickerSetID().vid().v - : 0; + const auto oldSetId = channel->mgInfo->stickerSet.id; const auto stickersChanged = (canEditStickers != channel->canEditStickers()) || (oldSetId != newSetId); if (oldSetId != newSetId) { - channel->mgInfo->stickerSet = set - ? MTP_inputStickerSetID(set->vid(), set->vaccess_hash()) - : MTP_inputStickerSetEmpty(); + channel->mgInfo->stickerSet = StickerSetIdentifier{ + .id = set ? set->vid().v : 0, + .accessHash = set ? set->vaccess_hash().v : 0, + }; } if (stickersChanged) { session->changes().peerUpdated(channel, UpdateFlag::StickersSet); diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index a08e34b09..abe9e0bec 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -100,7 +100,7 @@ public: QString creatorRank; int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other bool joinedMessageFound = false; - MTPInputStickerSet stickerSet = MTP_inputStickerSetEmpty(); + StickerSetIdentifier stickerSet; enum LastParticipantsStatus { LastParticipantsUpToDate = 0x00, diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 5de2b3388..8b5a91be1 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -257,12 +257,10 @@ QString DocumentFileNameForSave( } Data::FileOrigin StickerData::setOrigin() const { - return set.match([&](const MTPDinputStickerSetID &data) { - return Data::FileOrigin( - Data::FileOriginStickerSet(data.vid().v, data.vaccess_hash().v)); - }, [&](const auto &) { - return Data::FileOrigin(); - }); + return set.id + ? Data::FileOrigin( + Data::FileOriginStickerSet(set.id, set.accessHash)) + : Data::FileOrigin(); } VoiceData::~VoiceData() { @@ -320,9 +318,21 @@ void DocumentData::setattributes( } if (sticker()) { sticker()->alt = qs(data.valt()); - if (sticker()->set.type() != mtpc_inputStickerSetID + if (!sticker()->set.id || data.vstickerset().type() == mtpc_inputStickerSetID) { - sticker()->set = data.vstickerset(); + sticker()->set = data.vstickerset().match([&]( + const MTPDinputStickerSetID &data) { + return StickerSetIdentifier{ + .id = data.vid().v, + .accessHash = data.vaccess_hash().v, + }; + }, [&](const MTPDinputStickerSetShortName &data) { + return StickerSetIdentifier{ + .shortName = qs(data.vshort_name()), + }; + }, [](const auto &) { + return StickerSetIdentifier(); + }); } } }, [&](const MTPDdocumentAttributeVideo &data) { @@ -1042,13 +1052,13 @@ bool DocumentData::isStickerSetInstalled() const { Expects(sticker() != nullptr); const auto &sets = _owner->stickers().sets(); - return sticker()->set.match([&](const MTPDinputStickerSetID &data) { - const auto i = sets.find(data.vid().v); + if (const auto id = sticker()->set.id) { + const auto i = sets.find(id); return (i != sets.cend()) && !(i->second->flags & MTPDstickerSet::Flag::f_archived) && (i->second->flags & MTPDstickerSet::Flag::f_installed_date); - }, [&](const MTPDinputStickerSetShortName &data) { - const auto name = qs(data.vshort_name()).toLower(); + } else if (!sticker()->set.shortName.isEmpty()) { + const auto name = sticker()->set.shortName.toLower(); for (const auto &[id, set] : sets) { if (set->shortName.toLower() == name) { return !(set->flags & MTPDstickerSet::Flag::f_archived) @@ -1056,13 +1066,9 @@ bool DocumentData::isStickerSetInstalled() const { } } return false; - }, [](const MTPDinputStickerSetEmpty &) { + } else { return false; - }, [](const MTPDinputStickerSetAnimatedEmoji &) { - return false; - }, [](const MTPDinputStickerSetDice &) { - return false; - }); + } } Image *DocumentData::getReplyPreview(Data::FileOrigin origin) { diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index cd3e89187..09d7ec121 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -62,7 +62,7 @@ struct StickerData : public DocumentAdditionalData { bool animated = false; QString alt; - MTPInputStickerSet set = MTP_inputStickerSetEmpty(); + StickerSetIdentifier set; }; struct SongData : public DocumentAdditionalData { diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index 602a65f28..2745afd0b 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -351,3 +351,16 @@ inline bool operator!=( const MessageCursor &b) { return !(a == b); } + +struct StickerSetIdentifier { + uint64 id = 0; + uint64 accessHash = 0; + QString shortName; + + [[nodiscard]] bool empty() const { + return !id && shortName.isEmpty(); + } + [[nodiscard]] explicit operator bool() const { + return !empty(); + } +}; diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index 7aedbf08a..f0e75e0bd 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -111,8 +111,7 @@ rpl::producer Stickers::stickerSetInstalled() const { } void Stickers::incrementSticker(not_null document) { - if (!document->sticker() - || document->sticker()->set.type() == mtpc_inputStickerSetEmpty) { + if (!document->sticker() || !document->sticker()->set) { return; } @@ -555,7 +554,7 @@ void Stickers::requestSetToPushFaved(not_null document) { setIsFaved(document, std::move(list)); }; session().api().request(MTPmessages_GetStickerSet( - document->sticker()->set + Data::InputStickerSet(document->sticker()->set) )).done([=](const MTPmessages_StickerSet &result) { Expects(result.type() == mtpc_messages_stickerSet); @@ -1060,9 +1059,8 @@ std::vector> Stickers::getListByEmoji( Expects(document->sticker() != nullptr); const auto sticker = document->sticker(); - if (sticker->set.type() == mtpc_inputStickerSetID) { - const auto setId = sticker->set.c_inputStickerSetID().vid().v; - const auto setIt = sets.find(setId); + if (sticker->set.id) { + const auto setIt = sets.find(sticker->set.id); if (setIt != sets.end()) { return InstallDateAdjusted(setIt->second->installDate, document); } @@ -1170,11 +1168,11 @@ std::optional>> Stickers::getEmojiListFromSet( not_null document) { if (auto sticker = document->sticker()) { auto &inputSet = sticker->set; - if (inputSet.type() != mtpc_inputStickerSetID) { + if (!inputSet.id) { return std::nullopt; } const auto &sets = this->sets(); - auto it = sets.find(inputSet.c_inputStickerSetID().vid().v); + auto it = sets.find(inputSet.id); if (it == sets.cend()) { return std::nullopt; } @@ -1289,9 +1287,7 @@ StickersSet *Stickers::feedSetFull(const MTPmessages_StickerSet &data) { const auto &d_docs = d.vdocuments().v; auto customIt = sets.find(Stickers::CustomSetId); - const auto inputSet = MTP_inputStickerSetID( - MTP_long(set->id), - MTP_long(set->access)); + const auto inputSet = set->identifier(); auto pack = StickersPack(); pack.reserve(d_docs.size()); @@ -1300,7 +1296,7 @@ StickersSet *Stickers::feedSetFull(const MTPmessages_StickerSet &data) { if (!document->sticker()) continue; pack.push_back(document); - if (document->sticker()->set.type() != mtpc_inputStickerSetID) { + if (!document->sticker()->set.id) { document->sticker()->set = inputSet; } if (customIt != sets.cend()) { diff --git a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp index f9444cbb1..cc076720c 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp @@ -80,6 +80,13 @@ MTPInputStickerSet StickersSet::mtpInput() const { : MTP_inputStickerSetShortName(MTP_string(shortName)); } +StickerSetIdentifier StickersSet::identifier() const { + return StickerSetIdentifier{ + .id = id, + .accessHash = access, + }; +} + void StickersSet::setThumbnail(const ImageWithLocation &data) { Data::UpdateCloudFile( _thumbnail, @@ -154,4 +161,25 @@ std::shared_ptr StickersSet::activeThumbnailView() { return _thumbnailView.lock(); } +MTPInputStickerSet InputStickerSet(StickerSetIdentifier id) { + return !id + ? MTP_inputStickerSetEmpty() + : id.id + ? MTP_inputStickerSetID(MTP_long(id.id), MTP_long(id.accessHash)) + : MTP_inputStickerSetShortName(MTP_string(id.shortName)); +} + +StickerSetIdentifier FromInputSet(const MTPInputStickerSet &id) { + return id.match([](const MTPDinputStickerSetID &data) { + return StickerSetIdentifier{ + .id = data.vid().v, + .accessHash = data.vaccess_hash().v, + }; + }, [](const MTPDinputStickerSetShortName &data) { + return StickerSetIdentifier{ .shortName = qs(data.vshort_name()) }; + }, [](const auto &) { + return StickerSetIdentifier(); + }); +} + } // namespace Stickers diff --git a/Telegram/SourceFiles/data/stickers/data_stickers_set.h b/Telegram/SourceFiles/data/stickers/data_stickers_set.h index cb4249c54..8a1dd1ad9 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers_set.h +++ b/Telegram/SourceFiles/data/stickers/data_stickers_set.h @@ -62,6 +62,7 @@ public: [[nodiscard]] Main::Session &session() const; [[nodiscard]] MTPInputStickerSet mtpInput() const; + [[nodiscard]] StickerSetIdentifier identifier() const; void setThumbnail(const ImageWithLocation &data); @@ -95,4 +96,7 @@ private: }; -} // namespace Stickers +[[nodiscard]] MTPInputStickerSet InputStickerSet(StickerSetIdentifier id); +[[nodiscard]] StickerSetIdentifier FromInputSet(const MTPInputStickerSet &id); + +} // namespace Data diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 6ec80aad1..7e17645fd 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -818,7 +818,7 @@ void GenerateItems( auto setLink = std::make_shared([set] { Ui::show(Box( App::wnd()->sessionController(), - set)); + Data::FromInputSet(set))); }); auto message = HistoryService::PreparedText { text }; message.links.push_back(fromLink); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 113161c7e..c94c82e94 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1769,7 +1769,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { const auto mediaHasTextForCopy = media && media->hasTextForCopy(); if (const auto document = media ? media->getDocument() : nullptr) { if (!item->isIsolatedEmoji() && document->sticker()) { - if (document->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + if (document->sticker()->set) { _menu->addAction(document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) : tr::lng_context_pack_add(tr::now), [=] { showStickerPackInfo(document); }); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 301d10f9b..8dfdc0afb 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -230,8 +230,7 @@ void AddDocumentActions( }); } } - if (document->sticker() - && document->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + if (document->sticker() && document->sticker()->set) { menu->addAction( (document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index c990234ed..db1b4590f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -291,7 +291,7 @@ void Sticker::refreshLink() { that->_parent->history()->owner().requestViewRepaint( that->_parent); }); - } else if (sticker && sticker->set.type() != mtpc_inputStickerSetEmpty) { + } else if (sticker && sticker->set) { _link = std::make_shared([document = _data](ClickContext context) { const auto my = context.other.value(); if (const auto window = my.sessionWindow.get()) { diff --git a/Telegram/SourceFiles/storage/serialize_document.cpp b/Telegram/SourceFiles/storage/serialize_document.cpp index 11cc511ed..4492b7bf6 100644 --- a/Telegram/SourceFiles/storage/serialize_document.cpp +++ b/Telegram/SourceFiles/storage/serialize_document.cpp @@ -34,19 +34,14 @@ void Document::writeToStream(QDataStream &stream, DocumentData *document) { stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size); stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height()); stream << qint32(document->type); - if (auto sticker = document->sticker()) { + if (const auto sticker = document->sticker()) { stream << document->sticker()->alt; - switch (document->sticker()->set.type()) { - case mtpc_inputStickerSetID: { + if (document->sticker()->set.id) { stream << qint32(StickerSetTypeID); - } break; - case mtpc_inputStickerSetShortName: { + } else if (!document->sticker()->set.shortName.isEmpty()) { stream << qint32(StickerSetTypeShortName); - } break; - case mtpc_inputStickerSetEmpty: - default: { + } else { stream << qint32(StickerSetTypeEmpty); - } break; } } else { stream << qint32(document->getDuration()); diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 160013062..a750cca59 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -1750,7 +1750,7 @@ void Account::readStickerSets( ImageWithLocation{ .location = setThumbnail }); } const auto set = it->second.get(); - auto inputSet = MTP_inputStickerSetID(MTP_long(set->id), MTP_long(set->access)); + const auto inputSet = set->identifier(); const auto fillStickers = set->stickers.isEmpty(); if (scnt < 0) { // disabled not loaded set @@ -1783,7 +1783,7 @@ void Account::readStickerSets( if (fillStickers) { set->stickers.push_back(document); if (!(set->flags & MTPDstickerSet_ClientFlag::f_special)) { - if (document->sticker()->set.type() != mtpc_inputStickerSetID) { + if (!document->sticker()->set.id) { document->sticker()->set = inputSet; } }