mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Don't store MTPInputStickerSet in data.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user