Don't store MTPInputStickerSet in data.

This commit is contained in:
John Preston 2021-07-08 19:42:57 +03:00
parent 9dfb43d525
commit 75090dedaa
23 changed files with 152 additions and 119 deletions

View File

@ -52,8 +52,10 @@ void AttachedStickers::request(
}); });
const auto setId = (setData->vid().v && setData->vaccess_hash().v) const auto setId = (setData->vid().v && setData->vaccess_hash().v)
? MTP_inputStickerSetID(setData->vid(), setData->vaccess_hash()) ? StickerSetIdentifier{
: MTP_inputStickerSetShortName(setData->vshort_name()); .id = setData->vid().v,
.accessHash = setData->vaccess_hash().v }
: StickerSetIdentifier{ .shortName = qs(setData->vshort_name()) };
strongController->show( strongController->show(
Box<StickerSetBox>(strongController, setId), Box<StickerSetBox>(strongController, setId),
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_media.h" #include "api/api_media.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/stickers/data_stickers_set.h"
#include "history/history_item.h" #include "history/history_item.h"
namespace Api { namespace Api {
@ -47,7 +48,7 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
attributes.push_back(MTP_documentAttributeSticker( attributes.push_back(MTP_documentAttributeSticker(
MTP_flags(0), MTP_flags(0),
MTP_string(document->sticker()->alt), MTP_string(document->sticker()->alt),
document->sticker()->set, Data::InputStickerSet(document->sticker()->set),
MTPMaskCoords())); MTPMaskCoords()));
} else if (const auto song = document->song()) { } else if (const auto song = document->song()) {
const auto flags = MTPDdocumentAttributeAudio::Flag::f_title const auto flags = MTPDdocumentAttributeAudio::Flag::f_title

View File

@ -3028,11 +3028,16 @@ void ApiWrap::requestRecentStickersForce(bool attached) {
requestRecentStickersWithHash(0, attached); requestRecentStickersWithHash(0, attached);
} }
void ApiWrap::setGroupStickerSet(not_null<ChannelData*> megagroup, const MTPInputStickerSet &set) { void ApiWrap::setGroupStickerSet(
not_null<ChannelData*> megagroup,
const StickerSetIdentifier &set) {
Expects(megagroup->mgInfo != nullptr); Expects(megagroup->mgInfo != nullptr);
megagroup->mgInfo->stickerSet = set; megagroup->mgInfo->stickerSet = set;
request(MTPchannels_SetStickers(megagroup->inputChannel, set)).send(); request(MTPchannels_SetStickers(
megagroup->inputChannel,
Data::InputStickerSet(set)
)).send();
_session->data().stickers().notifyUpdated(); _session->data().stickers().notifyUpdated();
} }

View File

@ -288,7 +288,7 @@ public:
void requestRecentStickersForce(bool attached = false); void requestRecentStickersForce(bool attached = false);
void setGroupStickerSet( void setGroupStickerSet(
not_null<ChannelData*> megagroup, not_null<ChannelData*> megagroup,
const MTPInputStickerSet &set); const StickerSetIdentifier &set);
std::vector<not_null<DocumentData*>> *stickersByEmoji( std::vector<not_null<DocumentData*>> *stickersByEmoji(
not_null<EmojiPtr> emoji); not_null<EmojiPtr> emoji);

View File

@ -59,7 +59,7 @@ public:
Inner( Inner(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const MTPInputStickerSet &set); const StickerSetIdentifier &set);
bool loaded() const; bool loaded() const;
bool notInstalled() const; bool notInstalled() const;
@ -134,7 +134,7 @@ private:
const std::unique_ptr<Ui::PathShiftGradient> _pathGradient; const std::unique_ptr<Ui::PathShiftGradient> _pathGradient;
MTPInputStickerSet _input; StickerSetIdentifier _input;
mtpRequestId _installRequest = 0; mtpRequestId _installRequest = 0;
@ -153,7 +153,7 @@ private:
StickerSetBox::StickerSetBox( StickerSetBox::StickerSetBox(
QWidget*, QWidget*,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const MTPInputStickerSet &set) const StickerSetIdentifier &set)
: _controller(controller) : _controller(controller)
, _set(set) { , _set(set) {
} }
@ -162,7 +162,7 @@ QPointer<Ui::BoxContent> StickerSetBox::Show(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<DocumentData*> document) { not_null<DocumentData*> document) {
if (const auto sticker = document->sticker()) { if (const auto sticker = document->sticker()) {
if (sticker->set.type() != mtpc_inputStickerSetEmpty) { if (sticker->set) {
return controller->show( return controller->show(
Box<StickerSetBox>(controller, sticker->set), Box<StickerSetBox>(controller, sticker->set),
Ui::LayerOption::KeepOther).data(); Ui::LayerOption::KeepOther).data();
@ -344,28 +344,21 @@ void StickerSetBox::resizeEvent(QResizeEvent *e) {
StickerSetBox::Inner::Inner( StickerSetBox::Inner::Inner(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const MTPInputStickerSet &set) const StickerSetIdentifier &set)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller) , _controller(controller)
, _api(&_controller->session().mtp()) , _api(&_controller->session().mtp())
, _setId(set.id)
, _setAccess(set.accessHash)
, _setShortName(set.shortName)
, _pathGradient(std::make_unique<Ui::PathShiftGradient>( , _pathGradient(std::make_unique<Ui::PathShiftGradient>(
st::windowBgRipple, st::windowBgRipple,
st::windowBgOver, st::windowBgOver,
[=] { update(); })) [=] { update(); }))
, _input(set) , _input(set)
, _previewTimer([=] { showPreview(); }) { , _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( _api.request(MTPmessages_GetStickerSet(
_input Data::InputStickerSet(_input)
)).done([=](const MTPmessages_StickerSet &result) { )).done([=](const MTPmessages_StickerSet &result) {
gotSet(result); gotSet(result);
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
@ -881,7 +874,7 @@ void StickerSetBox::Inner::install() {
return; return;
} }
_installRequest = _api.request(MTPmessages_InstallStickerSet( _installRequest = _api.request(MTPmessages_InstallStickerSet(
_input, Data::InputStickerSet(_input),
MTP_bool(false) MTP_bool(false)
)).done([=](const MTPmessages_StickerSetInstallResult &result) { )).done([=](const MTPmessages_StickerSetInstallResult &result) {
installDone(result); installDone(result);
@ -892,7 +885,7 @@ void StickerSetBox::Inner::install() {
void StickerSetBox::Inner::archiveStickers() { void StickerSetBox::Inner::archiveStickers() {
_api.request(MTPmessages_InstallStickerSet( _api.request(MTPmessages_InstallStickerSet(
_input, Data::InputStickerSet(_input),
MTP_boolTrue() MTP_boolTrue()
)).done([=](const MTPmessages_StickerSetInstallResult &result) { )).done([=](const MTPmessages_StickerSetInstallResult &result) {
if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) {

View File

@ -26,7 +26,7 @@ public:
StickerSetBox( StickerSetBox(
QWidget*, QWidget*,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
const MTPInputStickerSet &set); const StickerSetIdentifier &set);
static QPointer<Ui::BoxContent> Show( static QPointer<Ui::BoxContent> Show(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
@ -49,7 +49,7 @@ private:
void handleError(Error error); void handleError(Error error);
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
MTPInputStickerSet _set; const StickerSetIdentifier _set;
class Inner; class Inner;
QPointer<Inner> _inner; QPointer<Inner> _inner;

View File

@ -233,7 +233,7 @@ private:
void rebuildMegagroupSet(); void rebuildMegagroupSet();
void fixupMegagroupSetAddress(); void fixupMegagroupSetAddress();
void handleMegagroupSetAddressChange(); void handleMegagroupSetAddressChange();
void setMegagroupSelectedSet(const MTPInputStickerSet &set); void setMegagroupSelectedSet(const StickerSetIdentifier &set);
int countMaxNameWidth() const; int countMaxNameWidth() const;
@ -284,7 +284,7 @@ private:
int _scrollbar = 0; int _scrollbar = 0;
ChannelData *_megagroupSet = nullptr; ChannelData *_megagroupSet = nullptr;
MTPInputStickerSet _megagroupSetInput = MTP_inputStickerSetEmpty(); StickerSetIdentifier _megagroupSetInput;
std::unique_ptr<Row> _megagroupSelectedSet; std::unique_ptr<Row> _megagroupSelectedSet;
object_ptr<AddressField> _megagroupSetField = { nullptr }; object_ptr<AddressField> _megagroupSetField = { nullptr };
object_ptr<Ui::PlainShadow> _megagroupSelectedShadow = { nullptr }; object_ptr<Ui::PlainShadow> _megagroupSelectedShadow = { nullptr };
@ -1713,14 +1713,14 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
const auto showSetByRow = [&](const Row &row) { const auto showSetByRow = [&](const Row &row) {
setSelected(SelectedRow()); setSelected(SelectedRow());
_controller->show( _controller->show(
Box<StickerSetBox>(_controller, row.set->mtpInput()), Box<StickerSetBox>(_controller, row.set->identifier()),
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
}; };
if (selectedIndex >= 0 && !_inDragArea) { if (selectedIndex >= 0 && !_inDragArea) {
const auto row = _rows[selectedIndex].get(); const auto row = _rows[selectedIndex].get();
if (!row->isRecentSet()) { if (!row->isRecentSet()) {
if (_megagroupSet) { if (_megagroupSet) {
setMegagroupSelectedSet(row->set->mtpInput()); setMegagroupSelectedSet(row->set->identifier());
} else { } else {
showSetByRow(*row); showSetByRow(*row);
} }
@ -1735,12 +1735,8 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
void StickersBox::Inner::saveGroupSet() { void StickersBox::Inner::saveGroupSet() {
Expects(_megagroupSet != nullptr); Expects(_megagroupSet != nullptr);
auto oldId = (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) auto oldId = _megagroupSet->mgInfo->stickerSet.id;
? _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v auto newId = _megagroupSetInput.id;
: 0;
auto newId = (_megagroupSetInput.type() == mtpc_inputStickerSetID)
? _megagroupSetInput.c_inputStickerSetID().vid().v
: 0;
if (newId != oldId) { if (newId != oldId) {
session().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput); session().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput);
session().data().stickers().notifyStickerSetInstalled( session().data().stickers().notifyStickerSetInstalled(
@ -1877,7 +1873,7 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() {
const auto &sets = session().data().stickers().sets(); const auto &sets = session().data().stickers().sets();
const auto it = sets.find(_megagroupSelectedSet->set->id); const auto it = sets.find(_megagroupSelectedSet->set->id);
if (it != sets.cend() && !it->second->shortName.isEmpty()) { if (it != sets.cend() && !it->second->shortName.isEmpty()) {
setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); setMegagroupSelectedSet({});
} }
} }
} else if (!_megagroupSetRequestId) { } else if (!_megagroupSetRequestId) {
@ -1886,12 +1882,10 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() {
)).done([=](const MTPmessages_StickerSet &result) { )).done([=](const MTPmessages_StickerSet &result) {
_megagroupSetRequestId = 0; _megagroupSetRequestId = 0;
auto set = session().data().stickers().feedSetFull(result); auto set = session().data().stickers().feedSetFull(result);
setMegagroupSelectedSet(MTP_inputStickerSetID( setMegagroupSelectedSet(set->identifier());
MTP_long(set->id),
MTP_long(set->access)));
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
_megagroupSetRequestId = 0; _megagroupSetRequestId = 0;
setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); setMegagroupSelectedSet({});
}).send(); }).send();
} else { } else {
_megagroupSetAddressChangedTimer.callOnce(kHandleMegagroupSetAddressChangeTimeout); _megagroupSetAddressChangedTimer.callOnce(kHandleMegagroupSetAddressChangeTimeout);
@ -1900,7 +1894,8 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() {
void StickersBox::Inner::rebuildMegagroupSet() { void StickersBox::Inner::rebuildMegagroupSet() {
Expects(_megagroupSet != nullptr); Expects(_megagroupSet != nullptr);
if (_megagroupSetInput.type() != mtpc_inputStickerSetID) {
if (!_megagroupSetInput.id) {
if (_megagroupSelectedSet) { if (_megagroupSelectedSet) {
_megagroupSetField->setText(QString()); _megagroupSetField->setText(QString());
_megagroupSetField->finishAnimating(); _megagroupSetField->finishAnimating();
@ -1910,15 +1905,14 @@ void StickersBox::Inner::rebuildMegagroupSet() {
_megagroupSelectedShadow.destroy(); _megagroupSelectedShadow.destroy();
return; return;
} }
auto &inputId = _megagroupSetInput.c_inputStickerSetID(); auto setId = _megagroupSetInput.id;
auto setId = inputId.vid().v;
const auto &sets = session().data().stickers().sets(); const auto &sets = session().data().stickers().sets();
auto it = sets.find(setId); auto it = sets.find(setId);
if (it == sets.cend() if (it == sets.cend()
|| (it->second->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) { || (it->second->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
session().api().scheduleStickerSetRequest( session().api().scheduleStickerSetRequest(
inputId.vid().v, _megagroupSetInput.id,
inputId.vaccess_hash().v); _megagroupSetInput.accessHash);
return; return;
} }
@ -1954,7 +1948,7 @@ void StickersBox::Inner::rebuildMegagroupSet() {
_megagroupSelectedRemove.create(this, st::groupStickersRemove); _megagroupSelectedRemove.create(this, st::groupStickersRemove);
_megagroupSelectedRemove->show(anim::type::instant); _megagroupSelectedRemove->show(anim::type::instant);
_megagroupSelectedRemove->setClickedCallback([this] { _megagroupSelectedRemove->setClickedCallback([this] {
setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); setMegagroupSelectedSet({});
}); });
_megagroupSelectedShadow.create(this); _megagroupSelectedShadow.create(this);
updateControlsGeometry(); updateControlsGeometry();
@ -2025,7 +2019,7 @@ void StickersBox::Inner::rebuild(bool masks) {
updateSize(); updateSize();
} }
void StickersBox::Inner::setMegagroupSelectedSet(const MTPInputStickerSet &set) { void StickersBox::Inner::setMegagroupSelectedSet(const StickerSetIdentifier &set) {
_megagroupSetInput = set; _megagroupSetInput = set;
rebuild(false); rebuild(false);
_scrollsToY.fire(0); _scrollsToY.fire(0);

View File

@ -2134,8 +2134,7 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const {
} }
void StickersListWidget::showStickerSetBox(not_null<DocumentData*> document) { void StickersListWidget::showStickerSetBox(not_null<DocumentData*> document) {
if (document->sticker() if (document->sticker() && document->sticker()->set) {
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
_displayingSet = true; _displayingSet = true;
checkHideWithBox(StickerSetBox::Show(controller(), document)); checkHideWithBox(StickerSetBox::Show(controller(), document));
} }
@ -2714,7 +2713,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
auto isShownHere = [place](bool hidden) { auto isShownHere = [place](bool hidden) {
return (hidden == (place == GroupStickersPlace::Hidden)); return (hidden == (place == GroupStickersPlace::Hidden));
}; };
if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) { if (!_megagroupSet->mgInfo->stickerSet) {
if (canEdit) { if (canEdit) {
auto hidden = session().settings().isGroupStickersSectionHidden( auto hidden = session().settings().isGroupStickersSectionHidden(
_megagroupSet->id); _megagroupSet->id);
@ -2745,12 +2744,12 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
if (canEdit && hidden) { if (canEdit && hidden) {
removeHiddenForGroup(); removeHiddenForGroup();
} }
if (_megagroupSet->mgInfo->stickerSet.type() != mtpc_inputStickerSetID) { const auto &set = _megagroupSet->mgInfo->stickerSet;
if (!set.id) {
return; return;
} }
auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID();
const auto &sets = session().data().stickers().sets(); 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()) { if (it != sets.cend()) {
const auto set = it->second.get(); const auto set = it->second.get();
auto isInstalled = (set->flags & MTPDstickerSet::Flag::f_installed_date) auto isInstalled = (set->flags & MTPDstickerSet::Flag::f_installed_date)
@ -2771,13 +2770,12 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
PrepareStickers(set->stickers)); PrepareStickers(set->stickers));
} }
return; return;
} else if (!isShownHere(hidden) } else if (!isShownHere(hidden) || _megagroupSetIdRequested == set.id) {
|| _megagroupSetIdRequested == set.vid().v) {
return; return;
} }
_megagroupSetIdRequested = set.vid().v; _megagroupSetIdRequested = set.id;
_api.request(MTPmessages_GetStickerSet( _api.request(MTPmessages_GetStickerSet(
_megagroupSet->mgInfo->stickerSet Data::InputStickerSet(set)
)).done([=](const MTPmessages_StickerSet &result) { )).done([=](const MTPmessages_StickerSet &result) {
if (const auto set = session().data().stickers().feedSetFull(result)) { if (const auto set = session().data().stickers().feedSetFull(result)) {
refreshStickers(); refreshStickers();
@ -3083,8 +3081,8 @@ void StickersListWidget::displaySet(uint64 setId) {
Box<StickersBox>(controller(), _megagroupSet), Box<StickersBox>(controller(), _megagroupSet),
Ui::LayerOption::KeepOther).data()); Ui::LayerOption::KeepOther).data());
return; return;
} else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) { } else if (_megagroupSet->mgInfo->stickerSet.id) {
setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v; setId = _megagroupSet->mgInfo->stickerSet.id;
} else { } else {
return; return;
} }
@ -3094,7 +3092,7 @@ void StickersListWidget::displaySet(uint64 setId) {
if (it != sets.cend()) { if (it != sets.cend()) {
_displayingSet = true; _displayingSet = true;
checkHideWithBox(controller()->show( checkHideWithBox(controller()->show(
Box<StickerSetBox>(controller(), it->second->mtpInput()), Box<StickerSetBox>(controller(), it->second->identifier()),
Ui::LayerOption::KeepOther).data()); Ui::LayerOption::KeepOther).data());
} }
} }
@ -3160,8 +3158,8 @@ void StickersListWidget::removeMegagroupSet(bool locally) {
controller()->show(Box<ConfirmBox>(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] { controller()->show(Box<ConfirmBox>(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] {
Expects(group->mgInfo != nullptr); Expects(group->mgInfo != nullptr);
if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) { if (group->mgInfo->stickerSet) {
session().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty()); session().api().setGroupStickerSet(group, {});
} }
Ui::hideLayer(); Ui::hideLayer();
_removingSetId = 0; _removingSetId = 0;

View File

@ -70,7 +70,7 @@ bool ShowStickerSet(
Core::App().hideMediaView(); Core::App().hideMediaView();
controller->show(Box<StickerSetBox>( controller->show(Box<StickerSetBox>(
controller, controller,
MTP_inputStickerSetShortName(MTP_string(match->captured(1))))); StickerSetIdentifier{ .shortName = match->captured(1) }));
return true; return true;
} }

View File

@ -868,15 +868,14 @@ void ApplyChannelUpdate(
const auto stickerSet = update.vstickerset(); const auto stickerSet = update.vstickerset();
const auto set = stickerSet ? &stickerSet->c_stickerSet() : nullptr; const auto set = stickerSet ? &stickerSet->c_stickerSet() : nullptr;
const auto newSetId = (set ? set->vid().v : 0); const auto newSetId = (set ? set->vid().v : 0);
const auto oldSetId = (channel->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) const auto oldSetId = channel->mgInfo->stickerSet.id;
? channel->mgInfo->stickerSet.c_inputStickerSetID().vid().v
: 0;
const auto stickersChanged = (canEditStickers != channel->canEditStickers()) const auto stickersChanged = (canEditStickers != channel->canEditStickers())
|| (oldSetId != newSetId); || (oldSetId != newSetId);
if (oldSetId != newSetId) { if (oldSetId != newSetId) {
channel->mgInfo->stickerSet = set channel->mgInfo->stickerSet = StickerSetIdentifier{
? MTP_inputStickerSetID(set->vid(), set->vaccess_hash()) .id = set ? set->vid().v : 0,
: MTP_inputStickerSetEmpty(); .accessHash = set ? set->vaccess_hash().v : 0,
};
} }
if (stickersChanged) { if (stickersChanged) {
session->changes().peerUpdated(channel, UpdateFlag::StickersSet); session->changes().peerUpdated(channel, UpdateFlag::StickersSet);

View File

@ -100,7 +100,7 @@ public:
QString creatorRank; QString creatorRank;
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
bool joinedMessageFound = false; bool joinedMessageFound = false;
MTPInputStickerSet stickerSet = MTP_inputStickerSetEmpty(); StickerSetIdentifier stickerSet;
enum LastParticipantsStatus { enum LastParticipantsStatus {
LastParticipantsUpToDate = 0x00, LastParticipantsUpToDate = 0x00,

View File

@ -257,12 +257,10 @@ QString DocumentFileNameForSave(
} }
Data::FileOrigin StickerData::setOrigin() const { Data::FileOrigin StickerData::setOrigin() const {
return set.match([&](const MTPDinputStickerSetID &data) { return set.id
return Data::FileOrigin( ? Data::FileOrigin(
Data::FileOriginStickerSet(data.vid().v, data.vaccess_hash().v)); Data::FileOriginStickerSet(set.id, set.accessHash))
}, [&](const auto &) { : Data::FileOrigin();
return Data::FileOrigin();
});
} }
VoiceData::~VoiceData() { VoiceData::~VoiceData() {
@ -320,9 +318,21 @@ void DocumentData::setattributes(
} }
if (sticker()) { if (sticker()) {
sticker()->alt = qs(data.valt()); sticker()->alt = qs(data.valt());
if (sticker()->set.type() != mtpc_inputStickerSetID if (!sticker()->set.id
|| data.vstickerset().type() == mtpc_inputStickerSetID) { || 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) { }, [&](const MTPDdocumentAttributeVideo &data) {
@ -1042,13 +1052,13 @@ bool DocumentData::isStickerSetInstalled() const {
Expects(sticker() != nullptr); Expects(sticker() != nullptr);
const auto &sets = _owner->stickers().sets(); const auto &sets = _owner->stickers().sets();
return sticker()->set.match([&](const MTPDinputStickerSetID &data) { if (const auto id = sticker()->set.id) {
const auto i = sets.find(data.vid().v); const auto i = sets.find(id);
return (i != sets.cend()) return (i != sets.cend())
&& !(i->second->flags & MTPDstickerSet::Flag::f_archived) && !(i->second->flags & MTPDstickerSet::Flag::f_archived)
&& (i->second->flags & MTPDstickerSet::Flag::f_installed_date); && (i->second->flags & MTPDstickerSet::Flag::f_installed_date);
}, [&](const MTPDinputStickerSetShortName &data) { } else if (!sticker()->set.shortName.isEmpty()) {
const auto name = qs(data.vshort_name()).toLower(); const auto name = sticker()->set.shortName.toLower();
for (const auto &[id, set] : sets) { for (const auto &[id, set] : sets) {
if (set->shortName.toLower() == name) { if (set->shortName.toLower() == name) {
return !(set->flags & MTPDstickerSet::Flag::f_archived) return !(set->flags & MTPDstickerSet::Flag::f_archived)
@ -1056,13 +1066,9 @@ bool DocumentData::isStickerSetInstalled() const {
} }
} }
return false; return false;
}, [](const MTPDinputStickerSetEmpty &) { } else {
return false; return false;
}, [](const MTPDinputStickerSetAnimatedEmoji &) { }
return false;
}, [](const MTPDinputStickerSetDice &) {
return false;
});
} }
Image *DocumentData::getReplyPreview(Data::FileOrigin origin) { Image *DocumentData::getReplyPreview(Data::FileOrigin origin) {

View File

@ -62,7 +62,7 @@ struct StickerData : public DocumentAdditionalData {
bool animated = false; bool animated = false;
QString alt; QString alt;
MTPInputStickerSet set = MTP_inputStickerSetEmpty(); StickerSetIdentifier set;
}; };
struct SongData : public DocumentAdditionalData { struct SongData : public DocumentAdditionalData {

View File

@ -351,3 +351,16 @@ inline bool operator!=(
const MessageCursor &b) { const MessageCursor &b) {
return !(a == 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();
}
};

View File

@ -111,8 +111,7 @@ rpl::producer<uint64> Stickers::stickerSetInstalled() const {
} }
void Stickers::incrementSticker(not_null<DocumentData*> document) { void Stickers::incrementSticker(not_null<DocumentData*> document) {
if (!document->sticker() if (!document->sticker() || !document->sticker()->set) {
|| document->sticker()->set.type() == mtpc_inputStickerSetEmpty) {
return; return;
} }
@ -555,7 +554,7 @@ void Stickers::requestSetToPushFaved(not_null<DocumentData*> document) {
setIsFaved(document, std::move(list)); setIsFaved(document, std::move(list));
}; };
session().api().request(MTPmessages_GetStickerSet( session().api().request(MTPmessages_GetStickerSet(
document->sticker()->set Data::InputStickerSet(document->sticker()->set)
)).done([=](const MTPmessages_StickerSet &result) { )).done([=](const MTPmessages_StickerSet &result) {
Expects(result.type() == mtpc_messages_stickerSet); Expects(result.type() == mtpc_messages_stickerSet);
@ -1060,9 +1059,8 @@ std::vector<not_null<DocumentData*>> Stickers::getListByEmoji(
Expects(document->sticker() != nullptr); Expects(document->sticker() != nullptr);
const auto sticker = document->sticker(); const auto sticker = document->sticker();
if (sticker->set.type() == mtpc_inputStickerSetID) { if (sticker->set.id) {
const auto setId = sticker->set.c_inputStickerSetID().vid().v; const auto setIt = sets.find(sticker->set.id);
const auto setIt = sets.find(setId);
if (setIt != sets.end()) { if (setIt != sets.end()) {
return InstallDateAdjusted(setIt->second->installDate, document); return InstallDateAdjusted(setIt->second->installDate, document);
} }
@ -1170,11 +1168,11 @@ std::optional<std::vector<not_null<EmojiPtr>>> Stickers::getEmojiListFromSet(
not_null<DocumentData*> document) { 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.id) {
return std::nullopt; return std::nullopt;
} }
const auto &sets = this->sets(); const auto &sets = this->sets();
auto it = sets.find(inputSet.c_inputStickerSetID().vid().v); auto it = sets.find(inputSet.id);
if (it == sets.cend()) { if (it == sets.cend()) {
return std::nullopt; return std::nullopt;
} }
@ -1289,9 +1287,7 @@ StickersSet *Stickers::feedSetFull(const MTPmessages_StickerSet &data) {
const auto &d_docs = d.vdocuments().v; const auto &d_docs = d.vdocuments().v;
auto customIt = sets.find(Stickers::CustomSetId); auto customIt = sets.find(Stickers::CustomSetId);
const auto inputSet = MTP_inputStickerSetID( const auto inputSet = set->identifier();
MTP_long(set->id),
MTP_long(set->access));
auto pack = StickersPack(); auto pack = StickersPack();
pack.reserve(d_docs.size()); pack.reserve(d_docs.size());
@ -1300,7 +1296,7 @@ StickersSet *Stickers::feedSetFull(const MTPmessages_StickerSet &data) {
if (!document->sticker()) continue; if (!document->sticker()) continue;
pack.push_back(document); pack.push_back(document);
if (document->sticker()->set.type() != mtpc_inputStickerSetID) { if (!document->sticker()->set.id) {
document->sticker()->set = inputSet; document->sticker()->set = inputSet;
} }
if (customIt != sets.cend()) { if (customIt != sets.cend()) {

View File

@ -80,6 +80,13 @@ MTPInputStickerSet StickersSet::mtpInput() const {
: MTP_inputStickerSetShortName(MTP_string(shortName)); : MTP_inputStickerSetShortName(MTP_string(shortName));
} }
StickerSetIdentifier StickersSet::identifier() const {
return StickerSetIdentifier{
.id = id,
.accessHash = access,
};
}
void StickersSet::setThumbnail(const ImageWithLocation &data) { void StickersSet::setThumbnail(const ImageWithLocation &data) {
Data::UpdateCloudFile( Data::UpdateCloudFile(
_thumbnail, _thumbnail,
@ -154,4 +161,25 @@ std::shared_ptr<StickersSetThumbnailView> StickersSet::activeThumbnailView() {
return _thumbnailView.lock(); 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 } // namespace Stickers

View File

@ -62,6 +62,7 @@ public:
[[nodiscard]] Main::Session &session() const; [[nodiscard]] Main::Session &session() const;
[[nodiscard]] MTPInputStickerSet mtpInput() const; [[nodiscard]] MTPInputStickerSet mtpInput() const;
[[nodiscard]] StickerSetIdentifier identifier() const;
void setThumbnail(const ImageWithLocation &data); 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

View File

@ -818,7 +818,7 @@ void GenerateItems(
auto setLink = std::make_shared<LambdaClickHandler>([set] { auto setLink = std::make_shared<LambdaClickHandler>([set] {
Ui::show(Box<StickerSetBox>( Ui::show(Box<StickerSetBox>(
App::wnd()->sessionController(), App::wnd()->sessionController(),
set)); Data::FromInputSet(set)));
}); });
auto message = HistoryService::PreparedText { text }; auto message = HistoryService::PreparedText { text };
message.links.push_back(fromLink); message.links.push_back(fromLink);

View File

@ -1769,7 +1769,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
const auto mediaHasTextForCopy = media && media->hasTextForCopy(); const auto mediaHasTextForCopy = media && media->hasTextForCopy();
if (const auto document = media ? media->getDocument() : nullptr) { if (const auto document = media ? media->getDocument() : nullptr) {
if (!item->isIsolatedEmoji() && document->sticker()) { 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), [=] { _menu->addAction(document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) : tr::lng_context_pack_add(tr::now), [=] {
showStickerPackInfo(document); showStickerPackInfo(document);
}); });

View File

@ -230,8 +230,7 @@ void AddDocumentActions(
}); });
} }
} }
if (document->sticker() if (document->sticker() && document->sticker()->set) {
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
menu->addAction( menu->addAction(
(document->isStickerSetInstalled() (document->isStickerSetInstalled()
? tr::lng_context_pack_info(tr::now) ? tr::lng_context_pack_info(tr::now)

View File

@ -291,7 +291,7 @@ void Sticker::refreshLink() {
that->_parent->history()->owner().requestViewRepaint( that->_parent->history()->owner().requestViewRepaint(
that->_parent); that->_parent);
}); });
} else if (sticker && sticker->set.type() != mtpc_inputStickerSetEmpty) { } else if (sticker && sticker->set) {
_link = std::make_shared<LambdaClickHandler>([document = _data](ClickContext context) { _link = std::make_shared<LambdaClickHandler>([document = _data](ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>(); const auto my = context.other.value<ClickHandlerContext>();
if (const auto window = my.sessionWindow.get()) { if (const auto window = my.sessionWindow.get()) {

View File

@ -34,19 +34,14 @@ void Document::writeToStream(QDataStream &stream, DocumentData *document) {
stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size); stream << document->filename() << document->mimeString() << qint32(document->_dc) << qint32(document->size);
stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height()); stream << qint32(document->dimensions.width()) << qint32(document->dimensions.height());
stream << qint32(document->type); stream << qint32(document->type);
if (auto sticker = document->sticker()) { if (const auto sticker = document->sticker()) {
stream << document->sticker()->alt; stream << document->sticker()->alt;
switch (document->sticker()->set.type()) { if (document->sticker()->set.id) {
case mtpc_inputStickerSetID: {
stream << qint32(StickerSetTypeID); stream << qint32(StickerSetTypeID);
} break; } else if (!document->sticker()->set.shortName.isEmpty()) {
case mtpc_inputStickerSetShortName: {
stream << qint32(StickerSetTypeShortName); stream << qint32(StickerSetTypeShortName);
} break; } else {
case mtpc_inputStickerSetEmpty:
default: {
stream << qint32(StickerSetTypeEmpty); stream << qint32(StickerSetTypeEmpty);
} break;
} }
} else { } else {
stream << qint32(document->getDuration()); stream << qint32(document->getDuration());

View File

@ -1750,7 +1750,7 @@ void Account::readStickerSets(
ImageWithLocation{ .location = setThumbnail }); ImageWithLocation{ .location = setThumbnail });
} }
const auto set = it->second.get(); 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(); const auto fillStickers = set->stickers.isEmpty();
if (scnt < 0) { // disabled not loaded set if (scnt < 0) { // disabled not loaded set
@ -1783,7 +1783,7 @@ void Account::readStickerSets(
if (fillStickers) { if (fillStickers) {
set->stickers.push_back(document); set->stickers.push_back(document);
if (!(set->flags & MTPDstickerSet_ClientFlag::f_special)) { if (!(set->flags & MTPDstickerSet_ClientFlag::f_special)) {
if (document->sticker()->set.type() != mtpc_inputStickerSetID) { if (!document->sticker()->set.id) {
document->sticker()->set = inputSet; document->sticker()->set = inputSet;
} }
} }