diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 78265bf30..a81402d77 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -120,7 +120,7 @@ auto MentionClickHandler::getTextEntity() const -> TextEntity { void MentionNameClickHandler::onClick(ClickContext context) const { const auto button = context.button; if (button == Qt::LeftButton || button == Qt::MiddleButton) { - if (auto user = Auth().data().userLoaded(_userId)) { + if (auto user = _session->data().userLoaded(_userId)) { Ui::showPeerProfile(user); } } @@ -132,7 +132,7 @@ auto MentionNameClickHandler::getTextEntity() const -> TextEntity { } QString MentionNameClickHandler::tooltip() const { - if (const auto user = Auth().data().userLoaded(_userId)) { + if (const auto user = _session->data().userLoaded(_userId)) { const auto name = user->name; if (name != _text) { return name; diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index 92724f2b8..136c236d3 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/basic_click_handlers.h" +namespace Main { +class Session; +} // namespace Main + class HiddenUrlClickHandler : public UrlClickHandler { public: HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) { @@ -72,8 +76,13 @@ private: class MentionNameClickHandler : public ClickHandler { public: - MentionNameClickHandler(QString text, UserId userId, uint64 accessHash) - : _text(text) + MentionNameClickHandler( + not_null session, + QString text, + UserId userId, + uint64 accessHash) + : _session(session) + , _text(text) , _userId(userId) , _accessHash(accessHash) { } @@ -85,6 +94,7 @@ public: QString tooltip() const override; private: + const not_null _session; QString _text; UserId _userId; uint64 _accessHash; diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index a249fd533..617110625 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -112,8 +112,11 @@ std::shared_ptr UiIntegration::createLinkHandler( case EntityType::MentionName: { auto fields = TextUtilities::MentionNameDataToFields(data.data); - if (fields.userId) { + if (!my || !my->session) { + LOG(("Mention name without a session: %1").arg(data.data)); + } else if (fields.userId) { return std::make_shared( + my->session, data.text, fields.userId, fields.accessHash); diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index f5e9ff1d9..b119280b5 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/integration.h" +namespace Main { +class Session; +} // namespace Main + namespace Core { class UiIntegration : public Ui::Integration { @@ -19,6 +23,7 @@ public: Instagram, }; struct Context { + Main::Session *session = nullptr; HashtagMentionType type = HashtagMentionType::Telegram; }; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index e7d4f40cc..7c63556ab 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -301,8 +301,7 @@ QString DocumentFileNameForSave( DocumentClickHandler::DocumentClickHandler( not_null document, FullMsgId context) -: FileClickHandler(context) -, _session(&document->session()) +: FileClickHandler(&document->session(), context) , _document(document) { } @@ -353,9 +352,7 @@ void DocumentOpenClickHandler::Open( } void DocumentOpenClickHandler::onClickImpl() const { - if (valid()) { - Open(context(), document(), getActionItem()); - } + Open(context(), document(), getActionItem()); } void DocumentSaveClickHandler::Save( @@ -393,16 +390,10 @@ void DocumentSaveClickHandler::Save( } void DocumentSaveClickHandler::onClickImpl() const { - if (valid()) { - Save(context(), document()); - } + Save(context(), document()); } void DocumentCancelClickHandler::onClickImpl() const { - if (!valid()) { - return; - } - const auto data = document(); if (!data->date) { return; @@ -435,9 +426,7 @@ void DocumentOpenWithClickHandler::Open( } void DocumentOpenWithClickHandler::onClickImpl() const { - if (valid()) { - Open(context(), document()); - } + Open(context(), document()); } Data::FileOrigin StickerData::setOrigin() const { diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 3767f8d39..f391da7f4 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -335,16 +335,11 @@ public: not_null document, FullMsgId context = FullMsgId()); - [[nodiscard]] bool valid() const { - return !_session.empty(); - } - [[nodiscard]] not_null document() const { return _document; } private: - const base::weak_ptr _session; const not_null _document; }; diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index d2aeebba0..6829ead83 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -329,22 +329,16 @@ PhotoClickHandler::PhotoClickHandler( not_null photo, FullMsgId context, PeerData *peer) -: FileClickHandler(context) -, _session(&photo->session()) +: FileClickHandler(&photo->session(), context) , _photo(photo) , _peer(peer) { } void PhotoOpenClickHandler::onClickImpl() const { - if (valid()) { - Core::App().showPhoto(this); - } + Core::App().showPhoto(this); } void PhotoSaveClickHandler::onClickImpl() const { - if (!valid()) { - return; - } const auto data = photo(); if (!data->date) { return; @@ -354,9 +348,6 @@ void PhotoSaveClickHandler::onClickImpl() const { } void PhotoCancelClickHandler::onClickImpl() const { - if (!valid()) { - return; - } const auto data = photo(); if (!data->date) { return; diff --git a/Telegram/SourceFiles/data/data_photo.h b/Telegram/SourceFiles/data/data_photo.h index bf13efcb4..eaf666d45 100644 --- a/Telegram/SourceFiles/data/data_photo.h +++ b/Telegram/SourceFiles/data/data_photo.h @@ -145,10 +145,6 @@ public: FullMsgId context = FullMsgId(), PeerData *peer = nullptr); - [[nodiscard]] bool valid() const { - return !_session.empty(); - } - [[nodiscard]] not_null photo() const { return _photo; } @@ -157,7 +153,6 @@ public: } private: - const base::weak_ptr _session; const not_null _photo; PeerData * const _peer = nullptr; diff --git a/Telegram/SourceFiles/data/data_types.cpp b/Telegram/SourceFiles/data/data_types.cpp index 8f21a9f94..bd54884b8 100644 --- a/Telegram/SourceFiles/data/data_types.cpp +++ b/Telegram/SourceFiles/data/data_types.cpp @@ -136,7 +136,7 @@ void MessageCursor::applyTo(not_null field) { } HistoryItem *FileClickHandler::getActionItem() const { - return Auth().data().message(context()); + return _session->data().message(context()); } PeerId PeerFromMessage(const MTPmessage &message) { diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index 43a2c45b9..6ac30c572 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -10,28 +10,32 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/value_ordering.h" #include "ui/text/text.h" // For QFIXED_MAX +class HistoryItem; +using HistoryItemsList = std::vector>; + +class StorageImageLocation; +class WebFileLocation; +struct GeoPointLocation; + namespace Storage { namespace Cache { struct Key; } // namespace Cache } // namespace Storage -class HistoryItem; -using HistoryItemsList = std::vector>; - namespace Ui { class InputField; } // namespace Ui +namespace Main { +class Session; +} // namespace Main + namespace Images { enum class Option; using Options = base::flags