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

Method sendPreparedMessage

Telegram/SourceFiles/data/data_histories.cpp:1094–1152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1092}
1093
1094int Histories::sendPreparedMessage(
1095 not_null<History*> history,
1096 FullReplyTo replyTo,
1097 uint64 randomId,
1098 Fn<PreparedMessage(not_null<History*>, FullReplyTo)> message,
1099 Fn<void(const MTPUpdates&, const MTP::Response&)> done,
1100 Fn<void(const MTP::Error&, const MTP::Response&)> fail) {
1101 if (isCreatingTopic(history, replyTo.topicRootId)) {
1102 const auto id = ++_requestAutoincrement;
1103 const auto creatingId = FullMsgId(
1104 history->peer->id,
1105 replyTo.topicRootId);
1106 auto i = _creatingTopics.find(creatingId);
1107 if (i == end(_creatingTopics)) {
1108 sendCreateTopicRequest(history, replyTo.topicRootId);
1109 i = _creatingTopics.emplace(creatingId).first;
1110 }
1111 i->second.push_back({
1112 .randomId = randomId,
1113 .replyTo = replyTo.messageId,
1114 .message = std::move(message),
1115 .done = std::move(done),
1116 .fail = std::move(fail),
1117 .requestId = id,
1118 });
1119 _creatingTopicRequests.emplace(id);
1120 return id;
1121 }
1122 auto realReplyTo = replyTo;
1123 const auto topicReplyToId = [&](const auto &id) {
1124 return convertTopicReplyToId(history, id);
1125 };
1126 realReplyTo.messageId = topicReplyToId(replyTo.messageId);
1127 realReplyTo.topicRootId = topicReplyToId(replyTo.topicRootId);
1128 return v::match(message(history, realReplyTo), [&](const auto &request) {
1129 const auto type = RequestType::Send;
1130 return sendRequest(history, type, [=](Fn<void()> finish) {
1131 const auto session = &_owner->session();
1132 const auto api = &session->api();
1133 history->sendRequestId = api->request(
1134 base::duplicate(request)
1135 ).done([=](
1136 const MTPUpdates &result,
1137 const MTP::Response &response) {
1138 api->applyUpdates(result, randomId);
1139 done(result, response);
1140 finish();
1141 }).fail([=](
1142 const MTP::Error &error,
1143 const MTP::Response &response) {
1144 fail(error, response);
1145 finish();
1146 }).afterRequest(
1147 history->sendRequestId
1148 ).send();
1149 return history->sendRequestId;
1150 });
1151 });

Callers 15

forwardMessagesMethod · 0.80
sendRichMessageMethod · 0.80
sendMessageMethod · 0.80
sendInlineResultMethod · 0.80
sendMediaWithRandomIdMethod · 0.80
sendMultiPaidMediaMethod · 0.80
sendAlbumIfReadyMethod · 0.80
PrepareShareBoxFunction · 0.80
ShareBotGameFunction · 0.80
SendSimpleMediaFunction · 0.80
SendExistingMediaFunction · 0.80

Calls 12

emplaceMethod · 0.80
apiMethod · 0.80
afterRequestMethod · 0.80
FullMsgIdClass · 0.70
finishFunction · 0.50
findMethod · 0.45
sessionMethod · 0.45
sendMethod · 0.45
failMethod · 0.45
doneMethod · 0.45
requestMethod · 0.45
applyUpdatesMethod · 0.45

Tested by

no test coverage detected