mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Don't expect itemId from shareContact.
This commit is contained in:
parent
191f832e52
commit
8adbbe6885
3 changed files with 46 additions and 57 deletions
|
@ -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<void(bool)> 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<UserData*> user,
|
||||
const SendAction &action) {
|
||||
const SendAction &action,
|
||||
Fn<void(bool)> 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<void(bool)> 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<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
Api::SendOptions options) {
|
||||
Api::SendOptions options,
|
||||
Fn<void(bool)> done) {
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
_session->data().registerMessageRandomId(randomId, item->fullId());
|
||||
|
||||
sendMediaWithRandomId(item, media, options, randomId);
|
||||
sendMediaWithRandomId(item, media, options, randomId, std::move(done));
|
||||
}
|
||||
|
||||
void ApiWrap::sendMediaWithRandomId(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
Api::SendOptions options,
|
||||
uint64 randomId) {
|
||||
uint64 randomId,
|
||||
Fn<void(bool)> 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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -290,14 +290,16 @@ public:
|
|||
Data::ResolvedForwardDraft &&draft,
|
||||
const SendAction &action,
|
||||
FnMut<void()> &&successCallback = nullptr);
|
||||
FullMsgId shareContact(
|
||||
void shareContact(
|
||||
const QString &phone,
|
||||
const QString &firstName,
|
||||
const QString &lastName,
|
||||
const SendAction &action);
|
||||
FullMsgId shareContact(
|
||||
const SendAction &action,
|
||||
Fn<void(bool)> done = nullptr);
|
||||
void shareContact(
|
||||
not_null<UserData*> user,
|
||||
const SendAction &action);
|
||||
const SendAction &action,
|
||||
Fn<void(bool)> done = nullptr);
|
||||
void applyAffectedMessages(
|
||||
not_null<PeerData*> 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<void(bool)> done);
|
||||
|
||||
void deleteHistory(
|
||||
not_null<PeerData*> peer,
|
||||
|
@ -518,12 +521,14 @@ private:
|
|||
void sendMedia(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
Api::SendOptions options);
|
||||
Api::SendOptions options,
|
||||
Fn<void(bool)> done = nullptr);
|
||||
void sendMediaWithRandomId(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputMedia &media,
|
||||
Api::SendOptions options,
|
||||
uint64 randomId);
|
||||
uint64 randomId,
|
||||
Fn<void(bool)> done = nullptr);
|
||||
FileLoadTo fileLoadTaskOptions(const SendAction &action) const;
|
||||
|
||||
void getTopPromotionDelayed(TimeId now, TimeId next);
|
||||
|
|
|
@ -645,40 +645,10 @@ void AttachWebView::botSharePhone(Fn<void(bool shared)> 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<rpl::lifetime>();
|
||||
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<const HistoryItem*> 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(
|
||||
|
|
Loading…
Add table
Reference in a new issue