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

Method sendVotes

Telegram/SourceFiles/api/api_polls.cpp:330–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330void Polls::sendVotes(
331 FullMsgId itemId,
332 const std::vector<QByteArray> &options) {
333 if (_pollVotesRequestIds.contains(itemId)) {
334 return;
335 }
336 const auto item = _session->data().message(itemId);
337 const auto media = item ? item->media() : nullptr;
338 const auto poll = media ? media->poll() : nullptr;
339 if (!item) {
340 return;
341 }
342 const auto peer = item->history()->peer;
343
344 const auto showSending = poll && !options.empty();
345 const auto hideSending = [=] {
346 if (showSending) {
347 if (const auto item = _session->data().message(itemId)) {
348 poll->sendingVotes.clear();
349 _session->data().requestItemRepaint(item);
350 }
351 }
352 };
353 if (showSending) {
354 poll->sendingVotes = options;
355 _session->data().requestItemRepaint(item);
356 } else if (poll && options.empty() && poll->voted()) {
357 for (auto &answer : poll->answers) {
358 answer.chosen = false;
359 }
360 ++poll->version;
361 _session->data().notifyPollUpdateDelayed(poll);
362 }
363
364 auto prepared = QVector<MTPbytes>();
365 prepared.reserve(options.size());
366 ranges::transform(
367 options,
368 ranges::back_inserter(prepared),
369 [](const QByteArray &option) { return MTP_bytes(option); });
370 const auto requestId = _api.request(MTPmessages_SendVote(
371 peer->input(),
372 MTP_int(item->id),
373 MTP_vector<MTPbytes>(prepared)
374 )).done([=](const MTPUpdates &result) {
375 _pollVotesRequestIds.erase(itemId);
376 hideSending();
377 if (poll) {
378 if (poll->voteRestriction() != PollData::VoteRestriction::None) {
379 poll->setVoteRestriction(PollData::VoteRestriction::None);
380 _session->data().notifyPollUpdateDelayed(poll);
381 }
382 }
383 _session->updates().applyUpdates(result);
384 }).fail([=](const MTP::Error &error) {
385 _pollVotesRequestIds.erase(itemId);
386 hideSending();
387 if (poll) {

Callers 7

refreshVoteButtonMethod · 0.80
FillPollOptionPageFunction · 0.80
AddPollActionsFunction · 0.80
sendMultiOptionsMethod · 0.80
FillPollAnswerMenuFunction · 0.80

Calls 15

MTP_bytesFunction · 0.85
ShowVoteRestrictionToastFunction · 0.85
requestItemRepaintMethod · 0.80
votedMethod · 0.80
voteRestrictionMethod · 0.80
setVoteRestrictionMethod · 0.80
requestItemResizeMethod · 0.80
emplaceMethod · 0.80
MTP_intFunction · 0.50
containsMethod · 0.45

Tested by

no test coverage detected