mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Inline bot results display improved for geo, venue and contact types.
This commit is contained in:
parent
cf9a78a164
commit
bf37c73d66
5 changed files with 75 additions and 7 deletions
|
@ -2027,8 +2027,20 @@ int32 StickerPanInner::validateExistingInlineRows(const InlineResults &results)
|
|||
|
||||
if (_inlineRows.isEmpty()) {
|
||||
_inlineWithThumb = false;
|
||||
auto hasThumbDisplay = [](InlineResult *inlineResult) -> bool {
|
||||
if (!inlineResult->thumb->isNull()) {
|
||||
return true;
|
||||
}
|
||||
if (inlineResult->type == InlineResult::Type::Contact) {
|
||||
return true;
|
||||
}
|
||||
if (inlineResult->sendData->hasLocationCoords()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
for (int32 i = until; i < count; ++i) {
|
||||
if (!results.at(i)->thumb->isNull()) {
|
||||
if (hasThumbDisplay(results.at(i))) {
|
||||
_inlineWithThumb = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6112,9 +6112,9 @@ void LocationData::load() {
|
|||
manager.getData(this);
|
||||
}
|
||||
|
||||
HistoryLocation::HistoryLocation(const LocationCoords &coords, const QString &title, const QString &description) : HistoryMedia(),
|
||||
_title(st::msgMinWidth),
|
||||
_description(st::msgMinWidth) {
|
||||
HistoryLocation::HistoryLocation(const LocationCoords &coords, const QString &title, const QString &description) : HistoryMedia()
|
||||
, _title(st::msgMinWidth)
|
||||
, _description(st::msgMinWidth) {
|
||||
if (!title.isEmpty()) {
|
||||
_title.setText(st::webPageTitleFont, textClean(title), _webpageTitleOptions);
|
||||
}
|
||||
|
|
|
@ -2026,6 +2026,21 @@ LayoutInlineArticle::LayoutInlineArticle(InlineResult *result, bool withThumb) :
|
|||
}
|
||||
if (!result->content_url.isEmpty()) {
|
||||
_link = clickHandlerFromUrl(result->content_url);
|
||||
} else {
|
||||
LocationCoords location;
|
||||
if (result->sendData->getLocationCoords(&location)) {
|
||||
_link.reset(new LocationClickHandler(location));
|
||||
int32 w = st::inlineThumbSize, h = st::inlineThumbSize;
|
||||
int32 zoom = 13, scale = 1;
|
||||
if (cScale() == dbisTwo || cRetina()) {
|
||||
scale = 2;
|
||||
w /= 2;
|
||||
h /= 2;
|
||||
}
|
||||
QString coords = qsl("%1,%2").arg(location.lat).arg(location.lon);
|
||||
QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|").arg(zoom).arg(w).arg(h).arg(scale) + coords + qsl("&sensor=false");
|
||||
result->thumb = ImagePtr(url);
|
||||
}
|
||||
}
|
||||
QVector<QStringRef> parts = _result->url.splitRef('/');
|
||||
if (!parts.isEmpty()) {
|
||||
|
@ -2052,9 +2067,9 @@ void LayoutInlineArticle::initDimensions() {
|
|||
int32 titleHeight = qMin(_title.countHeight(_maxw), 2 * st::semiboldFont->height);
|
||||
|
||||
int32 descriptionLines = (_withThumb || _url) ? 2 : 3;
|
||||
|
||||
QString description = _result->sendData->getLayoutDescription(_result);
|
||||
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, descriptionLines * st::normalFont->height, Qt::LayoutDirectionAuto };
|
||||
_description.setText(st::normalFont, _result->description, descriptionOpts);
|
||||
_description.setText(st::normalFont, description, descriptionOpts);
|
||||
int32 descriptionHeight = qMin(_description.countHeight(_maxw), descriptionLines * st::normalFont->height);
|
||||
|
||||
_minh = titleHeight + descriptionHeight;
|
||||
|
@ -2145,7 +2160,14 @@ void LayoutInlineArticle::getState(ClickHandlerPtr &link, HistoryCursorState &cu
|
|||
}
|
||||
|
||||
void LayoutInlineArticle::prepareThumb(int32 width, int32 height) const {
|
||||
if (_result->thumb->isNull()) return;
|
||||
if (_result->thumb->isNull()) {
|
||||
if (_result->type == InlineResult::Type::Contact) {
|
||||
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
||||
_thumb = userDefPhoto(qHash(_result->id) % UserColorsCount)->pixCircled(width, height);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_result->thumb->loaded()) {
|
||||
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
||||
|
|
|
@ -1442,6 +1442,10 @@ WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &u
|
|||
, pendingTill(pendingTill) {
|
||||
}
|
||||
|
||||
QString InlineResultSendData::getLayoutDescription(InlineResult *owner) const {
|
||||
return owner->description;
|
||||
}
|
||||
|
||||
InlineResultSendData::SentMTPMessageFields InlineResultSendText::getSentMessageFields(InlineResult*) const {
|
||||
SentMTPMessageFields result;
|
||||
result.text = MTP_string(_message);
|
||||
|
@ -1467,6 +1471,10 @@ InlineResultSendData::SentMTPMessageFields InlineResultSendContact::getSentMessa
|
|||
return result;
|
||||
}
|
||||
|
||||
QString InlineResultSendContact::getLayoutDescription(InlineResult *owner) const {
|
||||
return App::formatPhone(_phoneNumber) + '\n' + owner->description;
|
||||
}
|
||||
|
||||
InlineResultSendData::SentMTPMessageFields InlineResultSendPhoto::getSentMessageFields(InlineResult *owner) const {
|
||||
SentMTPMessageFields result;
|
||||
|
||||
|
|
|
@ -1276,6 +1276,14 @@ public:
|
|||
};
|
||||
virtual SentMTPMessageFields getSentMessageFields(InlineResult *owner) const = 0;
|
||||
|
||||
virtual bool hasLocationCoords() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool getLocationCoords(LocationCoords *location) const {
|
||||
return false;
|
||||
}
|
||||
virtual QString getLayoutDescription(InlineResult *owner) const;
|
||||
|
||||
};
|
||||
|
||||
// Plain text message.
|
||||
|
@ -1312,6 +1320,15 @@ public:
|
|||
|
||||
SentMTPMessageFields getSentMessageFields(InlineResult *owner) const override;
|
||||
|
||||
bool hasLocationCoords() const override {
|
||||
return true;
|
||||
}
|
||||
bool getLocationCoords(LocationCoords *location) const override {
|
||||
t_assert(location != nullptr);
|
||||
*location = _location;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
LocationCoords _location;
|
||||
|
||||
|
@ -1335,6 +1352,13 @@ public:
|
|||
|
||||
SentMTPMessageFields getSentMessageFields(InlineResult *owner) const override;
|
||||
|
||||
bool getLocationCoords(LocationCoords *location) const override {
|
||||
if (location) {
|
||||
*location = _location;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
LocationCoords _location;
|
||||
QString _venueId, _provider, _title, _address;
|
||||
|
@ -1356,6 +1380,8 @@ public:
|
|||
|
||||
SentMTPMessageFields getSentMessageFields(InlineResult *owner) const override;
|
||||
|
||||
QString getLayoutDescription(InlineResult *owner) const override;
|
||||
|
||||
private:
|
||||
QString _firstName, _lastName, _phoneNumber;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue