mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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();
|
message = &r.vsend_message();
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
auto badAttachment = (result->_photo && result->_photo->isNull())
|
if ((result->_photo && result->_photo->isNull())
|
||||||
|| (result->_document && result->_document->isNull());
|
|| (result->_document && result->_document->isNull())
|
||||||
|
|| !message) {
|
||||||
if (!message) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,108 +169,98 @@ std::unique_ptr<Result> Result::Create(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (message->type()) {
|
message->match([&](const MTPDbotInlineMessageMediaAuto &data) {
|
||||||
case mtpc_botInlineMessageMediaAuto: {
|
const auto message = qs(data.vmessage());
|
||||||
const auto &r = message->c_botInlineMessageMediaAuto();
|
|
||||||
const auto message = qs(r.vmessage());
|
|
||||||
const auto entities = Api::EntitiesFromMTP(
|
const auto entities = Api::EntitiesFromMTP(
|
||||||
session,
|
session,
|
||||||
r.ventities().value_or_empty());
|
data.ventities().value_or_empty());
|
||||||
if (result->_type == Type::Photo) {
|
if (result->_type == Type::Photo) {
|
||||||
if (!result->_photo) {
|
if (result->_photo) {
|
||||||
return nullptr;
|
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) {
|
} else if (result->_type == Type::Game) {
|
||||||
result->createGame(session);
|
result->createGame(session);
|
||||||
result->sendData = std::make_unique<internal::SendGame>(
|
result->sendData = std::make_unique<internal::SendGame>(
|
||||||
session,
|
session,
|
||||||
result->_game);
|
result->_game);
|
||||||
} else {
|
} else {
|
||||||
if (!result->_document) {
|
if (result->_document) {
|
||||||
return nullptr;
|
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()) {
|
}, [&](const MTPDbotInlineMessageText &data) {
|
||||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case mtpc_botInlineMessageText: {
|
|
||||||
const auto &r = message->c_botInlineMessageText();
|
|
||||||
result->sendData = std::make_unique<internal::SendText>(
|
result->sendData = std::make_unique<internal::SendText>(
|
||||||
session,
|
session,
|
||||||
qs(r.vmessage()),
|
qs(data.vmessage()),
|
||||||
Api::EntitiesFromMTP(session, r.ventities().value_or_empty()),
|
Api::EntitiesFromMTP(session, data.ventities().value_or_empty()),
|
||||||
r.is_no_webpage());
|
data.is_no_webpage());
|
||||||
if (const auto markup = r.vreply_markup()) {
|
}, [&](const MTPDbotInlineMessageMediaGeo &data) {
|
||||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
data.vgeo().match([&](const MTPDgeoPoint &geo) {
|
||||||
}
|
if (const auto period = data.vperiod()) {
|
||||||
} break;
|
result->sendData = std::make_unique<internal::SendGeo>(
|
||||||
|
session,
|
||||||
case mtpc_botInlineMessageMediaGeo: {
|
geo,
|
||||||
// #TODO layer 72 save period and send live location?..
|
period->v,
|
||||||
auto &r = message->c_botInlineMessageMediaGeo();
|
(data.vheading()
|
||||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
? std::make_optional(data.vheading()->v)
|
||||||
result->sendData = std::make_unique<internal::SendGeo>(
|
: std::nullopt),
|
||||||
session,
|
(data.vproximity_notification_radius()
|
||||||
r.vgeo().c_geoPoint());
|
? std::make_optional(
|
||||||
} else {
|
data.vproximity_notification_radius()->v)
|
||||||
badAttachment = true;
|
: std::nullopt));
|
||||||
}
|
} else {
|
||||||
if (const auto markup = r.vreply_markup()) {
|
result->sendData = std::make_unique<internal::SendGeo>(
|
||||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
session,
|
||||||
}
|
geo);
|
||||||
} break;
|
}
|
||||||
|
}, [&](const MTPDgeoPointEmpty &) {
|
||||||
case mtpc_botInlineMessageMediaVenue: {
|
LOG(("Inline Error: Empty 'geo' in media-geo."));
|
||||||
auto &r = message->c_botInlineMessageMediaVenue();
|
});
|
||||||
if (r.vgeo().type() == mtpc_geoPoint) {
|
}, [&](const MTPDbotInlineMessageMediaVenue &data) {
|
||||||
|
data.vgeo().match([&](const MTPDgeoPoint &geo) {
|
||||||
result->sendData = std::make_unique<internal::SendVenue>(
|
result->sendData = std::make_unique<internal::SendVenue>(
|
||||||
session,
|
session,
|
||||||
r.vgeo().c_geoPoint(),
|
geo,
|
||||||
qs(r.vvenue_id()),
|
qs(data.vvenue_id()),
|
||||||
qs(r.vprovider()),
|
qs(data.vprovider()),
|
||||||
qs(r.vtitle()),
|
qs(data.vtitle()),
|
||||||
qs(r.vaddress()));
|
qs(data.vaddress()));
|
||||||
} else {
|
}, [&](const MTPDgeoPointEmpty &) {
|
||||||
badAttachment = true;
|
LOG(("Inline Error: Empty 'geo' in media-venue."));
|
||||||
}
|
});
|
||||||
if (const auto markup = r.vreply_markup()) {
|
}, [&](const MTPDbotInlineMessageMediaContact &data) {
|
||||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case mtpc_botInlineMessageMediaContact: {
|
|
||||||
auto &r = message->c_botInlineMessageMediaContact();
|
|
||||||
result->sendData = std::make_unique<internal::SendContact>(
|
result->sendData = std::make_unique<internal::SendContact>(
|
||||||
session,
|
session,
|
||||||
qs(r.vfirst_name()),
|
qs(data.vfirst_name()),
|
||||||
qs(r.vlast_name()),
|
qs(data.vlast_name()),
|
||||||
qs(r.vphone_number()));
|
qs(data.vphone_number()));
|
||||||
if (const auto markup = r.vreply_markup()) {
|
}, [&](const MTPDbotInlineMessageMediaInvoice &data) {
|
||||||
result->_mtpKeyboard = std::make_unique<MTPReplyMarkup>(*markup);
|
// #TODO payments
|
||||||
}
|
});
|
||||||
} break;
|
|
||||||
|
|
||||||
default: {
|
if (!result->sendData || !result->sendData->isValid()) {
|
||||||
badAttachment = true;
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badAttachment || !result->sendData || !result->sendData->isValid()) {
|
|
||||||
return nullptr;
|
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()) {
|
if (const auto point = result->getLocationPoint()) {
|
||||||
const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200;
|
const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200;
|
||||||
const auto zoom = 15 + (scale - 1);
|
const auto zoom = 15 + (scale - 1);
|
||||||
|
|
|
@ -97,7 +97,18 @@ SendDataCommon::SentMTPMessageFields SendText::getSentMessageFields() const {
|
||||||
|
|
||||||
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const {
|
SendDataCommon::SentMTPMessageFields SendGeo::getSentMessageFields() const {
|
||||||
SentMTPMessageFields result;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,18 @@ public:
|
||||||
: SendDataCommon(session)
|
: SendDataCommon(session)
|
||||||
, _location(point) {
|
, _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 {
|
bool isValid() const override {
|
||||||
return true;
|
return true;
|
||||||
|
@ -151,6 +163,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Data::LocationPoint _location;
|
Data::LocationPoint _location;
|
||||||
|
std::optional<int> _period;
|
||||||
|
std::optional<int> _heading;
|
||||||
|
std::optional<int> _proximityNotificationRadius;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue