From 90dedb7b70c8c38b4605e7f5d1924838a4f5704d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 19 Dec 2021 17:07:57 +0300 Subject: [PATCH] Added spoiler support to input field. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/api/api_text_entities.cpp | 4 +++- Telegram/SourceFiles/chat_helpers/message_field.cpp | 3 ++- Telegram/SourceFiles/core/ui_integration.cpp | 4 ++++ Telegram/SourceFiles/core/ui_integration.h | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f5e1a0ad4..a0da8a5a9 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1963,6 +1963,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_menu_formatting_underline" = "Underline"; "lng_menu_formatting_strike_out" = "Strike-through"; "lng_menu_formatting_monospace" = "Monospace"; +"lng_menu_formatting_spoiler" = "Spoiler"; "lng_menu_formatting_link_create" = "Create link"; "lng_menu_formatting_link_edit" = "Edit link"; "lng_menu_formatting_clear" = "Plain text"; diff --git a/Telegram/SourceFiles/api/api_text_entities.cpp b/Telegram/SourceFiles/api/api_text_entities.cpp index 6286bd5e0..45f13882c 100644 --- a/Telegram/SourceFiles/api/api_text_entities.cpp +++ b/Telegram/SourceFiles/api/api_text_entities.cpp @@ -73,7 +73,7 @@ EntitiesInText EntitiesFromMTP( case mtpc_messageEntityCode: { auto &d = entity.c_messageEntityCode(); result.push_back({ EntityType::Code, d.voffset().v, d.vlength().v }); } break; case mtpc_messageEntityPre: { auto &d = entity.c_messageEntityPre(); result.push_back({ EntityType::Pre, d.voffset().v, d.vlength().v, Clean(qs(d.vlanguage())) }); } break; case mtpc_messageEntityBankCard: break; // Skipping cards. - case mtpc_messageEntitySpoiler: break; // #TODO spoiler + case mtpc_messageEntitySpoiler: { auto &d = entity.c_messageEntitySpoiler(); result.push_back({ EntityType::Spoiler, d.voffset().v, d.vlength().v }); } break; // #TODO entities } } @@ -97,6 +97,7 @@ MTPVector EntitiesToMTP( && entity.type() != EntityType::StrikeOut && entity.type() != EntityType::Code // #TODO entities && entity.type() != EntityType::Pre + && entity.type() != EntityType::Spoiler && entity.type() != EntityType::MentionName && entity.type() != EntityType::CustomUrl) { continue; @@ -132,6 +133,7 @@ MTPVector EntitiesToMTP( case EntityType::StrikeOut: v.push_back(MTP_messageEntityStrike(offset, length)); break; case EntityType::Code: v.push_back(MTP_messageEntityCode(offset, length)); break; // #TODO entities 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; } } return MTP_vector(std::move(v)); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 6f584d5ab..56ecb95ab 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -547,7 +547,8 @@ void MessageLinksParser::parse() { return (tag == Ui::InputField::kTagBold) || (tag == Ui::InputField::kTagItalic) || (tag == Ui::InputField::kTagUnderline) - || (tag == Ui::InputField::kTagStrikeOut); + || (tag == Ui::InputField::kTagStrikeOut) + || (tag == Ui::InputField::kTagSpoiler); }; auto ranges = QVector(); diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 24ceb2a6c..96f45d147 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -315,6 +315,10 @@ QString UiIntegration::phraseFormattingMonospace() { return tr::lng_menu_formatting_monospace(tr::now); } +QString UiIntegration::phraseFormattingSpoiler() { + return tr::lng_menu_formatting_spoiler(tr::now); +} + bool OpenGLLastCheckFailed() { return QFile::exists(OpenGLCheckFilePath()); } diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index a1fcf44ca..769aebcab 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -70,6 +70,7 @@ public: QString phraseFormattingUnderline() override; QString phraseFormattingStrikeOut() override; QString phraseFormattingMonospace() override; + QString phraseFormattingSpoiler() override; };