mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +02:00
Support sending live location in inline bot results.
This commit is contained in:
parent
3ec3f6484f
commit
8889329415
3 changed files with 100 additions and 85 deletions
|
@ -149,10 +149,9 @@ std::unique_ptr<Result> Result::Create(
|
|||
message = &r.vsend_message();
|
||||
} break;
|
||||
}
|
||||
auto badAttachment = (result->_photo && result->_photo->isNull())
|
||||
|| (result->_document && result->_document->isNull());
|
||||
|
||||
if (!message) {
|
||||
if ((result->_photo && result->_photo->isNull())
|
||||
|| (result->_document && result->_document->isNull())
|
||||
|| !message) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -170,108 +169,98 @@ std::unique_ptr<Result> Result::Create(
|
|||
}
|
||||
}
|
||||
|
||||
switch (message->type()) {
|
||||
case mtpc_botInlineMessageMediaAuto: {
|
||||
const auto &r = message->c_botInlineMessageMediaAuto();
|
||||
const auto message = qs(r.vmessage());
|
||||
message->match([&](const MTPDbotInlineMessageMediaAuto &data) {
|
||||
const auto message = qs(data.vmessage());
|
||||
const auto entities = Api::EntitiesFromMTP(
|
||||
session,
|
||||
r.ventities().value_or_empty());
|
||||
data.ventities().value_or_empty());
|
||||
if (result->_type == Type::Photo) {
|
||||
if (!result->_photo) {
|
||||
return nullptr;
|
||||
if (result->_photo) {
|
||||
result->sendData = std::make_unique<internal::SendPhoto>(
|
||||
session,
|
||||
result->_photo,
|
||||
message,
|
||||
entities);
|
||||
} else {
|
||||
LOG(("Inline Error: No 'photo' in media-auto, type=photo."));
|
||||
}
|
||||
result->sendData = std::make_unique<internal::SendPhoto>(
|
||||
session,
|
||||
result->_photo,
|
||||
message,
|
||||
entities);
|
||||
} else if (result->_type == Type::Game) {
|
||||
result->createGame(session);
|
||||
result->sendData = std::make_unique<internal::SendGame>(
|
||||
session,
|
||||
result->_game);
|
||||
} else {
|
||||
if (!result->_document) {
|
||||
return nullptr;
|
||||
if (result->_document) {
|
||||
result->sendData = std::make_unique<internal::SendFile>(
|
||||
session,
|
||||
result->_document,
|
||||
message,
|
||||
entities);
|
||||
} else {
|
||||
LOG(("Inline Error: No 'document' in media-auto, type=%1."
|
||||
).arg(int(result->_type)));
|
||||
}
|
||||
result->sendData = std::make_unique<internal::SendFile>(
|
||||
session,
|
||||
result->_document,
|
||||
message,
|
||||
entities);
|
||||
}
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_botInlineMessageText: {
|
||||
const auto &r = message->c_botInlineMessageText();
|
||||
}, [&](const MTPDbotInlineMessageText &data) {
|
||||
result->sendData = std::make_unique<internal::SendText>(
|
||||
session,
|
||||
qs(r.vmessage()),
|
||||
Api::EntitiesFromMTP(session, r.ventities().value_or_empty()),
|
||||
r.is_no_webpage());
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_botInlineMessageMediaGeo: {
|
||||
// #TODO layer 72 save period and send live location?..
|
||||
auto &r = message->c_botInlineMessageMediaGeo();
|
||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
||||
result->sendData = std::make_unique<internal::SendGeo>(
|
||||
session,
|
||||
r.vgeo().c_geoPoint());
|
||||
} else {
|
||||
badAttachment = true;
|
||||
}
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_botInlineMessageMediaVenue: {
|
||||
auto &r = message->c_botInlineMessageMediaVenue();
|
||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(session, data.ventities().value_or_empty()),
|
||||
data.is_no_webpage());
|
||||
}, [&](const MTPDbotInlineMessageMediaGeo &data) {
|
||||
data.vgeo().match([&](const MTPDgeoPoint &geo) {
|
||||
if (const auto period = data.vperiod()) {
|
||||
result->sendData = std::make_unique<internal::SendGeo>(
|
||||
session,
|
||||
geo,
|
||||
period->v,
|
||||
(data.vheading()
|
||||
? std::make_optional(data.vheading()->v)
|
||||
: std::nullopt),
|
||||
(data.vproximity_notification_radius()
|
||||
? std::make_optional(
|
||||
data.vproximity_notification_radius()->v)
|
||||
: std::nullopt));
|
||||
} else {
|
||||
result->sendData = std::make_unique<internal::SendGeo>(
|
||||
session,
|
||||
geo);
|
||||
}
|
||||
}, [&](const MTPDgeoPointEmpty &) {
|
||||
LOG(("Inline Error: Empty 'geo' in media-geo."));
|
||||
});
|
||||
}, [&](const MTPDbotInlineMessageMediaVenue &data) {
|
||||
data.vgeo().match([&](const MTPDgeoPoint &geo) {
|
||||
result->sendData = std::make_unique<internal::SendVenue>(
|
||||
session,
|
||||
r.vgeo().c_geoPoint(),
|
||||
qs(r.vvenue_id()),
|
||||
qs(r.vprovider()),
|
||||
qs(r.vtitle()),
|
||||
qs(r.vaddress()));
|
||||
} else {
|
||||
badAttachment = true;
|
||||
}
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_botInlineMessageMediaContact: {
|
||||
auto &r = message->c_botInlineMessageMediaContact();
|
||||
geo,
|
||||
qs(data.vvenue_id()),
|
||||
qs(data.vprovider()),
|
||||
qs(data.vtitle()),
|
||||
qs(data.vaddress()));
|
||||
}, [&](const MTPDgeoPointEmpty &) {
|
||||
LOG(("Inline Error: Empty 'geo' in media-venue."));
|
||||
});
|
||||
}, [&](const MTPDbotInlineMessageMediaContact &data) {
|
||||
result->sendData = std::make_unique<internal::SendContact>(
|
||||
session,
|
||||
qs(r.vfirst_name()),
|
||||
qs(r.vlast_name()),
|
||||
qs(r.vphone_number()));
|
||||
if (const auto markup = r.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
} break;
|
||||
qs(data.vfirst_name()),
|
||||
qs(data.vlast_name()),
|
||||
qs(data.vphone_number()));
|
||||
}, [&](const MTPDbotInlineMessageMediaInvoice &data) {
|
||||
// #TODO payments
|
||||
});
|
||||
|
||||
default: {
|
||||
badAttachment = true;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (badAttachment || !result->sendData || !result->sendData->isValid()) {
|
||||
if (!result->sendData || !result->sendData->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
message->match([&](const auto &data) {
|
||||
if (const auto markup = data.vreply_markup()) {
|
||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
||||
}
|
||||
});
|
||||
|
||||
if (const auto point = result->getLocationPoint()) {
|
||||
const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200;
|
||||
const auto zoom = 15 + (scale - 1);
|
||||
|
|
|
@ -97,7 +97,18 @@ SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const {
|
|||
|
||||
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const {
|
||||
SentMTPMessageFields result;
|
||||
result.media = MTP_messageMediaGeo(_location.toMTP());
|
||||
if (_period) {
|
||||
using Flag = MTPDmessageMediaGeoLive::Flag;
|
||||
result.media = MTP_messageMediaGeoLive(
|
||||
MTP_flags((_heading ? Flag::f_heading : Flag(0))
|
||||
| (_proximityNotificationRadius ? Flag::f_proximity_notification_radius : Flag(0))),
|
||||
_location.toMTP(),
|
||||
MTP_int(_heading.value_or(0)),
|
||||
MTP_int(*_period),
|
||||
MTP_int(_proximityNotificationRadius.value_or(0)));
|
||||
} else {
|
||||
result.media = MTP_messageMediaGeo(_location.toMTP());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,18 @@ public:
|
|||
: SendDataCommon(session)
|
||||
, _location(point) {
|
||||
}
|
||||
SendGeo(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDgeoPoint &point,
|
||||
int period,
|
||||
std::optional<int> heading,
|
||||
std::optional<int> proximityNotificationRadius)
|
||||
: SendDataCommon(session)
|
||||
, _location(point)
|
||||
, _period(period)
|
||||
, _heading(heading)
|
||||
, _proximityNotificationRadius(proximityNotificationRadius){
|
||||
}
|
||||
|
||||
bool isValid() const override {
|
||||
return true;
|
||||
|
@ -151,6 +163,9 @@ public:
|
|||
|
||||
private:
|
||||
Data::LocationPoint _location;
|
||||
std::optional<int> _period;
|
||||
std::optional<int> _heading;
|
||||
std::optional<int> _proximityNotificationRadius;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue