diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp index 582abde95..6d20ece59 100644 --- a/Telegram/SourceFiles/dropdown.cpp +++ b/Telegram/SourceFiles/dropdown.cpp @@ -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; } diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index c67b5d4a0..d155ba916 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -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); } diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index 72528908a..b80586a83 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -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 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()) { diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 5acee84be..a62639326 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -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; diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 0dadc52e2..b917ab83e 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -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;