2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Simplify CustomEmojiId.

This commit is contained in:
John Preston
2022-08-15 13:17:24 +03:00
parent f0f7318978
commit c126a1e56e
5 changed files with 12 additions and 32 deletions

View File

@@ -20,31 +20,24 @@ namespace {
using namespace TextUtilities;
[[nodiscard]] QString CustomEmojiEntityData(
not_null<Main::Session*> session,
const MTPDmessageEntityCustomEmoji &data) {
return Data::SerializeCustomEmojiId({
.selfId = session->userId().bare,
.id = data.vdocument_id().v,
});
}
[[nodiscard]] std::optional<MTPMessageEntity> CustomEmojiEntity(
not_null<Main::Session*> session,
MTPint offset,
MTPint length,
const QString &data) {
const auto parsed = Data::ParseCustomEmojiData(data);
if (!parsed.id || parsed.selfId != session->userId().bare) {
return {};
}
const auto document = session->data().document(parsed.id);
if (!document->sticker()) {
if (!parsed.id) {
return {};
}
return MTP_messageEntityCustomEmoji(
offset,
length,
MTP_long(document->id));
MTP_long(parsed.id));
}
[[nodiscard]] std::optional<MTPMessageEntity> MentionNameEntity(
@@ -125,9 +118,9 @@ EntitiesInText EntitiesFromMTP(
case mtpc_messageEntityPre: { auto &d = entity.c_messageEntityPre(); result.push_back({ EntityType::Pre, d.voffset().v, d.vlength().v, qs(d.vlanguage()) }); } break;
case mtpc_messageEntityBankCard: break; // Skipping cards. // #TODO entities
case mtpc_messageEntitySpoiler: { auto &d = entity.c_messageEntitySpoiler(); result.push_back({ EntityType::Spoiler, d.voffset().v, d.vlength().v }); } break;
case mtpc_messageEntityCustomEmoji: if (session) {
case mtpc_messageEntityCustomEmoji: {
const auto &d = entity.c_messageEntityCustomEmoji();
result.push_back({ EntityType::CustomEmoji, d.voffset().v, d.vlength().v, CustomEmojiEntityData(session, d) });
result.push_back({ EntityType::CustomEmoji, d.voffset().v, d.vlength().v, CustomEmojiEntityData(d) });
} break;
}
}
@@ -181,7 +174,7 @@ MTPVector<MTPMessageEntity> EntitiesToMTP(
case EntityType::Pre: v.push_back(MTP_messageEntityPre(offset, length, MTP_string(entity.data()))); break;
case EntityType::Spoiler: v.push_back(MTP_messageEntitySpoiler(offset, length)); break;
case EntityType::CustomEmoji: {
if (const auto valid = CustomEmojiEntity(session, offset, length, entity.data())) {
if (const auto valid = CustomEmojiEntity(offset, length, entity.data())) {
v.push_back(*valid);
}
} break;