MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / EntitiesToMTP

Function EntitiesToMTP

Telegram/SourceFiles/api/api_text_entities.cpp:284–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282}
283
284MTPVector<MTPMessageEntity> EntitiesToMTP(
285 Main::Session *session,
286 const EntitiesInText &entities,
287 ConvertOption option) {
288 auto v = QVector<MTPMessageEntity>();
289 v.reserve(entities.size());
290 for (const auto &entity : entities) {
291 if (entity.length() <= 0) {
292 continue;
293 }
294 if (option == ConvertOption::SkipLocal
295 && entity.type() != EntityType::Bold
296 //&& entity.type() != EntityType::Semibold // Not in API.
297 && entity.type() != EntityType::Italic
298 && entity.type() != EntityType::Underline
299 && entity.type() != EntityType::StrikeOut
300 && entity.type() != EntityType::Code // #TODO entities
301 && entity.type() != EntityType::Pre
302 && entity.type() != EntityType::Blockquote
303 && entity.type() != EntityType::Spoiler
304 && entity.type() != EntityType::MentionName
305 && entity.type() != EntityType::CustomUrl
306 && entity.type() != EntityType::CustomEmoji
307 && entity.type() != EntityType::FormattedDate) {
308 continue;
309 }
310
311 auto offset = MTP_int(entity.offset());
312 auto length = MTP_int(entity.length());
313 switch (entity.type()) {
314 case EntityType::Url: {
315 v.push_back(MTP_messageEntityUrl(offset, length));
316 } break;
317 case EntityType::CustomUrl: {
318 const auto external = UrlClickHandler::ExternalUrlFromInternalUrl(
319 entity.data());
320 v.push_back(
321 MTP_messageEntityTextUrl(
322 offset,
323 length,
324 MTP_string(external.isEmpty()
325 ? entity.data()
326 : external)));
327 } break;
328 case EntityType::Email: {
329 v.push_back(MTP_messageEntityEmail(offset, length));
330 } break;
331 case EntityType::Phone: {
332 v.push_back(MTP_messageEntityPhone(offset, length));
333 } break;
334 case EntityType::BankCard: {
335 v.push_back(MTP_messageEntityBankCard(offset, length));
336 } break;
337 case EntityType::Hashtag: {
338 v.push_back(MTP_messageEntityHashtag(offset, length));
339 } break;
340 case EntityType::Cashtag: {
341 v.push_back(MTP_messageEntityCashtag(offset, length));

Callers 15

saveDraftsToCloudMethod · 0.85
sendMessageMethod · 0.85
sendMediaWithRandomIdMethod · 0.85
sendMultiPaidMediaMethod · 0.85
requestBatchMethod · 0.85
PlaceAuctionBidFunction · 0.85
SendRequestFunction · 0.85
ReplyToForMTPFunction · 0.85
tlMethod · 0.85
PollDataToMTPFunction · 0.85
PollDataToInputMediaFunction · 0.85

Calls 12

MTP_stringFunction · 0.85
MentionNameEntityFunction · 0.85
MTP_flagsFunction · 0.85
CustomEmojiEntityFunction · 0.85
MTP_intFunction · 0.50
FlagEnum · 0.50
FlagsClass · 0.50
sizeMethod · 0.45
typeMethod · 0.45
offsetMethod · 0.45
dataMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected