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

Method sendMessage

Telegram/SourceFiles/apiwrap.cpp:4235–4495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4233}
4234
4235void ApiWrap::sendMessage(
4236 MessageToSend &&message,
4237 std::optional<MsgId> localMessageId) {
4238 const auto history = message.action.history;
4239 const auto peer = history->peer;
4240 auto &textWithTags = message.textWithTags;
4241
4242 auto action = message.action;
4243 action.generateLocal = true;
4244 sendAction(action);
4245
4246 const auto clearCloudDraft = action.clearDraft;
4247 const auto draftTopicRootId = action.replyTo.topicRootId;
4248 const auto draftMonoforumPeerId = action.replyTo.monoforumPeerId;
4249 const auto replyTo = action.replyTo.messageId
4250 ? peer->owner().message(action.replyTo.messageId)
4251 : nullptr;
4252 const auto topicRootId = draftTopicRootId
4253 ? draftTopicRootId
4254 : replyTo
4255 ? replyTo->topicRootId()
4256 : Data::ForumTopic::kGeneralId;
4257 const auto topic = peer->forumTopicFor(topicRootId);
4258 if (!(topic ? Data::CanSendTexts(topic) : Data::CanSendTexts(peer))
4259 || Api::SendDice(message)) {
4260 return;
4261 }
4262 local().saveRecentSentHashtags(textWithTags.text);
4263
4264 auto sending = TextWithEntities();
4265 auto left = TextWithEntities {
4266 textWithTags.text,
4267 TextUtilities::ConvertTextTagsToEntities(textWithTags.tags)
4268 };
4269 auto prepareFlags = Ui::ItemTextOptions(
4270 history,
4271 _session->user()).flags;
4272 TextUtilities::PrepareForSending(left, prepareFlags);
4273
4274 HistoryItem *lastMessage = nullptr;
4275
4276 auto &histories = history->owner().histories();
4277 const auto messageLengthLimit = Data::PremiumLimits(
4278 &history->session()
4279 ).messageLengthCurrent();
4280
4281 const auto exactWebPage = !message.webPage.url.isEmpty();
4282 auto isFirst = true;
4283 while (TextUtilities::CutPart(sending, left, messageLengthLimit)
4284 || (isFirst && exactWebPage)) {
4285 TextUtilities::Trim(left);
4286 const auto isLast = left.empty();
4287
4288 auto newId = FullMsgId(
4289 peer->id,
4290 localMessageId
4291 ? std::exchange(localMessageId, std::nullopt).value()
4292 : _session->data().nextLocalMessageId());

Callers

nothing calls this directly

Calls 15

CanSendTextsFunction · 0.85
SendDiceFunction · 0.85
TextWithEntitiesClass · 0.85
TrimFunction · 0.85
MTP_stringFunction · 0.85
NewMessageFlagsFunction · 0.85
MTP_flagsFunction · 0.85
MTP_longFunction · 0.85
ShouldSendSilentFunction · 0.85
FillMessagePostFlagsFunction · 0.85
EntitiesToMTPFunction · 0.85
NewMessageFromIdFunction · 0.85

Tested by

no test coverage detected