diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 92c4507be..d4086c9e0 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1060,7 +1060,7 @@ void ApiWrap::requestWallPaper( )).done([=](const MTPWallPaper &result) { _wallPaperRequestId = 0; _wallPaperSlug = QString(); - if (const auto paper = Data::WallPaper::Create(result)) { + if (const auto paper = Data::WallPaper::Create(&session(), result)) { if (const auto done = base::take(_wallPaperDone)) { done(*paper); } diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index 39d0b8d2f..3072fd125 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -98,7 +98,9 @@ int Style::minButtonWidth(HistoryMessageMarkupButton::Type type) const { } // namespace -BotKeyboard::BotKeyboard(QWidget *parent) : TWidget(parent) +BotKeyboard::BotKeyboard(not_null session, QWidget *parent) +: TWidget(parent) +, _session(session) , _st(&st::botKbButton) { setGeometry(0, 0, _st->margin, st::botKbScroll.deltat); _height = st::botKbScroll.deltat; @@ -149,7 +151,7 @@ void BotKeyboard::leaveEventHook(QEvent *e) { } bool BotKeyboard::moderateKeyActivate(int key) { - if (const auto item = Auth().data().message(_wasForMsgId)) { + if (const auto item = _session->data().message(_wasForMsgId)) { if (const auto markup = item->Get()) { if (key >= Qt::Key_1 && key <= Qt::Key_9) { const auto index = int(key - Qt::Key_1); diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.h b/Telegram/SourceFiles/chat_helpers/bot_keyboard.h index 4b61a3b7f..a87867b3b 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.h +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.h @@ -9,18 +9,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/tooltip.h" +class ReplyKeyboard; + namespace style { struct BotKeyboardButton; } // namespace style -class ReplyKeyboard; +namespace Main { +class Session; +} // namespace Main class BotKeyboard : public TWidget , public Ui::AbstractTooltipShower , public ClickHandlerHost { public: - BotKeyboard(QWidget *parent); + BotKeyboard(not_null session, QWidget *parent); bool moderateKeyActivate(int index); @@ -70,6 +74,7 @@ private: void updateStyle(int newWidth); void clearSelection(); + const not_null _session; FullMsgId _wasForMsgId; int _height = 0; int _maxOuterHeight = 0; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index 128e928fa..a878cada2 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -527,7 +527,7 @@ void EmojiKeywords::handleSessionChanges() { void EmojiKeywords::apiChanged(ApiWrap *api) { _api = api; if (_api) { - crl::on_main(&Auth(), crl::guard(&_guard, [=] { + crl::on_main(&_api->session(), crl::guard(&_guard, [=] { base::ObservableViewer( Lang::CurrentCloudManager().firstLanguageSuggestion() ) | rpl::filter([=] { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index e4b8c8ac6..caa5eb18f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -698,7 +698,7 @@ void EmojiListWidget::colorChosen(EmojiPtr emoji) { cRefEmojiVariants().insert( emoji->nonColoredId(), emoji->variantIndex(emoji)); - Auth().saveSettingsDelayed(); + controller()->session().saveSettingsDelayed(); } if (_pickerSel >= 0) { auto section = (_pickerSel / MatrixRowShift); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index dbde3fd92..55f1588ca 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -254,7 +254,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { }; mrows.reserve(mrows.size() + (_chat->participants.empty() ? _chat->lastAuthors.size() : _chat->participants.size())); if (_chat->noParticipantInfo()) { - Auth().api().requestFullPeer(_chat); + _chat->session().api().requestFullPeer(_chat); } else if (!_chat->participants.empty()) { for (const auto user : _chat->participants) { if (user->isInaccessible()) continue; @@ -277,7 +277,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { } else if (_channel && _channel->isMegagroup()) { QMultiMap ordered; if (_channel->lastParticipantsRequestNeeded()) { - Auth().api().requestLastParticipants(_channel); + _channel->session().api().requestLastParticipants(_channel); } else { mrows.reserve(mrows.size() + _channel->mgInfo->lastParticipants.size()); for (const auto user : _channel->mgInfo->lastParticipants) { @@ -600,7 +600,9 @@ FieldAutocompleteInner::FieldAutocompleteInner( , _brows(brows) , _srows(srows) , _previewTimer([=] { showPreview(); }) { - subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); + subscribe( + controller->session().downloaderTaskFinished(), + [=] { update(); }); } void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 67f4d2ed8..9a71890e3 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -48,17 +48,13 @@ constexpr auto kParseLinksTimeout = crl::time(1000); // For mention tags save and validate userId, ignore tags for different userId. class FieldTagMimeProcessor : public Ui::InputField::TagMimeProcessor { public: - QString tagFromMimeTag(const QString &mimeTag) override { - if (TextUtilities::IsMentionLink(mimeTag)) { - auto match = QRegularExpression(":(\\d+)$").match(mimeTag); - if (!match.hasMatch() - || match.capturedRef(1).toInt() != Auth().userId()) { - return QString(); - } - return mimeTag.mid(0, mimeTag.size() - match.capturedLength()); - } - return mimeTag; - } + explicit FieldTagMimeProcessor( + not_null controller); + + QString tagFromMimeTag(const QString &mimeTag) override; + +private: + const not_null _controller; }; @@ -85,6 +81,24 @@ private: }; +FieldTagMimeProcessor::FieldTagMimeProcessor( + not_null controller) +: _controller(controller) { +} + +QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) { + if (TextUtilities::IsMentionLink(mimeTag)) { + const auto userId = _controller->session().userId(); + auto match = QRegularExpression(":(\\d+)$").match(mimeTag); + if (!match.hasMatch() + || match.capturedRef(1).toInt() != userId) { + return QString(); + } + return mimeTag.mid(0, mimeTag.size() - match.capturedLength()); + } + return mimeTag; +} + //bool ValidateUrl(const QString &value) { // const auto match = qthelp::RegExpDomain().match(value); // if (!match.hasMatch() || match.capturedStart() != 0) { @@ -264,7 +278,8 @@ void InitMessageField( field->setMinHeight(st::historySendSize.height() - 2 * st::historySendPadding); field->setMaxHeight(st::historyComposeFieldMaxHeight); - field->setTagMimeProcessor(std::make_unique()); + field->setTagMimeProcessor( + std::make_unique(controller)); field->document()->setDocumentMargin(4.); field->setAdditionalMargin(style::ConvertScale(4) - 4); @@ -307,7 +322,9 @@ bool HasSendText(not_null field) { return false; } -InlineBotQuery ParseInlineBotQuery(not_null field) { +InlineBotQuery ParseInlineBotQuery( + not_null session, + not_null field) { auto result = InlineBotQuery(); const auto &full = field->getTextWithTags(); @@ -345,7 +362,7 @@ InlineBotQuery ParseInlineBotQuery(not_null field) { auto username = text.midRef(inlineUsernameStart, inlineUsernameLength); if (username != result.username) { result.username = username.toString(); - if (const auto peer = Auth().data().peerByUsername(result.username)) { + if (const auto peer = session->data().peerByUsername(result.username)) { if (const auto user = peer->asUser()) { result.bot = peer->asUser(); } else { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 812ca859b..aba01cb68 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -52,7 +52,9 @@ struct InlineBotQuery { UserData *bot = nullptr; bool lookingUpBot = false; }; -InlineBotQuery ParseInlineBotQuery(not_null field); +InlineBotQuery ParseInlineBotQuery( + not_null session, + not_null field); struct AutocompleteQuery { QString query; diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index 33ea64d0c..92724f2b8 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -73,9 +73,9 @@ private: class MentionNameClickHandler : public ClickHandler { public: MentionNameClickHandler(QString text, UserId userId, uint64 accessHash) - : _text(text) - , _userId(userId) - , _accessHash(accessHash) { + : _text(text) + , _userId(userId) + , _accessHash(accessHash) { } void onClick(ClickContext context) const override; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 644cb9e4f..8e27b203e 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -1579,7 +1579,7 @@ void UpdateApplication() { if (const auto controller = window->sessionController()) { controller->showSection( Info::Memento( - Info::Settings::Tag{ Auth().user() }, + Info::Settings::Tag{ controller->session().user() }, Info::Section::SettingsType::Advanced), Window::SectionShow()); } else { diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 76d270c19..9fe746f80 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -65,11 +65,14 @@ QString JoinStringList(const QStringList &list, const QString &separator) { return result; } -void LaunchWithWarning(const QString &name, HistoryItem *item) { +void LaunchWithWarning( + not_null session, + const QString &name, + HistoryItem *item) { const auto warn = [&] { if (!Data::IsExecutableName(name)) { return false; - } else if (!Auth().settings().exeLaunchWarning()) { + } else if (!session->settings().exeLaunchWarning()) { return false; } else if (item && item->history()->peer->isVerified()) { return false; @@ -81,13 +84,13 @@ void LaunchWithWarning(const QString &name, HistoryItem *item) { return; } const auto extension = '.' + Data::FileExtension(name); - const auto callback = [=](bool checked) { + const auto callback = crl::guard(session, [=](bool checked) { if (checked) { - Auth().settings().setExeLaunchWarning(false); - Auth().saveSettingsDelayed(); + session->settings().setExeLaunchWarning(false); + session->saveSettingsDelayed(); } File::Launch(name); - }; + }); Ui::show(Box( tr::lng_launch_exe_warning( lt_extension, @@ -313,7 +316,7 @@ void DocumentOpenClickHandler::Open( return; } } - LaunchWithWarning(location.name(), context); + LaunchWithWarning(&data->session(), location.name(), context); }; const auto media = data->createMediaView(); const auto &location = data->location(true); diff --git a/Telegram/SourceFiles/data/data_search_controller.cpp b/Telegram/SourceFiles/data/data_search_controller.cpp index 90fbd3676..c296d0c7e 100644 --- a/Telegram/SourceFiles/data/data_search_controller.cpp +++ b/Telegram/SourceFiles/data/data_search_controller.cpp @@ -186,10 +186,12 @@ SearchResult ParseSearchResult( return result; } -SearchController::CacheEntry::CacheEntry(const Query &query) -: peerData(Auth().data().peer(query.peerId)) +SearchController::CacheEntry::CacheEntry( + not_null session, + const Query &query) +: peerData(session->data().peer(query.peerId)) , migratedData(query.migratedPeerId - ? base::make_optional(Data(Auth().data().peer(query.migratedPeerId))) + ? base::make_optional(Data(session->data().peer(query.migratedPeerId))) : std::nullopt) { } @@ -211,7 +213,7 @@ void SearchController::setQuery(const Query &query) { if (_current == _cache.end()) { _current = _cache.emplace( query, - std::make_unique(query)).first; + std::make_unique(_session, query)).first; } } @@ -286,14 +288,14 @@ rpl::producer SearchController::simpleIdsSlice( return builder->applyUpdate(update); }) | rpl::start_with_next(pushNextSnapshot, lifetime); - Auth().data().itemRemoved( + _session->data().itemRemoved( ) | rpl::filter([=](not_null item) { return (item->history()->peer->id == peerId); }) | rpl::filter([=](not_null item) { return builder->removeOne(item->id); }) | rpl::start_with_next(pushNextSnapshot, lifetime); - Auth().data().historyCleared( + _session->data().historyCleared( ) | rpl::filter([=](not_null history) { return (history->peer->id == peerId); }) | rpl::filter([=] { @@ -337,7 +339,7 @@ void SearchController::restoreState(SavedState &&state) { if (it == _cache.end()) { it = _cache.emplace( state.query, - std::make_unique(state.query)).first; + std::make_unique(_session, state.query)).first; } auto replace = Data(it->second->peerData.peer); replace.list = std::move(state.peerList); diff --git a/Telegram/SourceFiles/data/data_search_controller.h b/Telegram/SourceFiles/data/data_search_controller.h index f9341ac4d..ba98c1af4 100644 --- a/Telegram/SourceFiles/data/data_search_controller.h +++ b/Telegram/SourceFiles/data/data_search_controller.h @@ -102,7 +102,7 @@ private: using SliceUpdate = Storage::SparseIdsSliceUpdate; struct CacheEntry { - CacheEntry(const Query &query); + CacheEntry(not_null session, const Query &query); Data peerData; std::optional migratedData; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 2d0af620e..60bda9dd0 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -2616,7 +2616,9 @@ void Session::documentApplyFields( not_null Session::webpage(WebPageId id) { auto i = _webpages.find(id); if (i == _webpages.cend()) { - i = _webpages.emplace(id, std::make_unique(id)).first; + i = _webpages.emplace( + id, + std::make_unique(this, id)).first; } return i->second.get(); } @@ -2773,7 +2775,7 @@ void Session::webpageApplyFields( description, photo ? processPhoto(*photo).get() : nullptr, document ? processDocument(*document).get() : lookupThemeDocument(), - WebPageCollage(data), + WebPageCollage(this, data), data.vduration().value_or_empty(), qs(data.vauthor().value_or_empty()), pendingTill); @@ -3800,7 +3802,7 @@ void Session::setWallpapers(const QVector &data, int32 hash) { _wallpapers.back().setLocalImageAsThumbnail(std::make_shared( u":/gui/art/bg_initial.jpg"_q)); for (const auto &paper : data) { - if (const auto parsed = Data::WallPaper::Create(paper)) { + if (const auto parsed = Data::WallPaper::Create(&session(), paper)) { _wallpapers.push_back(*parsed); } } diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index 652c9b7e1..189f36601 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -48,7 +48,7 @@ void SharedMediaShowOverview( not_null history) { if (SharedMediaOverviewType(type)) { App::wnd()->sessionController()->showSection(Info::Memento( - history->peer->id, + history->peer, Info::Section(type))); } } @@ -63,6 +63,7 @@ bool SharedMediaAllowSearch(Storage::SharedMediaType type) { } rpl::producer SharedMediaViewer( + not_null session, Storage::SharedMediaKey key, int limitBefore, int limitAfter) { @@ -76,10 +77,10 @@ rpl::producer SharedMediaViewer( limitBefore, limitAfter); auto requestMediaAround = [ - peer = Auth().data().peer(key.peerId), + peer = session->data().peer(key.peerId), type = key.type ](const SparseIdsSliceBuilder::AroundData &data) { - Auth().api().requestSharedMedia( + peer->session().api().requestSharedMedia( peer, type, data.aroundId, @@ -93,7 +94,7 @@ rpl::producer SharedMediaViewer( }; using SliceUpdate = Storage::SharedMediaSliceUpdate; - Auth().storage().sharedMediaSliceUpdated( + session->storage().sharedMediaSliceUpdated( ) | rpl::filter([=](const SliceUpdate &update) { return (update.peerId == key.peerId) && (update.type == key.type); @@ -102,7 +103,7 @@ rpl::producer SharedMediaViewer( }) | rpl::start_with_next(pushNextSnapshot, lifetime); using OneRemoved = Storage::SharedMediaRemoveOne; - Auth().storage().sharedMediaOneRemoved( + session->storage().sharedMediaOneRemoved( ) | rpl::filter([=](const OneRemoved &update) { return (update.peerId == key.peerId) && update.types.test(key.type); @@ -111,7 +112,7 @@ rpl::producer SharedMediaViewer( }) | rpl::start_with_next(pushNextSnapshot, lifetime); using AllRemoved = Storage::SharedMediaRemoveAll; - Auth().storage().sharedMediaAllRemoved( + session->storage().sharedMediaAllRemoved( ) | rpl::filter([=](const AllRemoved &update) { return (update.peerId == key.peerId); }) | rpl::filter([=] { @@ -119,7 +120,7 @@ rpl::producer SharedMediaViewer( }) | rpl::start_with_next(pushNextSnapshot, lifetime); using InvalidateBottom = Storage::SharedMediaInvalidateBottom; - Auth().storage().sharedMediaBottomInvalidated( + session->storage().sharedMediaBottomInvalidated( ) | rpl::filter([=](const InvalidateBottom &update) { return (update.peerId == key.peerId); }) | rpl::filter([=] { @@ -127,7 +128,7 @@ rpl::producer SharedMediaViewer( }) | rpl::start_with_next(pushNextSnapshot, lifetime); using Result = Storage::SharedMediaResult; - Auth().storage().query(Storage::SharedMediaQuery( + session->storage().query(Storage::SharedMediaQuery( key, limitBefore, limitAfter @@ -143,6 +144,7 @@ rpl::producer SharedMediaViewer( } rpl::producer SharedMediaMergedViewer( + not_null session, SharedMediaMergedKey key, int limitBefore, int limitAfter) { @@ -152,6 +154,7 @@ rpl::producer SharedMediaMergedViewer( int limitBefore, int limitAfter) { return SharedMediaViewer( + session, Storage::SharedMediaKey( peerId, key.type, @@ -349,12 +352,14 @@ std::optional SharedMediaWithLastSlice::LastFullMsgId( } rpl::producer SharedMediaWithLastViewer( + not_null session, SharedMediaWithLastSlice::Key key, int limitBefore, int limitAfter) { return [=](auto consumer) { if (base::get_if>(&key.universalId)) { return SharedMediaMergedViewer( + session, SharedMediaMergedKey( SharedMediaWithLastSlice::ViewerKey(key), key.type), @@ -369,12 +374,14 @@ rpl::producer SharedMediaWithLastViewer( } return rpl::combine( SharedMediaMergedViewer( + session, SharedMediaMergedKey( SharedMediaWithLastSlice::ViewerKey(key), key.type), limitBefore, limitAfter), SharedMediaMergedViewer( + session, SharedMediaMergedKey( SharedMediaWithLastSlice::EndingKey(key), key.type), @@ -392,10 +399,12 @@ rpl::producer SharedMediaWithLastViewer( } rpl::producer SharedMediaWithLastReversedViewer( + not_null session, SharedMediaWithLastSlice::Key key, int limitBefore, int limitAfter) { return SharedMediaWithLastViewer( + session, key, limitBefore, limitAfter diff --git a/Telegram/SourceFiles/data/data_shared_media.h b/Telegram/SourceFiles/data/data_shared_media.h index c184de8e7..dd1681c0e 100644 --- a/Telegram/SourceFiles/data/data_shared_media.h +++ b/Telegram/SourceFiles/data/data_shared_media.h @@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class History; +namespace Main { +class Session; +} // namespace Main + std::optional SharedMediaOverviewType( Storage::SharedMediaType type); void SharedMediaShowOverview( @@ -21,6 +25,7 @@ void SharedMediaShowOverview( bool SharedMediaAllowSearch(Storage::SharedMediaType type); rpl::producer SharedMediaViewer( + not_null session, Storage::SharedMediaKey key, int limitBefore, int limitAfter); @@ -46,6 +51,7 @@ struct SharedMediaMergedKey { }; rpl::producer SharedMediaMergedViewer( + not_null session, SharedMediaMergedKey key, int limitBefore, int limitAfter); @@ -179,11 +185,13 @@ private: }; rpl::producer SharedMediaWithLastViewer( + not_null session, SharedMediaWithLastSlice::Key key, int limitBefore, int limitAfter); rpl::producer SharedMediaWithLastReversedViewer( + not_null session, SharedMediaWithLastSlice::Key key, int limitBefore, int limitAfter); diff --git a/Telegram/SourceFiles/data/data_user_photos.cpp b/Telegram/SourceFiles/data/data_user_photos.cpp index f2a118a9c..fc968c07d 100644 --- a/Telegram/SourceFiles/data/data_user_photos.cpp +++ b/Telegram/SourceFiles/data/data_user_photos.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "apiwrap.h" #include "data/data_session.h" +#include "data/data_user.h" #include "storage/storage_facade.h" #include "storage/storage_user_photos.h" @@ -194,10 +195,11 @@ UserPhotosSlice UserPhotosSliceBuilder::snapshot() const { } rpl::producer UserPhotosViewer( + not_null session, UserPhotosSlice::Key key, int limitBefore, int limitAfter) { - return [key, limitBefore, limitAfter](auto consumer) { + return [=](auto consumer) { auto lifetime = rpl::lifetime(); auto builder = lifetime.make_state( key, @@ -208,17 +210,17 @@ rpl::producer UserPhotosViewer( consumer.put_next(builder->snapshot()); } }; - auto requestPhotosAround = [user = Auth().data().user(key.userId)]( + auto requestPhotosAround = [user = session->data().user(key.userId)]( PhotoId photoId) { - Auth().api().requestUserPhotos(user, photoId); + user->session().api().requestUserPhotos(user, photoId); }; builder->insufficientPhotosAround() | rpl::start_with_next(requestPhotosAround, lifetime); - Auth().storage().userPhotosSliceUpdated() + session->storage().userPhotosSliceUpdated() | rpl::start_with_next(applyUpdate, lifetime); - Auth().storage().query(Storage::UserPhotosQuery( + session->storage().query(Storage::UserPhotosQuery( key, limitBefore, limitAfter @@ -233,10 +235,12 @@ rpl::producer UserPhotosViewer( rpl::producer UserPhotosReversedViewer( + not_null session, UserPhotosSlice::Key key, int limitBefore, int limitAfter) { return UserPhotosViewer( + session, key, limitBefore, limitAfter diff --git a/Telegram/SourceFiles/data/data_user_photos.h b/Telegram/SourceFiles/data/data_user_photos.h index 13ea740e0..f6ad791c9 100644 --- a/Telegram/SourceFiles/data/data_user_photos.h +++ b/Telegram/SourceFiles/data/data_user_photos.h @@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_user_photos.h" #include "base/weak_ptr.h" +namespace Main { +class Session; +} // namespace Main + class UserPhotosSlice { public: using Key = Storage::UserPhotosKey; @@ -46,11 +50,13 @@ private: }; rpl::producer UserPhotosViewer( + not_null session, UserPhotosSlice::Key key, int limitBefore, int limitAfter); rpl::producer UserPhotosReversedViewer( + not_null session, UserPhotosSlice::Key key, int limitBefore, int limitAfter); diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index c938e0163..0b54c0de7 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -302,18 +302,22 @@ WallPaper WallPaper::withoutImageData() const { return result; } -std::optional WallPaper::Create(const MTPWallPaper &data) { - return data.match([](const MTPDwallPaper &data) { - return Create(data); +std::optional WallPaper::Create( + not_null session, + const MTPWallPaper &data) { + return data.match([&](const MTPDwallPaper &data) { + return Create(session, data); }, [](const MTPDwallPaperNoFile &data) { return std::optional(); // #TODO themes }); } -std::optional WallPaper::Create(const MTPDwallPaper &data) { +std::optional WallPaper::Create( + not_null session, + const MTPDwallPaper &data) { using Flag = MTPDwallPaper::Flag; - const auto document = Auth().data().processDocument( + const auto document = session->data().processDocument( data.vdocument()); if (!document->checkWallPaperProperties()) { return std::nullopt; diff --git a/Telegram/SourceFiles/data/data_wall_paper.h b/Telegram/SourceFiles/data/data_wall_paper.h index b1aa82fdf..50fef65e0 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.h +++ b/Telegram/SourceFiles/data/data_wall_paper.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class Image; +namespace Main { +class Session; +} // namespace Main + namespace Data { struct FileOrigin; @@ -49,8 +53,10 @@ public: [[nodiscard]] WallPaper withoutImageData() const; [[nodiscard]] static std::optional Create( + not_null session, const MTPWallPaper &data); [[nodiscard]] static std::optional Create( + not_null session, const MTPDwallPaper &data); [[nodiscard]] QByteArray serialize() const; diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index d3a5eaa93..e08da3326 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -35,6 +35,7 @@ QString SiteNameFromUrl(const QString &url) { } WebPageCollage ExtractCollage( + not_null owner, const QVector &items, const QVector &photos, const QVector &documents) { @@ -51,25 +52,24 @@ WebPageCollage ExtractCollage( return {}; } - auto &storage = Auth().data(); for (const auto &photo : photos) { - storage.processPhoto(photo); + owner->processPhoto(photo); } for (const auto &document : documents) { - storage.processDocument(document); + owner->processDocument(document); } auto result = WebPageCollage(); result.items.reserve(count); for (const auto &item : items) { const auto good = item.match([&](const MTPDpageBlockPhoto &data) { - const auto photo = storage.photo(data.vphoto_id().v); + const auto photo = owner->photo(data.vphoto_id().v); if (photo->isNull()) { return false; } result.items.emplace_back(photo); return true; }, [&](const MTPDpageBlockVideo &data) { - const auto document = storage.document(data.vvideo_id().v); + const auto document = owner->document(data.vvideo_id().v); if (!document->isVideoFile()) { return false; } @@ -85,17 +85,19 @@ WebPageCollage ExtractCollage( return result; } -WebPageCollage ExtractCollage(const MTPDwebPage &data) { +WebPageCollage ExtractCollage( + not_null owner, + const MTPDwebPage &data) { const auto page = data.vcached_page(); if (!page) { return {}; } const auto processMedia = [&] { if (const auto photo = data.vphoto()) { - Auth().data().processPhoto(*photo); + owner->processPhoto(*photo); } if (const auto document = data.vdocument()) { - Auth().data().processDocument(*document); + owner->processDocument(*document); } }; return page->match([&](const auto &page) { @@ -111,12 +113,14 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) { case mtpc_pageBlockSlideshow: processMedia(); return ExtractCollage( + owner, block.c_pageBlockSlideshow().vitems().v, page.vphotos().v, page.vdocuments().v); case mtpc_pageBlockCollage: processMedia(); return ExtractCollage( + owner, block.c_pageBlockCollage().vitems().v, page.vphotos().v, page.vdocuments().v); @@ -148,8 +152,23 @@ WebPageType ParseWebPageType(const MTPDwebPage &page) { } } -WebPageCollage::WebPageCollage(const MTPDwebPage &data) -: WebPageCollage(ExtractCollage(data)) { +WebPageCollage::WebPageCollage( + not_null owner, + const MTPDwebPage &data) +: WebPageCollage(ExtractCollage(owner, data)) { +} + +WebPageData::WebPageData(not_null owner, const WebPageId &id) +: id(id) +, _owner(owner) { +} + +Data::Session &WebPageData::owner() const { + return *_owner; +} + +Main::Session &WebPageData::session() const { + return _owner->session(); } bool WebPageData::applyChanges( @@ -211,7 +230,7 @@ bool WebPageData::applyChanges( return false; } if (pendingTill > 0 && newPendingTill <= 0) { - Auth().api().clearWebPageRequest(this); + _owner->session().api().clearWebPageRequest(this); } type = newType; url = resultUrl; diff --git a/Telegram/SourceFiles/data/data_web_page.h b/Telegram/SourceFiles/data/data_web_page.h index 74e0aaae2..6f05b906f 100644 --- a/Telegram/SourceFiles/data/data_web_page.h +++ b/Telegram/SourceFiles/data/data_web_page.h @@ -12,9 +12,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class ChannelData; -namespace Main { +namespace Data { class Session; -} // namespace Main +} // namespace Data enum class WebPageType { Photo, @@ -32,15 +32,19 @@ struct WebPageCollage { using Item = base::variant; WebPageCollage() = default; - explicit WebPageCollage(const MTPDwebPage &data); + explicit WebPageCollage( + not_null owner, + const MTPDwebPage &data); std::vector items; }; struct WebPageData { - WebPageData(const WebPageId &id) : id(id) { - } + WebPageData(not_null owner, const WebPageId &id); + + [[nodiscard]] Data::Session &owner() const; + [[nodiscard]] Main::Session &session() const; bool applyChanges( WebPageType newType, @@ -79,4 +83,6 @@ struct WebPageData { private: void replaceDocumentGoodThumbnail(); + const not_null _owner; + }; diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 09b85112f..5e6c2c606 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -230,7 +230,7 @@ void paintRow( crl::time ms, PaintItemCallback &&paintItemCallback, PaintCounterCallback &&paintCounterCallback) { - const auto supportMode = Auth().supportMode(); + const auto supportMode = entry->session().supportMode(); if (supportMode) { draft = nullptr; } @@ -339,7 +339,7 @@ void paintRow( history->cloudDraftTextCache.drawElided(p, nameleft, texttop, availableWidth, 1); } else if (draft || (supportMode - && Auth().supportHelper().isOccupiedBySomeone(history))) { + && entry->session().supportHelper().isOccupiedBySomeone(history))) { if (!promoted) { PaintRowDate(p, date, rectForName, active, selected); } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 99cc4458a..b723d9e77 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -553,19 +553,6 @@ bool InnerWidget::elementUnderCursor( return (App::hoveredItem() == view); } -void InnerWidget::elementAnimationAutoplayAsync( - not_null view) { - crl::on_main(this, [this, msgId = view->data()->fullId()] { - if (const auto item = session().data().message(msgId)) { - if (const auto view = viewForItem(item)) { - if (const auto media = view->media()) { - media->autoplayAnimation(); - } - } - } - }); -} - crl::time InnerWidget::elementHighlightTime( not_null element) { return crl::time(0); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 9ed7773b5..177396075 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -96,8 +96,6 @@ public: HistoryView::Element *replacing = nullptr) override; bool elementUnderCursor( not_null view) override; - void elementAnimationAutoplayAsync( - not_null view) override; crl::time elementHighlightTime( not_null element) override; bool elementInSelectionMode() override; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index d220157a4..c0eb794f8 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -3333,18 +3333,6 @@ not_null HistoryInner::ElementDelegate() { not_null view) override { return (App::hoveredItem() == view); } - void elementAnimationAutoplayAsync( - not_null view) override { - crl::on_main(&Auth(), [msgId = view->data()->fullId()] { - if (const auto item = Auth().data().message(msgId)) { - if (const auto view = item->mainView()) { - if (const auto media = view->media()) { - media->autoplayAnimation(); - } - } - } - }); - } crl::time elementHighlightTime( not_null view) override { const auto fullAnimMs = App::main()->highlightStartTime( diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 595f287ed..f070635b6 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -354,9 +354,11 @@ void FastShareMessage(not_null item) { } Fn HistoryDependentItemCallback( - const FullMsgId &msgId) { - return [dependent = msgId](ChannelData *channel, MsgId msgId) { - if (const auto item = Auth().data().message(dependent)) { + not_null item) { + const auto session = &item->history()->session(); + const auto dependent = item->fullId(); + return [=](ChannelData *channel, MsgId msgId) { + if (const auto item = session->data().message(dependent)) { item->updateDependencyItem(); } }; @@ -830,7 +832,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { history()->session().api().requestMessageData( history()->peer->asChannel(), reply->replyToMsgId, - HistoryDependentItemCallback(fullId())); + HistoryDependentItemCallback(this)); } } if (const auto via = Get()) { diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 52718a245..440c9a5be 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -16,7 +16,7 @@ class Message; struct HistoryMessageEdited; Fn HistoryDependentItemCallback( - const FullMsgId &msgId); + not_null item); MTPDmessage::Flags NewMessageFlags(not_null peer); MTPDmessage_ClientFlags NewMessageClientFlags(); QString GetErrorTextForSending( diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 2164a9190..6937b0c03 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -687,7 +687,7 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) { history()->session().api().requestMessageData( history()->peer->asChannel(), dependent->msgId, - HistoryDependentItemCallback(fullId())); + HistoryDependentItemCallback(this)); } } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 7c0f96469..1de2544c4 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -371,7 +371,9 @@ HistoryWidget::HistoryWidget( _topBar->hide(); _scroll->hide(); - _keyboard = _kbScroll->setOwnedWidget(object_ptr(this)); + _keyboard = _kbScroll->setOwnedWidget(object_ptr( + &session(), + this)); _kbScroll->hide(); updateScrollColors(); @@ -1039,7 +1041,7 @@ void HistoryWidget::updateInlineBotQuery() { if (!_history) { return; } - const auto query = ParseInlineBotQuery(_field); + const auto query = ParseInlineBotQuery(&session(), _field); if (_inlineBotUsername != query.username) { _inlineBotUsername = query.username; if (_inlineBotResolveRequestId) { @@ -1780,7 +1782,7 @@ void HistoryWidget::showHistory( _contactStatus = nullptr; // Unload lottie animations. - Auth().data().unloadHeavyViewParts(HistoryInner::ElementDelegate()); + session().data().unloadHeavyViewParts(HistoryInner::ElementDelegate()); if (peerId) { _peer = session().data().peer(peerId); @@ -3841,7 +3843,7 @@ void HistoryWidget::inlineBotResolveDone( }(); session().data().processChats(data.vchats()); - const auto query = ParseInlineBotQuery(_field); + const auto query = ParseInlineBotQuery(&session(), _field); if (_inlineBotUsername == query.username) { applyInlineBotQuery( query.lookingUpBot ? resolvedBot : query.bot, diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 1c8f26517..0acd09a85 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -72,10 +72,6 @@ bool SimpleElementDelegate::elementUnderCursor( return false; } -void SimpleElementDelegate::elementAnimationAutoplayAsync( - not_null element) { -} - crl::time SimpleElementDelegate::elementHighlightTime( not_null element) { return crl::time(0); diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index ed841f9cf..264fbb898 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -43,8 +43,6 @@ public: not_null message, Element *replacing = nullptr) = 0; virtual bool elementUnderCursor(not_null view) = 0; - virtual void elementAnimationAutoplayAsync( - not_null element) = 0; virtual crl::time elementHighlightTime( not_null element) = 0; virtual bool elementInSelectionMode() = 0; @@ -71,8 +69,6 @@ public: not_null message, Element *replacing = nullptr) override; bool elementUnderCursor(not_null view) override; - void elementAnimationAutoplayAsync( - not_null element) override; crl::time elementHighlightTime( not_null element) override; bool elementInSelectionMode() override; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 8a36d9fc7..c93c0128e 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1123,17 +1123,6 @@ bool ListWidget::elementUnderCursor( return (_overElement == view); } -void ListWidget::elementAnimationAutoplayAsync( - not_null view) { - crl::on_main(this, [this, msgId = view->data()->fullId()]{ - if (const auto view = viewForItem(msgId)) { - if (const auto media = view->media()) { - media->autoplayAnimation(); - } - } - }); -} - crl::time ListWidget::elementHighlightTime( not_null element) { if (element->data()->fullId() == _highlightedMessageId) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 428352e90..877d986f1 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -190,8 +190,6 @@ public: not_null message, Element *replacing = nullptr) override; bool elementUnderCursor(not_null view) override; - void elementAnimationAutoplayAsync( - not_null view) override; crl::time elementHighlightTime( not_null element) override; bool elementInSelectionMode() override; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 29a5377b1..df2dcb7e1 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -455,7 +455,7 @@ void TopBarWidget::infoClicked() { // Info::Section(Info::Section::Type::Profile))); } else if (_activeChat.peer()->isSelf()) { _controller->showSection(Info::Memento( - _activeChat.peer()->id, + _activeChat.peer(), Info::Section(Storage::SharedMediaType::Photo))); } else { _controller->showPeerInfo(_activeChat.peer()); diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp index 524e4e977..d9d51639b 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp @@ -20,18 +20,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info { namespace CommonGroups { +Memento::Memento(not_null user) +: ContentMemento(user, 0) { +} + Section Memento::section() const { return Section(Section::Type::CommonGroups); } +not_null Memento::user() const { + return peer()->asUser(); +} + object_ptr Memento::createWidget( QWidget *parent, not_null controller, const QRect &geometry) { - auto result = object_ptr( - parent, - controller, - Auth().data().user(userId())); + auto result = object_ptr(parent, controller, user()); result->setInternalState(geometry, this); return result; } @@ -66,7 +71,7 @@ bool Widget::showInternal(not_null memento) { return false; } if (auto groupsMemento = dynamic_cast(memento.get())) { - if (groupsMemento->userId() == user()->bareId()) { + if (groupsMemento->user() == user()) { restoreState(groupsMemento); return true; } @@ -83,7 +88,7 @@ void Widget::setInternalState( } std::unique_ptr Widget::doCreateMemento() { - auto result = std::make_unique(user()->bareId()); + auto result = std::make_unique(user()); saveState(result.get()); return result; } diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h index ab17cd2e9..ebc5ca940 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h @@ -23,9 +23,7 @@ class InnerWidget; class Memento final : public ContentMemento { public: - Memento(UserId userId) - : ContentMemento(peerFromUser(userId), 0) { - } + explicit Memento(not_null user); object_ptr createWidget( QWidget *parent, @@ -34,9 +32,7 @@ public: Section section() const override; - UserId userId() const { - return peerToUser(peerId()); - } + not_null user() const; void setListState(std::unique_ptr state); std::unique_ptr listState(); diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 61b56c7c3..47cbea464 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -262,8 +262,8 @@ void ContentWidget::refreshSearchField(bool shown) { } Key ContentMemento::key() const { - if (const auto peerId = this->peerId()) { - return Key(Auth().data().peer(peerId)); + if (const auto peer = this->peer()) { + return Key(peer); //} else if (const auto feed = this->feed()) { // #feed // return Key(feed); } else if (const auto poll = this->poll()) { diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 9620a165f..bcfa01169 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -116,8 +116,8 @@ private: class ContentMemento { public: - ContentMemento(PeerId peerId, PeerId migratedPeerId) - : _peerId(peerId) + ContentMemento(not_null peer, PeerId migratedPeerId) + : _peer(peer) , _migratedPeerId(migratedPeerId) { } //explicit ContentMemento(not_null feed) : _feed(feed) { // #feed @@ -133,8 +133,8 @@ public: not_null controller, const QRect &geometry) = 0; - PeerId peerId() const { - return _peerId; + PeerData *peer() const { + return _peer; } PeerId migratedPeerId() const { return _migratedPeerId; @@ -183,7 +183,7 @@ public: } private: - const PeerId _peerId = 0; + PeerData * const _peer = nullptr; const PeerId _migratedPeerId = 0; //Data::Feed * const _feed = nullptr; // #feed UserData * const _settingsSelf = nullptr; diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 8d44e3800..d56199634 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -25,19 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" namespace Info { -namespace { - -not_null CorrectPeer(PeerId peerId) { - Expects(peerId != 0); - - const auto result = Auth().data().peer(peerId); - if (const auto to = result->migrateTo()) { - return to; - } - return result; -} - -} // namespace Key::Key(not_null peer) : _value(peer) { } @@ -91,10 +78,13 @@ rpl::producer AbstractController::mediaSource( SparseIdsMergedSlice::UniversalMsgId aroundId, int limitBefore, int limitAfter) const { + Expects(peer() != nullptr); + return SharedMediaMergedViewer( + &session(), SharedMediaMergedKey( SparseIdsMergedSlice::Key( - peerId(), + peer()->id, migratedPeerId(), aroundId), section().mediaType()), @@ -112,11 +102,8 @@ AbstractController::AbstractController( , _parent(parent) { } -PeerId AbstractController::peerId() const { - if (const auto peer = key().peer()) { - return peer->id; - } - return PeerId(0); +PeerData *AbstractController::peer() const { + return key().peer(); } PeerId AbstractController::migratedPeerId() const { @@ -154,7 +141,7 @@ Controller::Controller( , _widget(widget) , _key(memento->key()) , _migrated(memento->migratedPeerId() - ? Auth().data().peer(memento->migratedPeerId()).get() + ? window->session().data().peer(memento->migratedPeerId()).get() : nullptr) , _section(memento->section()) { updateSearchControllers(memento); @@ -175,7 +162,7 @@ void Controller::setupMigrationViewer() { const auto section = _section; InvokeQueued(_widget, [=] { window->showSection( - Memento(peer->id, section), + Memento(peer, section), Window::SectionShow( Window::SectionShow::Way::Backward, anim::type::instant, @@ -195,7 +182,7 @@ rpl::producer Controller::wrapValue() const { bool Controller::validateMementoPeer( not_null memento) const { - return memento->peerId() == peerId() + return memento->peer() == peer() && memento->migratedPeerId() == migratedPeerId() //&& memento->feed() == feed() // #feed && memento->settingsSelf() == settingsSelf(); @@ -313,6 +300,7 @@ rpl::producer Controller::mediaSource( } return SharedMediaMergedViewer( + &session(), SharedMediaMergedKey( SparseIdsMergedSlice::Key( query.peerId, diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index de2c5f8b3..c3f097d93 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -114,7 +114,7 @@ public: virtual PeerData *migrated() const = 0; virtual Section section() const = 0; - PeerId peerId() const; + PeerData *peer() const; PeerId migratedPeerId() const; //Data::Feed *feed() const { // #feed // return key().feed(); diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index ca4b0317f..36ddb750d 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -164,10 +164,10 @@ bool LayerWidget::takeToThirdSection() { //// shrink the window size. //// //// See https://github.com/telegramdesktop/tdesktop/issues/4091 - //Auth().settings().setThirdSectionExtendedBy(0); + //localCopy->session()().settings().setThirdSectionExtendedBy(0); - //Auth().settings().setThirdSectionInfoEnabled(true); - //Auth().saveSettingsDelayed(); + //localCopy->session()().settings().setThirdSectionInfoEnabled(true); + //localCopy->session()().saveSettingsDelayed(); //localCopy->showSection( // std::move(memento), // Window::SectionShow( diff --git a/Telegram/SourceFiles/info/info_memento.cpp b/Telegram/SourceFiles/info/info_memento.cpp index 97fe6142d..dc47593b5 100644 --- a/Telegram/SourceFiles/info/info_memento.cpp +++ b/Telegram/SourceFiles/info/info_memento.cpp @@ -27,12 +27,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info { -Memento::Memento(PeerId peerId) -: Memento(peerId, Section::Type::Profile) { +Memento::Memento(not_null peer) +: Memento(peer, Section::Type::Profile) { } -Memento::Memento(PeerId peerId, Section section) -: Memento(DefaultStack(peerId, section)) { +Memento::Memento(not_null peer, Section section) +: Memento(DefaultStack(peer, section)) { } //Memento::Memento(not_null feed, Section section) // #feed @@ -52,10 +52,10 @@ Memento::Memento(std::vector> stack) } std::vector> Memento::DefaultStack( - PeerId peerId, + not_null peer, Section section) { auto result = std::vector>(); - result.push_back(DefaultContent(peerId, section)); + result.push_back(DefaultContent(peer, section)); return result; } @@ -102,7 +102,7 @@ Section Memento::DefaultSection(not_null peer) { //} Memento Memento::Default(not_null peer) { - return Memento(peer->id, DefaultSection(peer)); + return Memento(peer, DefaultSection(peer)); } // // #feed //Memento Memento::Default(Dialogs::Key key) { @@ -113,35 +113,29 @@ Memento Memento::Default(not_null peer) { //} std::unique_ptr Memento::DefaultContent( - PeerId peerId, + not_null peer, Section section) { - Expects(peerId != 0); - - auto peer = Auth().data().peer(peerId); if (auto to = peer->migrateTo()) { peer = to; } auto migrated = peer->migrateFrom(); - peerId = peer->id; auto migratedPeerId = migrated ? migrated->id : PeerId(0); switch (section.type()) { case Section::Type::Profile: return std::make_unique( - peerId, + peer, migratedPeerId); case Section::Type::Media: return std::make_unique( - peerId, + peer, migratedPeerId, section.mediaType()); case Section::Type::CommonGroups: - Assert(peerIsUser(peerId)); - return std::make_unique( - peerToUser(peerId)); + return std::make_unique(peer->asUser()); case Section::Type::Members: return std::make_unique( - peerId, + peer, migratedPeerId); } Unexpected("Wrong section type in Info::Memento::DefaultContent()"); diff --git a/Telegram/SourceFiles/info/info_memento.h b/Telegram/SourceFiles/info/info_memento.h index 58b604f4c..c317116cb 100644 --- a/Telegram/SourceFiles/info/info_memento.h +++ b/Telegram/SourceFiles/info/info_memento.h @@ -32,8 +32,8 @@ class WrapWidget; class Memento final : public Window::SectionMemento { public: - explicit Memento(PeerId peerId); - Memento(PeerId peerId, Section section); + explicit Memento(not_null peer); + Memento(not_null peer, Section section); //Memento(not_null feed, Section section); // #feed Memento(Settings::Tag settings, Section section); Memento(not_null poll, FullMsgId contextId); @@ -69,7 +69,7 @@ public: private: static std::vector> DefaultStack( - PeerId peerId, + not_null peer, Section section); //static std::vector> DefaultStack( // #feed // not_null feed, @@ -85,7 +85,7 @@ private: // not_null feed, // Section section); static std::unique_ptr DefaultContent( - PeerId peerId, + not_null peer, Section section); std::vector> _stack; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 188ae0261..32dda9bd2 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -138,9 +138,9 @@ void WrapWidget::injectActiveProfile(Dialogs::Key key) { } void WrapWidget::injectActivePeerProfile(not_null peer) { - const auto firstPeerId = hasStackHistory() - ? _historyStack.front().section->peerId() - : _controller->peerId(); + const auto firstPeer = hasStackHistory() + ? _historyStack.front().section->peer() + : _controller->peer(); const auto firstSectionType = hasStackHistory() ? _historyStack.front().section->section().type() : _controller->section().type(); @@ -160,12 +160,12 @@ void WrapWidget::injectActivePeerProfile(not_null peer) { : Section::MediaType::kCount; if (firstSectionType != expectedType || firstSectionMediaType != expectedMediaType - || firstPeerId != peer->id) { + || firstPeer != peer) { auto section = peer->isSelf() ? Section(Section::MediaType::Photo) : Section(Section::Type::Profile); injectActiveProfileMemento(std::move( - Memento(peer->id, section).takeStack().front())); + Memento(peer, section).takeStack().front())); } } // // #feed @@ -519,11 +519,11 @@ void WrapWidget::addProfileNotificationsButton() { (wrap() == Wrap::Layer ? st::infoLayerTopBarNotifications : st::infoTopBarNotifications))); - notifications->addClickHandler([peer] { - const auto muteForSeconds = Auth().data().notifyIsMuted(peer) + notifications->addClickHandler([=] { + const auto muteForSeconds = peer->owner().notifyIsMuted(peer) ? 0 : Data::NotifySettings::kDefaultMutePeriod; - Auth().data().updateNotifySettings(peer, muteForSeconds); + peer->owner().updateNotifySettings(peer, muteForSeconds); }); Profile::NotificationsEnabledValue( peer @@ -908,9 +908,9 @@ bool WrapWidget::returnToFirstStackFrame( if (!hasStackHistory()) { return false; } - auto firstPeerId = _historyStack.front().section->peerId(); + auto firstPeer = _historyStack.front().section->peer(); auto firstSection = _historyStack.front().section->section(); - if (firstPeerId == memento->peerId() + if (firstPeer == memento->peer() && firstSection.type() == memento->section().type() && firstSection.type() == Section::Type::Profile) { _historyStack.resize(1); diff --git a/Telegram/SourceFiles/info/media/info_media_buttons.h b/Telegram/SourceFiles/info/media/info_media_buttons.h index 56427c835..eaf2154ad 100644 --- a/Telegram/SourceFiles/info/media/info_media_buttons.h +++ b/Telegram/SourceFiles/info/media/info_media_buttons.h @@ -92,7 +92,7 @@ inline auto AddButton( tracker)->entity(); result->addClickHandler([=] { navigation->showSection( - Info::Memento(peer->id, Section(type))); + Info::Memento(peer, Section(type))); }); return result; }; @@ -111,7 +111,7 @@ inline auto AddCommonGroupsButton( tracker)->entity(); result->addClickHandler([=] { navigation->showSection( - Info::Memento(user->id, Section::Type::CommonGroups)); + Info::Memento(user, Section::Type::CommonGroups)); }); return result; }; diff --git a/Telegram/SourceFiles/info/media/info_media_widget.cpp b/Telegram/SourceFiles/info/media/info_media_widget.cpp index dece63f6f..8fa06414c 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_widget.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" #include "ui/ui_utility.h" +#include "data/data_peer.h" #include "styles/style_info.h" namespace Info { @@ -37,16 +38,16 @@ Type TabIndexToType(int index) { Memento::Memento(not_null controller) : Memento( - controller->peerId(), + controller->peer(), controller->migratedPeerId(), controller->section().mediaType()) { } -Memento::Memento(PeerId peerId, PeerId migratedPeerId, Type type) -: ContentMemento(peerId, migratedPeerId) +Memento::Memento(not_null peer, PeerId migratedPeerId, Type type) +: ContentMemento(peer, migratedPeerId) , _type(type) { _searchState.query.type = type; - _searchState.query.peerId = peerId; + _searchState.query.peerId = peer->id; _searchState.query.migratedPeerId = migratedPeerId; if (migratedPeerId) { _searchState.migratedList = Storage::SparseIdsList(); diff --git a/Telegram/SourceFiles/info/media/info_media_widget.h b/Telegram/SourceFiles/info/media/info_media_widget.h index a64f6c9cf..1f1632aa1 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_widget.h @@ -25,7 +25,7 @@ class InnerWidget; class Memento final : public ContentMemento { public: Memento(not_null controller); - Memento(PeerId peerId, PeerId migratedPeerId, Type type); + Memento(not_null peer, PeerId migratedPeerId, Type type); using SearchState = Api::DelayedSearchController::SavedState; diff --git a/Telegram/SourceFiles/info/members/info_members_widget.cpp b/Telegram/SourceFiles/info/members/info_members_widget.cpp index d0e9c35b0..6e1c78603 100644 --- a/Telegram/SourceFiles/info/members/info_members_widget.cpp +++ b/Telegram/SourceFiles/info/members/info_members_widget.cpp @@ -18,12 +18,12 @@ namespace Members { Memento::Memento(not_null controller) : Memento( - controller->peerId(), + controller->peer(), controller->migratedPeerId()) { } -Memento::Memento(PeerId peerId, PeerId migratedPeerId) -: ContentMemento(peerId, migratedPeerId) { +Memento::Memento(not_null peer, PeerId migratedPeerId) +: ContentMemento(peer, migratedPeerId) { } Section Memento::section() const { diff --git a/Telegram/SourceFiles/info/members/info_members_widget.h b/Telegram/SourceFiles/info/members/info_members_widget.h index c44153733..1e43f7c78 100644 --- a/Telegram/SourceFiles/info/members/info_members_widget.h +++ b/Telegram/SourceFiles/info/members/info_members_widget.h @@ -24,7 +24,7 @@ using SavedState = Profile::MembersState; class Memento final : public ContentMemento { public: Memento(not_null controller); - Memento(PeerId peerId, PeerId migratedPeerId); + Memento(not_null peer, PeerId migratedPeerId); object_ptr createWidget( QWidget *parent, diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index a8992513c..dee907f16 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -840,7 +840,7 @@ object_ptr SetupChannelMembers( MembersCountValue(channel) | tr::to_count()); auto membersCallback = [=] { controller->showSection(Info::Memento( - channel->id, + channel, Section::Type::Members)); }; diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index 63c020972..77e6648b9 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -81,7 +81,7 @@ object_ptr InnerWidget::setupContent( _controller->parentController())); _cover->showSection( ) | rpl::start_with_next([=](Section section) { - _controller->showSection(Info::Memento(_peer->id, section)); + _controller->showSection(Info::Memento(_peer, section)); }, _cover->lifetime()); _cover->setOnlineCount(rpl::single(0)); auto details = SetupDetails(_controller, parent, _peer); diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 2a9a051a2..19ff33713 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -150,9 +150,9 @@ rpl::producer NotificationsEnabledValue(not_null peer) { peer, Notify::PeerUpdate::Flag::NotificationsEnabled ) | rpl::map([] { return rpl::empty_value(); }), - Auth().data().defaultNotifyUpdates(peer) - ) | rpl::map([peer] { - return !Auth().data().notifyIsMuted(peer); + peer->owner().defaultNotifyUpdates(peer) + ) | rpl::map([=] { + return !peer->owner().notifyIsMuted(peer); }) | rpl::distinct_until_changed(); } @@ -322,6 +322,7 @@ rpl::producer SharedMediaCountValue( auto aroundId = 0; auto limit = 0; auto updated = SharedMediaMergedViewer( + &peer->session(), SharedMediaMergedKey( SparseIdsMergedSlice::Key( peer->id, @@ -391,7 +392,7 @@ rpl::producer ScamValue(not_null peer) { // return rpl::single( // Data::FeedUpdate{ feed, Flag::Channels } // ) | rpl::then( -// Auth().data().feedUpdated() +// feed->owner().feedUpdated() // ) | rpl::filter([=](const Data::FeedUpdate &update) { // return (update.feed == feed) && (update.flag == Flag::Channels); // }) | rpl::filter([=] { diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp index f8156e14c..d9c25e619 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp @@ -18,12 +18,12 @@ namespace Profile { Memento::Memento(not_null controller) : Memento( - controller->peerId(), + controller->peer(), controller->migratedPeerId()) { } -Memento::Memento(PeerId peerId, PeerId migratedPeerId) -: ContentMemento(peerId, migratedPeerId) { +Memento::Memento(not_null peer, PeerId migratedPeerId) +: ContentMemento(peer, migratedPeerId) { } Section Memento::section() const { diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.h b/Telegram/SourceFiles/info/profile/info_profile_widget.h index fa1b098df..8e944f44d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.h +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.h @@ -19,7 +19,7 @@ struct MembersState; class Memento final : public ContentMemento { public: Memento(not_null controller); - Memento(PeerId peerId, PeerId migratedPeerId); + Memento(not_null peer, PeerId migratedPeerId); object_ptr createWidget( QWidget *parent, diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 1417c14a5..16ef9be42 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -111,13 +111,13 @@ std::unique_ptr Result::Create( if (const auto content = r.vcontent()) { result->_content_url = GetContentUrl(*content); if (result->_type == Type::Photo) { - result->_photo = Auth().data().photoFromWeb( + result->_photo = session->data().photoFromWeb( *content, (imageThumb ? Images::FromWebDocument(*r.vthumb()) : ImageLocation())); } else if (contentMime != "text/html"_q) { - result->_document = Auth().data().documentFromWeb( + result->_document = session->data().documentFromWeb( result->adjustAttributes(*content), (imageThumb ? Images::FromWebDocument(*r.vthumb()) @@ -140,10 +140,10 @@ std::unique_ptr Result::Create( result->_title = qs(r.vtitle().value_or_empty()); result->_description = qs(r.vdescription().value_or_empty()); if (const auto photo = r.vphoto()) { - result->_photo = Auth().data().processPhoto(*photo); + result->_photo = session->data().processPhoto(*photo); } if (const auto document = r.vdocument()) { - result->_document = Auth().data().processDocument(*document); + result->_document = session->data().processDocument(*document); } message = &r.vsend_message(); } break; @@ -186,7 +186,7 @@ std::unique_ptr Result::Create( message, entities); } else if (result->_type == Type::Game) { - result->createGame(); + result->createGame(session); result->sendData = std::make_unique( session, result->_game); @@ -412,11 +412,13 @@ QString Result::getLayoutDescription() const { Result::~Result() { } -void Result::createGame() { - if (_game) return; +void Result::createGame(not_null session) { + if (_game) { + return; + } const auto gameId = rand_value(); - _game = Auth().data().game( + _game = session->data().game( gameId, 0, QString(), diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.h b/Telegram/SourceFiles/inline_bots/inline_bot_result.h index 45395a102..11dee8260 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.h @@ -77,7 +77,7 @@ public: ~Result(); private: - void createGame(); + void createGame(not_null session); QSize thumbBox() const; MTPWebDocument adjustAttributes(const MTPWebDocument &document); MTPVector adjustAttributes( diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index b47b1cfdb..4cf917ce6 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -32,7 +32,7 @@ namespace Intro { namespace details { namespace { -void PrepareSupportMode() { +void PrepareSupportMode(not_null session) { using ::Data::AutoDownload::Full; anim::SetDisabled(true); @@ -41,7 +41,7 @@ void PrepareSupportMode() { Global::SetDesktopNotify(false); Global::SetSoundNotify(false); Global::SetFlashBounceNotify(false); - Auth().settings().autoDownload() = Full::FullDisabled(); + session->settings().autoDownload() = Full::FullDisabled(); Local::writeUserSettings(); } @@ -151,7 +151,7 @@ void Step::finish(const MTPUser &user, QImage &&photo) { session.api().uploadPeerPhoto(session.user(), std::move(photo)); } if (session.supportMode()) { - PrepareSupportMode(); + PrepareSupportMode(&session); } } } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 079edd011..a8bf9874c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2571,7 +2571,7 @@ auto MainWidget::thirdSectionForCurrentMainSection( return std::move(_thirdSectionFromStack); } else if (const auto peer = key.peer()) { return std::make_unique( - peer->id, + peer, Info::Memento::DefaultSection(peer)); //} else if (const auto feed = key.feed()) { // #feed // return std::make_unique( diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 214f1252c..ba21f031b 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -176,7 +176,9 @@ void Instance::setCurrent(const AudioMsgId &audioId) { data->current = audioId; data->isPlaying = false; - const auto item = Auth().data().message(data->current.contextId()); + const auto item = (audioId.audio() && audioId.contextId()) + ? audioId.audio()->owner().message(audioId.contextId()) + : nullptr; if (item) { data->history = item->history()->migrateToOrMe(); data->migrated = data->history->migrateFrom(); @@ -264,6 +266,7 @@ void Instance::validatePlaylist(not_null data) { if (const auto key = playlistKey(data)) { data->playlistRequestedKey = key; SharedMediaMergedViewer( + &data->history->session(), SharedMediaMergedKey(*key, data->overview), kIdsLimit, kIdsLimit @@ -302,8 +305,9 @@ HistoryItem *Instance::itemByIndex(not_null data, int index) { || index >= data->playlistSlice->size()) { return nullptr; } + Assert(data->history != nullptr); const auto fullId = (*data->playlistSlice)[index]; - return Auth().data().message(fullId); + return data->history->owner().message(fullId); } bool Instance::moveInPlaylist( @@ -740,20 +744,21 @@ void Instance::handleStreamingUpdate( HistoryItem *Instance::roundVideoItem() const { const auto data = getData(AudioMsgId::Type::Voice); return (data->streamed - && !data->streamed->instance.info().video.size.isEmpty()) - ? Auth().data().message(data->streamed->id.contextId()) + && !data->streamed->instance.info().video.size.isEmpty() + && data->history) + ? data->history->owner().message(data->streamed->id.contextId()) : nullptr; } void Instance::requestRoundVideoResize() const { if (const auto item = roundVideoItem()) { - Auth().data().requestItemResize(item); + item->history()->owner().requestItemResize(item); } } void Instance::requestRoundVideoRepaint() const { if (const auto item = roundVideoItem()) { - Auth().data().requestItemRepaint(item); + item->history()->owner().requestItemRepaint(item); } } diff --git a/Telegram/SourceFiles/media/player/media_player_panel.cpp b/Telegram/SourceFiles/media/player/media_player_panel.cpp index 6eb44bf44..c5e03e2e5 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.cpp +++ b/Telegram/SourceFiles/media/player/media_player_panel.cpp @@ -288,7 +288,7 @@ void Panel::refreshList() { }, weak->lifetime()); auto memento = Info::Media::Memento( - peerId(), + peer, migratedPeerId(), section().mediaType()); memento.setAroundId(contextId); diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 2bbad2d24..2121b33af 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -302,9 +302,13 @@ void Widget::mouseReleaseEvent(QMouseEvent *e) { if (auto downLabels = base::take(_labelsDown)) { if (_labelsOver == downLabels) { if (_type == AudioMsgId::Type::Voice) { - auto current = instance()->current(_type); - if (auto item = Auth().data().message(current.contextId())) { - Ui::showPeerHistoryAtItem(item); + const auto current = instance()->current(_type); + const auto document = current.audio(); + const auto context = current.contextId(); + if (document && context) { + if (const auto item = document->owner().message(context)) { + Ui::showPeerHistoryAtItem(item); + } } } } @@ -516,7 +520,7 @@ void Widget::handleSongChange() { TextWithEntities textWithEntities; if (document->isVoiceMessage() || document->isVideoMessage()) { - if (const auto item = Auth().data().message(current.contextId())) { + if (const auto item = document->owner().message(current.contextId())) { const auto name = item->fromOriginal()->name; const auto date = [item] { const auto parsed = ItemDateTime(item); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 202a92bf5..f1851a35d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1589,12 +1589,15 @@ bool OverlayWidget::validSharedMedia() const { } void OverlayWidget::validateSharedMedia() { - if (auto key = sharedMediaKey()) { + if (const auto key = sharedMediaKey()) { + Assert(_history != nullptr); + _sharedMedia = std::make_unique(*key); auto viewer = (key->type == SharedMediaType::ChatPhoto) ? SharedMediaWithLastReversedViewer : SharedMediaWithLastViewer; viewer( + &_history->session(), *key, kIdsLimit, kIdsLimit @@ -1656,8 +1659,11 @@ bool OverlayWidget::validUserPhotos() const { void OverlayWidget::validateUserPhotos() { if (const auto key = userPhotosKey()) { + Assert(_user != nullptr); + _userPhotos = std::make_unique(*key); UserPhotosReversedViewer( + &_user->session(), *key, kIdsLimit, kIdsLimit diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index f16086dd4..d59be5115 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -339,6 +339,7 @@ FormRequest::FormRequest( } EditFile::EditFile( + not_null session, not_null value, FileType type, const File &fields, @@ -346,13 +347,15 @@ EditFile::EditFile( : value(value) , type(type) , fields(std::move(fields)) -, uploadData(std::move(uploadData)) +, uploadData(session, std::move(uploadData)) , guard(std::make_shared(true)) { } UploadScanDataPointer::UploadScanDataPointer( + not_null session, std::unique_ptr &&value) -: _value(std::move(value)) { +: _session(session) +, _value(std::move(value)) { } UploadScanDataPointer::UploadScanDataPointer( @@ -364,7 +367,7 @@ UploadScanDataPointer &UploadScanDataPointer::operator=( UploadScanDataPointer::~UploadScanDataPointer() { if (const auto value = _value.get()) { if (const auto fullId = value->fullId) { - Auth().uploader().cancel(fullId); + _session->uploader().cancel(fullId); } } } @@ -460,12 +463,12 @@ int Value::whatNotFilled() const { return result; } -void Value::saveInEdit() { +void Value::saveInEdit(not_null session) { const auto saveList = [&](FileType type) { filesInEdit(type) = ranges::view::all( files(type) ) | ranges::view::transform([=](const File &file) { - return EditFile(this, type, file, nullptr); + return EditFile(session, this, type, file, nullptr); }) | ranges::to_vector; }; saveList(FileType::Scan); @@ -474,6 +477,7 @@ void Value::saveInEdit() { specialScansInEdit.clear(); for (const auto &[type, scan] : specialScans) { specialScansInEdit.emplace(type, EditFile( + session, this, type, scan, @@ -627,6 +631,10 @@ FormController::FormController( , _view(std::make_unique(this)) { } +Main::Session &FormController::session() const { + return _controller->session(); +} + void FormController::show() { requestForm(); requestPassword(); @@ -876,7 +884,7 @@ void FormController::submitPassword( saved.hashForAuth = base::take(_passwordCheckHash); saved.hashForSecret = hashForSecret; saved.secretId = _secretId; - Auth().data().rememberPassportCredentials( + session().data().rememberPassportCredentials( std::move(saved), kRememberCredentialsDelay); } @@ -963,7 +971,7 @@ void FormController::checkSavedPasswordSettings( } } if (_secret.empty()) { - Auth().data().forgetPassportCredentials(); + session().data().forgetPassportCredentials(); showForm(); } }).fail([=](const RPCError &error) { @@ -971,7 +979,7 @@ void FormController::checkSavedPasswordSettings( if (error.type() != qstr("SRP_ID_INVALID") || !handleSrpIdInvalid(_passwordCheckRequestId)) { } else { - Auth().data().forgetPassportCredentials(); + session().data().forgetPassportCredentials(); showForm(); } }).send(); @@ -1366,7 +1374,12 @@ void FormController::uploadScan( } const auto nonconst = findValue(value); const auto fileIndex = [&]() -> std::optional { - auto scanInEdit = EditFile{ nonconst, type, File(), nullptr }; + auto scanInEdit = EditFile( + &session(), + nonconst, + type, + File(), + nullptr); if (type == FileType::Scan || type == FileType::Translation) { auto &list = nonconst->filesInEdit(type); auto scanIndex = int(list.size()); @@ -1494,17 +1507,17 @@ void FormController::subscribeToUploader() { using namespace Storage; - Auth().uploader().secureReady( + session().uploader().secureReady( ) | rpl::start_with_next([=](const UploadSecureDone &data) { scanUploadDone(data); }, _uploaderSubscriptions); - Auth().uploader().secureProgress( + session().uploader().secureProgress( ) | rpl::start_with_next([=](const UploadSecureProgress &data) { scanUploadProgress(data); }, _uploaderSubscriptions); - Auth().uploader().secureFailed( + session().uploader().secureFailed( ) | rpl::start_with_next([=](const FullMsgId &fullId) { scanUploadFail(fullId); }, _uploaderSubscriptions); @@ -1515,7 +1528,9 @@ void FormController::uploadEncryptedFile( UploadScanData &&data) { subscribeToUploader(); - file.uploadData = std::make_unique(std::move(data)); + file.uploadData = UploadScanDataPointer( + &session(), + std::make_unique(std::move(data))); auto prepared = std::make_shared( TaskId(), @@ -1532,8 +1547,10 @@ void FormController::uploadEncryptedFile( file.uploadData->fullId = FullMsgId( 0, - Auth().data().nextLocalMessageId()); - Auth().uploader().upload(file.uploadData->fullId, std::move(prepared)); + session().data().nextLocalMessageId()); + session().uploader().upload( + file.uploadData->fullId, + std::move(prepared)); } void FormController::scanUploadDone(const Storage::UploadSecureDone &data) { @@ -1583,7 +1600,7 @@ QString FormController::defaultEmail() const { } QString FormController::defaultPhoneNumber() const { - return Auth().user()->phone(); + return session().user()->phone(); } auto FormController::scanUpdated() const @@ -1705,7 +1722,7 @@ void FormController::startValueEdit(not_null value) { loadFile(scan); } } - nonconst->saveInEdit(); + nonconst->saveInEdit(&session()); } void FormController::loadFile(File &file) { @@ -1725,7 +1742,7 @@ void FormController::loadFile(File &file) { std::make_unique( StorageFileLocation( file.dcId, - Auth().userId(), + session().userId(), MTP_inputSecureFileLocation( MTP_long(file.id), MTP_long(file.accessHash))), @@ -2235,7 +2252,7 @@ void FormController::saveSecret( MTP_bytes(encryptedSecret), MTP_long(saved.secretId))) )).done([=](const MTPBool &result) { - Auth().data().rememberPassportCredentials( + session().data().rememberPassportCredentials( std::move(saved), kRememberCredentialsDelay); @@ -2342,7 +2359,7 @@ void FormController::fillDownloadedFile( if (bytes.size() > Storage::kMaxFileInMemory) { return; } - Auth().data().cache().put( + session().data().cache().put( Data::DocumentCacheKey(destination.dcId, destination.id), Storage::Cache::Database::TaggedValue( QByteArray( @@ -2495,7 +2512,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) { const auto &data = result.c_account_authorizationForm(); - Auth().data().processUsers(data.vusers()); + session().data().processUsers(data.vusers()); for (const auto &value : data.vvalues().v) { auto parsed = parseValue(value); @@ -2529,7 +2546,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) { if (!ValidateForm(_form)) { return false; } - _bot = Auth().data().userLoaded(_request.botId); + _bot = session().data().userLoaded(_request.botId); _form.pendingErrors = data.verrors().v; return true; } @@ -2597,7 +2614,7 @@ void FormController::showForm() { } else if (_password.request) { if (!_savedPasswordValue.isEmpty()) { submitPassword(base::duplicate(_savedPasswordValue)); - } else if (const auto saved = Auth().data().passportCredentials()) { + } else if (const auto saved = session().data().passportCredentials()) { checkSavedPasswordSettings(*saved); } else { _view->showAskPassword(); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index b6a531c76..5afba1374 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -23,6 +23,10 @@ namespace Window { class SessionController; } // namespace Window +namespace Main { +class Session; +} // namespace Main + namespace Passport { struct Config { @@ -73,7 +77,9 @@ struct UploadScanData { class UploadScanDataPointer { public: - UploadScanDataPointer(std::unique_ptr &&value); + UploadScanDataPointer( + not_null session, + std::unique_ptr &&value); UploadScanDataPointer(UploadScanDataPointer &&other); UploadScanDataPointer &operator=(UploadScanDataPointer &&other); ~UploadScanDataPointer(); @@ -84,6 +90,7 @@ public: UploadScanData *operator->() const; private: + not_null _session; std::unique_ptr _value; }; @@ -115,6 +122,7 @@ struct File { struct EditFile { EditFile( + not_null session, not_null value, FileType type, const File &fields, @@ -188,7 +196,7 @@ struct Value { bool requiresSpecialScan(FileType type) const; bool requiresScan(FileType type) const; bool scansAreFilled() const; - void saveInEdit(); + void saveInEdit(not_null session); void clearEditData(); bool uploadingScan() const; bool saving() const; @@ -324,9 +332,10 @@ public: not_null controller, const FormRequest &request); - not_null window() const { + [[nodiscard]] not_null window() const { return _controller; } + [[nodiscard]] Main::Session &session() const; void show(); UserData *bot() const; diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 7adf23d31..dffd6ee0a 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -598,7 +598,7 @@ void ChatBackground::checkUploadWallPaper() { LOG(("API Error: " "Got wallPaperNoFile after account.UploadWallPaper.")); }); - if (const auto paper = Data::WallPaper::Create(result)) { + if (const auto paper = Data::WallPaper::Create(_session, result)) { setPaper(*paper); writeNewBackgroundSettings(); notify(BackgroundUpdate(BackgroundUpdate::Type::New, tile())); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 2510431c2..b21ec467d 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -68,18 +68,18 @@ Main::Session &SessionNavigation::session() const { void SessionNavigation::showPeerInfo( PeerId peerId, const SectionShow ¶ms) { - //if (Adaptive::ThreeColumn() - // && !_session->settings().thirdSectionInfoEnabled()) { - // _session->settings().setThirdSectionInfoEnabled(true); - // _session->saveSettingsDelayed(); - //} - showSection(Info::Memento(peerId), params); + showPeerInfo(_session->data().peer(peerId), params); } void SessionNavigation::showPeerInfo( not_null peer, const SectionShow ¶ms) { - showPeerInfo(peer->id, params); + //if (Adaptive::ThreeColumn() + // && !_session->settings().thirdSectionInfoEnabled()) { + // _session->settings().setThirdSectionInfoEnabled(true); + // _session->saveSettingsDelayed(); + //} + showSection(Info::Memento(peer), params); } void SessionNavigation::showPeerInfo(