mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Simplify CustomEmojiId.
This commit is contained in:
parent
f0f7318978
commit
c126a1e56e
5 changed files with 12 additions and 32 deletions
|
@ -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;
|
||||
|
|
|
@ -87,11 +87,10 @@ QString FieldTagMimeProcessor::operator()(QStringView mimeTag) {
|
|||
} else if (Ui::InputField::IsCustomEmojiLink(tag)) {
|
||||
const auto data = Ui::InputField::CustomEmojiEntityData(tag);
|
||||
const auto emoji = Data::ParseCustomEmojiData(data);
|
||||
if (emoji.selfId != id) {
|
||||
if (!emoji.id) {
|
||||
i = all.erase(i);
|
||||
continue;
|
||||
}
|
||||
if (!_session->premium()) {
|
||||
} else if (!_session->premium()) {
|
||||
const auto document = _session->data().document(emoji.id);
|
||||
if (document->isPremiumEmoji()) {
|
||||
if (!_allowPremiumEmoji
|
||||
|
|
|
@ -488,10 +488,9 @@ std::unique_ptr<Ui::CustomEmoji::Loader> CustomEmojiManager::createLoader(
|
|||
std::unique_ptr<Ui::CustomEmoji::Loader> CustomEmojiManager::createLoader(
|
||||
DocumentId documentId,
|
||||
SizeTag tag) {
|
||||
const auto selfId = _owner->session().userId().bare;
|
||||
auto result = std::make_unique<CustomEmojiLoader>(
|
||||
_owner,
|
||||
CustomEmojiId{ .selfId = selfId, .id = documentId },
|
||||
CustomEmojiId{ .id = documentId },
|
||||
tag);
|
||||
if (result->resolving()) {
|
||||
const auto i = SizeIndex(tag);
|
||||
|
@ -669,27 +668,17 @@ int FrameSizeFromTag(SizeTag tag) {
|
|||
}
|
||||
|
||||
QString SerializeCustomEmojiId(const CustomEmojiId &id) {
|
||||
return QString::number(id.id)
|
||||
+ ':'
|
||||
+ QString::number(id.selfId);
|
||||
return QString::number(id.id);
|
||||
}
|
||||
|
||||
QString SerializeCustomEmojiId(not_null<DocumentData*> document) {
|
||||
return SerializeCustomEmojiId({
|
||||
.selfId = document->session().userId().bare,
|
||||
.id = document->id,
|
||||
});
|
||||
}
|
||||
|
||||
CustomEmojiId ParseCustomEmojiData(QStringView data) {
|
||||
const auto components = data.split(':');
|
||||
if (components.size() != 2) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
.selfId = components[1].toULongLong(),
|
||||
.id = components[0].toULongLong(),
|
||||
};
|
||||
return { .id = data.toULongLong() };
|
||||
}
|
||||
|
||||
bool AllowEmojiWithoutPremium(not_null<PeerData*> peer) {
|
||||
|
|
|
@ -24,8 +24,7 @@ class Session;
|
|||
class CustomEmojiLoader;
|
||||
|
||||
struct CustomEmojiId {
|
||||
uint64 selfId = 0;
|
||||
uint64 id = 0;
|
||||
DocumentId id = 0;
|
||||
};
|
||||
|
||||
class CustomEmojiManager final : public base::has_weak_ptr {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 180b0bc51796dcbe5d9371280e49fda24dfaf0fd
|
||||
Subproject commit fbd82ff92b6e7e1d1f5bb61308d59b60b066f073
|
Loading…
Add table
Reference in a new issue