diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 2bea4bba8..aa83e5f8d 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3316,37 +3316,50 @@ void ApiWrap::forwardMessages( _session->data().sendHistoryChangeNotifications(); } -FullMsgId ApiWrap::shareContact( +void ApiWrap::shareContact( const QString &phone, const QString &firstName, const QString &lastName, - const SendAction &action) { + const SendAction &action, + Fn done) { const auto userId = UserId(0); - return sendSharedContact(phone, firstName, lastName, userId, action); + sendSharedContact( + phone, + firstName, + lastName, + userId, + action, + std::move(done)); } -FullMsgId ApiWrap::shareContact( +void ApiWrap::shareContact( not_null user, - const SendAction &action) { + const SendAction &action, + Fn done) { const auto userId = peerToUser(user->id); const auto phone = _session->data().findContactPhone(user); if (phone.isEmpty()) { - return {}; + if (done) { + done(false); + } + return; } return sendSharedContact( phone, user->firstName, user->lastName, userId, - action); + action, + std::move(done)); } -FullMsgId ApiWrap::sendSharedContact( +void ApiWrap::sendSharedContact( const QString &phone, const QString &firstName, const QString &lastName, UserId userId, - const SendAction &action) { + const SendAction &action, + Fn done) { sendAction(action); const auto history = action.history; @@ -3391,14 +3404,13 @@ FullMsgId ApiWrap::sendSharedContact( MTP_string(), // vcard MTP_long(userId.bare)), HistoryMessageMarkupData()); - const auto result = item->fullId(); const auto media = MTP_inputMediaContact( MTP_string(phone), MTP_string(firstName), MTP_string(lastName), MTP_string()); // vcard - sendMedia(item, media, action.options); + sendMedia(item, media, action.options, std::move(done)); _session->data().sendHistoryChangeNotifications(); _session->changes().historyUpdated( @@ -3406,8 +3418,6 @@ FullMsgId ApiWrap::sendSharedContact( (action.options.scheduled ? Data::HistoryUpdate::Flag::ScheduledSent : Data::HistoryUpdate::Flag::MessageSent)); - - return result; } void ApiWrap::sendVoiceMessage( @@ -3931,18 +3941,20 @@ void ApiWrap::uploadAlbumMedia( void ApiWrap::sendMedia( not_null item, const MTPInputMedia &media, - Api::SendOptions options) { + Api::SendOptions options, + Fn done) { const auto randomId = base::RandomValue(); _session->data().registerMessageRandomId(randomId, item->fullId()); - sendMediaWithRandomId(item, media, options, randomId); + sendMediaWithRandomId(item, media, options, randomId, std::move(done)); } void ApiWrap::sendMediaWithRandomId( not_null item, const MTPInputMedia &media, Api::SendOptions options, - uint64 randomId) { + uint64 randomId, + Fn done) { const auto history = item->history(); const auto replyTo = item->replyTo(); @@ -3984,10 +3996,12 @@ void ApiWrap::sendMediaWithRandomId( MTP_int(options.scheduled), (options.sendAs ? options.sendAs->input : MTP_inputPeerEmpty()) ), [=](const MTPUpdates &result, const MTP::Response &response) { + if (done) done(true); if (updateRecentStickers) { requestRecentStickersForce(true); } }, [=](const MTP::Error &error, const MTP::Response &response) { + if (done) done(false); sendMessageFail(error, peer, randomId, itemId); }); } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index b064d8df7..f61eb0957 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -290,14 +290,16 @@ public: Data::ResolvedForwardDraft &&draft, const SendAction &action, FnMut &&successCallback = nullptr); - FullMsgId shareContact( + void shareContact( const QString &phone, const QString &firstName, const QString &lastName, - const SendAction &action); - FullMsgId shareContact( + const SendAction &action, + Fn done = nullptr); + void shareContact( not_null user, - const SendAction &action); + const SendAction &action, + Fn done = nullptr); void applyAffectedMessages( not_null peer, const MTPmessages_AffectedMessages &result); @@ -486,12 +488,13 @@ private: SharedMediaType type, Api::SearchResult &&parsed); - FullMsgId sendSharedContact( + void sendSharedContact( const QString &phone, const QString &firstName, const QString &lastName, UserId userId, - const SendAction &action); + const SendAction &action, + Fn done); void deleteHistory( not_null peer, @@ -518,12 +521,14 @@ private: void sendMedia( not_null item, const MTPInputMedia &media, - Api::SendOptions options); + Api::SendOptions options, + Fn done = nullptr); void sendMediaWithRandomId( not_null item, const MTPInputMedia &media, Api::SendOptions options, - uint64 randomId); + uint64 randomId, + Fn done = nullptr); FileLoadTo fileLoadTaskOptions(const SendAction &action) const; void getTopPromotionDelayed(TimeId now, TimeId next); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 623f2bea7..0a45d407d 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -645,40 +645,10 @@ void AttachWebView::botSharePhone(Fn callback) { } auto action = Api::SendAction(history); action.clearDraft = false; - const auto id = history->session().api().shareContact( + history->session().api().shareContact( _bot->session().user(), - action); - const auto owner = &_bot->owner(); - const auto lifetime = std::make_shared(); - const auto check = [=] { - const auto item = id ? owner->message(id) : nullptr; - if (!item || item->hasFailed()) { - lifetime->destroy(); - callback(false); - } - }; - - _bot->session().changes().historyUpdates( - history, - Data::HistoryUpdate::Flag::ClientSideMessages - ) | rpl::start_with_next(check, *lifetime); - - owner->itemRemoved( - ) | rpl::start_with_next([=](not_null item) { - if (item->fullId() == id) { - check(); - } - }, *lifetime); - - owner->itemIdChanged( - ) | rpl::start_with_next([=](const Data::Session::IdChange &change) { - if (FullMsgId(change.newId.peer, change.oldId) == id) { - lifetime->destroy(); - callback(true); - } - }, *lifetime); - - check(); + action, + std::move(callback)); } void AttachWebView::botInvokeCustomMethod(