Support spoiler and custom emoji entities in secret chats.

This commit is contained in:
levlam 2022-07-27 21:10:18 +03:00
parent 6383e7f1b1
commit af607bf611
4 changed files with 29 additions and 5 deletions

View File

@ -121,6 +121,11 @@ messageEntityBlockquote#20df5d0 offset:int length:int = MessageEntity;
decryptedMessageMediaDocument#6abd9782 thumb:bytes thumb_w:int thumb_h:int mime_type:string size:long key:bytes iv:bytes attributes:Vector<DocumentAttribute> caption:string = DecryptedMessageMedia;
// layer 144
messageEntitySpoiler#32ca960f offset:int length:int = MessageEntity;
messageEntityCustomEmoji#c8cf05f8 offset:int length:int document_id:long = MessageEntity;
---functions---
test.dummyFunction = Bool;

View File

@ -766,7 +766,7 @@ secretChatStateClosed = SecretChatState;
//@is_outbound True, if the chat was created by the current user; otherwise false
//@key_hash Hash of the currently used key for comparison with the hash of the chat partner's key. This is a string of 36 little-endian bytes, which must be split into groups of 2 bits, each denoting a pixel of one of 4 colors FFFFFF, D5E6F3, 2D5775, and 2F99C9.
//-The pixels must be used to make a 12x12 square image filled from left to right, top to bottom. Alternatively, the first 32 bytes of the hash can be converted to the hexadecimal format and printed as 32 2-digit hex numbers
//@layer Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer >= 101, files bigger than 2000MB are supported if the layer >= 143
//@layer Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer >= 101, files bigger than 2000MB are supported if the layer >= 143, spoiler and custom emoji text entities are supported if the layer >= 144
secretChat id:int32 user_id:int53 state:SecretChatState is_outbound:Bool key_hash:bytes layer:int32 = SecretChat;
@ -2075,7 +2075,7 @@ textEntityTypeUnderline = TextEntityType;
//@description A strikethrough text
textEntityTypeStrikethrough = TextEntityType;
//@description A spoiler text. Not supported in secret chats
//@description A spoiler text
textEntityTypeSpoiler = TextEntityType;
//@description Text that must be formatted as if inside a code HTML tag
@ -2093,7 +2093,7 @@ textEntityTypeTextUrl url:string = TextEntityType;
//@description A text shows instead of a raw mention of the user (e.g., when the user has no username) @user_id Identifier of the mentioned user
textEntityTypeMentionName user_id:int53 = TextEntityType;
//@description A custom emoji. Not supported in secret chats. The text behind a custom emoji must be an emoji. Only premium users can use premium custom emoji @custom_emoji_id Unique identifier of the custom emoji
//@description A custom emoji. The text behind a custom emoji must be an emoji. Only premium users can use premium custom emoji @custom_emoji_id Unique identifier of the custom emoji
textEntityTypeCustomEmoji custom_emoji_id:int64 = TextEntityType;
//@description A media timestamp @media_timestamp Timestamp from which a video/audio/video note/voice note playing must start, in seconds. The media can be in the content or the web page preview of the current message, or in the same places in the replied message

View File

@ -3273,8 +3273,15 @@ vector<tl_object_ptr<secret_api::MessageEntity>> get_input_secret_message_entiti
case MessageEntity::Type::MediaTimestamp:
break;
case MessageEntity::Type::Spoiler:
if (layer >= static_cast<int32>(SecretChatLayer::SpoilerAndCustomEmojiEntities)) {
result.push_back(make_tl_object<secret_api::messageEntitySpoiler>(entity.offset, entity.length));
}
break;
case MessageEntity::Type::CustomEmoji:
if (layer >= static_cast<int32>(SecretChatLayer::SpoilerAndCustomEmojiEntities)) {
result.push_back(
make_tl_object<secret_api::messageEntityCustomEmoji>(entity.offset, entity.length, entity.document_id));
}
break;
default:
UNREACHABLE();
@ -3636,6 +3643,16 @@ vector<MessageEntity> get_message_entities(vector<tl_object_ptr<secret_api::Mess
case secret_api::messageEntityMentionName::ID:
// skip all name mentions in secret chats
break;
case secret_api::messageEntitySpoiler::ID: {
auto entity = static_cast<const secret_api::messageEntitySpoiler *>(secret_entity.get());
entities.emplace_back(MessageEntity::Type::Spoiler, entity->offset_, entity->length_);
break;
}
case secret_api::messageEntityCustomEmoji::ID: {
auto entity = static_cast<const secret_api::messageEntityCustomEmoji *>(secret_entity.get());
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_, entity->document_id_);
break;
}
default:
UNREACHABLE();
}
@ -4392,7 +4409,8 @@ void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialo
entity.type == MessageEntity::Type::BlockQuote)) {
return true;
}
if (entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji) {
if (layer < static_cast<int32>(SecretChatLayer::SpoilerAndCustomEmojiEntities) &&
(entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji)) {
return true;
}
return false;

View File

@ -14,7 +14,8 @@ enum class SecretChatLayer : int32 {
NewEntities = 101,
DeleteMessagesOnClose = 123,
SupportBigFiles = 143,
Current = SupportBigFiles
SpoilerAndCustomEmojiEntities = 144,
Current = SpoilerAndCustomEmojiEntities
};
} // namespace td