mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Don't store MTPInputStickerSet in data.
This commit is contained in:
parent
9dfb43d525
commit
75090dedaa
23 changed files with 152 additions and 119 deletions
|
@ -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<StickerSetBox>(strongController, setId),
|
||||
Ui::LayerOption::KeepOther);
|
||||
|
|
|
@ -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<MTPDocumentAttribute> 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
|
||||
|
|
|
@ -3028,11 +3028,16 @@ void ApiWrap::requestRecentStickersForce(bool 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);
|
||||
|
||||
megagroup->mgInfo->stickerSet = set;
|
||||
request(MTPchannels_SetStickers(megagroup->inputChannel, set)).send();
|
||||
request(MTPchannels_SetStickers(
|
||||
megagroup->inputChannel,
|
||||
Data::InputStickerSet(set)
|
||||
)).send();
|
||||
_session->data().stickers().notifyUpdated();
|
||||
}
|
||||
|
||||
|
|
|
@ -288,7 +288,7 @@ public:
|
|||
void requestRecentStickersForce(bool attached = false);
|
||||
void setGroupStickerSet(
|
||||
not_null<ChannelData*> megagroup,
|
||||
const MTPInputStickerSet &set);
|
||||
const StickerSetIdentifier &set);
|
||||
std::vector<not_null<DocumentData*>> *stickersByEmoji(
|
||||
not_null<EmojiPtr> emoji);
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
Inner(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const MTPInputStickerSet &set);
|
||||
const StickerSetIdentifier &set);
|
||||
|
||||
bool loaded() const;
|
||||
bool notInstalled() const;
|
||||
|
@ -134,7 +134,7 @@ private:
|
|||
|
||||
const std::unique_ptr<Ui::PathShiftGradient> _pathGradient;
|
||||
|
||||
MTPInputStickerSet _input;
|
||||
StickerSetIdentifier _input;
|
||||
|
||||
mtpRequestId _installRequest = 0;
|
||||
|
||||
|
@ -153,7 +153,7 @@ private:
|
|||
StickerSetBox::StickerSetBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const MTPInputStickerSet &set)
|
||||
const StickerSetIdentifier &set)
|
||||
: _controller(controller)
|
||||
, _set(set) {
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ QPointer<Ui::BoxContent> StickerSetBox::Show(
|
|||
not_null<Window::SessionController*> controller,
|
||||
not_null<DocumentData*> document) {
|
||||
if (const auto sticker = document->sticker()) {
|
||||
if (sticker->set.type() != mtpc_inputStickerSetEmpty) {
|
||||
if (sticker->set) {
|
||||
return controller->show(
|
||||
Box<StickerSetBox>(controller, sticker->set),
|
||||
Ui::LayerOption::KeepOther).data();
|
||||
|
@ -344,28 +344,21 @@ void StickerSetBox::resizeEvent(QResizeEvent *e) {
|
|||
StickerSetBox::Inner::Inner(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> 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<Ui::PathShiftGradient>(
|
||||
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) {
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
StickerSetBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const MTPInputStickerSet &set);
|
||||
const StickerSetIdentifier &set);
|
||||
|
||||
static QPointer<Ui::BoxContent> Show(
|
||||
not_null<Window::SessionController*> controller,
|
||||
|
@ -49,7 +49,7 @@ private:
|
|||
void handleError(Error error);
|
||||
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
MTPInputStickerSet _set;
|
||||
const StickerSetIdentifier _set;
|
||||
|
||||
class Inner;
|
||||
QPointer<Inner> _inner;
|
||||
|
|
|
@ -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<Row> _megagroupSelectedSet;
|
||||
object_ptr<AddressField> _megagroupSetField = { nullptr };
|
||||
object_ptr<Ui::PlainShadow> _megagroupSelectedShadow = { nullptr };
|
||||
|
@ -1713,14 +1713,14 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
|||
const auto showSetByRow = [&](const Row &row) {
|
||||
setSelected(SelectedRow());
|
||||
_controller->show(
|
||||
Box<StickerSetBox>(_controller, row.set->mtpInput()),
|
||||
Box<StickerSetBox>(_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);
|
||||
|
|
|
@ -2134,8 +2134,7 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const {
|
|||
}
|
||||
|
||||
void StickersListWidget::showStickerSetBox(not_null<DocumentData*> 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<StickersBox>(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<StickerSetBox>(controller(), it->second->mtpInput()),
|
||||
Box<StickerSetBox>(controller(), it->second->identifier()),
|
||||
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] {
|
||||
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;
|
||||
|
|
|
@ -70,7 +70,7 @@ bool ShowStickerSet(
|
|||
Core::App().hideMediaView();
|
||||
controller->show(Box<StickerSetBox>(
|
||||
controller,
|
||||
MTP_inputStickerSetShortName(MTP_string(match->captured(1)))));
|
||||
StickerSetIdentifier{ .shortName = match->captured(1) }));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -62,7 +62,7 @@ struct StickerData : public DocumentAdditionalData {
|
|||
|
||||
bool animated = false;
|
||||
QString alt;
|
||||
MTPInputStickerSet set = MTP_inputStickerSetEmpty();
|
||||
StickerSetIdentifier set;
|
||||
};
|
||||
|
||||
struct SongData : public DocumentAdditionalData {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -111,8 +111,7 @@ rpl::producer<uint64> Stickers::stickerSetInstalled() const {
|
|||
}
|
||||
|
||||
void Stickers::incrementSticker(not_null<DocumentData*> 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<DocumentData*> 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<not_null<DocumentData*>> 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<std::vector<not_null<EmojiPtr>>> Stickers::getEmojiListFromSet(
|
|||
not_null<DocumentData*> 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()) {
|
||||
|
|
|
@ -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<StickersSetThumbnailView> 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -818,7 +818,7 @@ void GenerateItems(
|
|||
auto setLink = std::make_shared<LambdaClickHandler>([set] {
|
||||
Ui::show(Box<StickerSetBox>(
|
||||
App::wnd()->sessionController(),
|
||||
set));
|
||||
Data::FromInputSet(set)));
|
||||
});
|
||||
auto message = HistoryService::PreparedText { text };
|
||||
message.links.push_back(fromLink);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<LambdaClickHandler>([document = _data](ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto window = my.sessionWindow.get()) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue