2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Remove some more Auth() calls.

This commit is contained in:
John Preston
2020-06-08 13:06:50 +04:00
parent bede709f6b
commit 3878a1b212
67 changed files with 380 additions and 299 deletions

View File

@@ -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<Main::Session*> 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<ConfirmDontWarnBox>(
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);

View File

@@ -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<Main::Session*> 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<CacheEntry>(query)).first;
std::make_unique<CacheEntry>(_session, query)).first;
}
}
@@ -286,14 +288,14 @@ rpl::producer<SparseIdsSlice> SearchController::simpleIdsSlice(
return builder->applyUpdate(update);
}) | rpl::start_with_next(pushNextSnapshot, lifetime);
Auth().data().itemRemoved(
_session->data().itemRemoved(
) | rpl::filter([=](not_null<const HistoryItem*> item) {
return (item->history()->peer->id == peerId);
}) | rpl::filter([=](not_null<const HistoryItem*> item) {
return builder->removeOne(item->id);
}) | rpl::start_with_next(pushNextSnapshot, lifetime);
Auth().data().historyCleared(
_session->data().historyCleared(
) | rpl::filter([=](not_null<const History*> 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<CacheEntry>(state.query)).first;
std::make_unique<CacheEntry>(_session, state.query)).first;
}
auto replace = Data(it->second->peerData.peer);
replace.list = std::move(state.peerList);

View File

@@ -102,7 +102,7 @@ private:
using SliceUpdate = Storage::SparseIdsSliceUpdate;
struct CacheEntry {
CacheEntry(const Query &query);
CacheEntry(not_null<Main::Session*> session, const Query &query);
Data peerData;
std::optional<Data> migratedData;

View File

@@ -2616,7 +2616,9 @@ void Session::documentApplyFields(
not_null<WebPageData*> Session::webpage(WebPageId id) {
auto i = _webpages.find(id);
if (i == _webpages.cend()) {
i = _webpages.emplace(id, std::make_unique<WebPageData>(id)).first;
i = _webpages.emplace(
id,
std::make_unique<WebPageData>(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<MTPWallPaper> &data, int32 hash) {
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
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);
}
}

View File

@@ -48,7 +48,7 @@ void SharedMediaShowOverview(
not_null<History*> 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<SparseIdsSlice> SharedMediaViewer(
not_null<Main::Session*> session,
Storage::SharedMediaKey key,
int limitBefore,
int limitAfter) {
@@ -76,10 +77,10 @@ rpl::producer<SparseIdsSlice> 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<SparseIdsSlice> 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<SparseIdsSlice> 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<SparseIdsSlice> 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<SparseIdsSlice> 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<SparseIdsSlice> 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<SparseIdsSlice> SharedMediaViewer(
}
rpl::producer<SparseIdsMergedSlice> SharedMediaMergedViewer(
not_null<Main::Session*> session,
SharedMediaMergedKey key,
int limitBefore,
int limitAfter) {
@@ -152,6 +154,7 @@ rpl::producer<SparseIdsMergedSlice> SharedMediaMergedViewer(
int limitBefore,
int limitAfter) {
return SharedMediaViewer(
session,
Storage::SharedMediaKey(
peerId,
key.type,
@@ -349,12 +352,14 @@ std::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId(
}
rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
not_null<Main::Session*> session,
SharedMediaWithLastSlice::Key key,
int limitBefore,
int limitAfter) {
return [=](auto consumer) {
if (base::get_if<not_null<PhotoData*>>(&key.universalId)) {
return SharedMediaMergedViewer(
session,
SharedMediaMergedKey(
SharedMediaWithLastSlice::ViewerKey(key),
key.type),
@@ -369,12 +374,14 @@ rpl::producer<SharedMediaWithLastSlice> 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<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
}
rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastReversedViewer(
not_null<Main::Session*> session,
SharedMediaWithLastSlice::Key key,
int limitBefore,
int limitAfter) {
return SharedMediaWithLastViewer(
session,
key,
limitBefore,
limitAfter

View File

@@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class History;
namespace Main {
class Session;
} // namespace Main
std::optional<Storage::SharedMediaType> SharedMediaOverviewType(
Storage::SharedMediaType type);
void SharedMediaShowOverview(
@@ -21,6 +25,7 @@ void SharedMediaShowOverview(
bool SharedMediaAllowSearch(Storage::SharedMediaType type);
rpl::producer<SparseIdsSlice> SharedMediaViewer(
not_null<Main::Session*> session,
Storage::SharedMediaKey key,
int limitBefore,
int limitAfter);
@@ -46,6 +51,7 @@ struct SharedMediaMergedKey {
};
rpl::producer<SparseIdsMergedSlice> SharedMediaMergedViewer(
not_null<Main::Session*> session,
SharedMediaMergedKey key,
int limitBefore,
int limitAfter);
@@ -179,11 +185,13 @@ private:
};
rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
not_null<Main::Session*> session,
SharedMediaWithLastSlice::Key key,
int limitBefore,
int limitAfter);
rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastReversedViewer(
not_null<Main::Session*> session,
SharedMediaWithLastSlice::Key key,
int limitBefore,
int limitAfter);

View File

@@ -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<UserPhotosSlice> UserPhotosViewer(
not_null<Main::Session*> 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<UserPhotosSliceBuilder>(
key,
@@ -208,17 +210,17 @@ rpl::producer<UserPhotosSlice> 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<UserPhotosSlice> UserPhotosViewer(
rpl::producer<UserPhotosSlice> UserPhotosReversedViewer(
not_null<Main::Session*> session,
UserPhotosSlice::Key key,
int limitBefore,
int limitAfter) {
return UserPhotosViewer(
session,
key,
limitBefore,
limitAfter

View File

@@ -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<UserPhotosSlice> UserPhotosViewer(
not_null<Main::Session*> session,
UserPhotosSlice::Key key,
int limitBefore,
int limitAfter);
rpl::producer<UserPhotosSlice> UserPhotosReversedViewer(
not_null<Main::Session*> session,
UserPhotosSlice::Key key,
int limitBefore,
int limitAfter);

View File

@@ -302,18 +302,22 @@ WallPaper WallPaper::withoutImageData() const {
return result;
}
std::optional<WallPaper> WallPaper::Create(const MTPWallPaper &data) {
return data.match([](const MTPDwallPaper &data) {
return Create(data);
std::optional<WallPaper> WallPaper::Create(
not_null<Main::Session*> session,
const MTPWallPaper &data) {
return data.match([&](const MTPDwallPaper &data) {
return Create(session, data);
}, [](const MTPDwallPaperNoFile &data) {
return std::optional<WallPaper>(); // #TODO themes
});
}
std::optional<WallPaper> WallPaper::Create(const MTPDwallPaper &data) {
std::optional<WallPaper> WallPaper::Create(
not_null<Main::Session*> 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;

View File

@@ -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<WallPaper> Create(
not_null<Main::Session*> session,
const MTPWallPaper &data);
[[nodiscard]] static std::optional<WallPaper> Create(
not_null<Main::Session*> session,
const MTPDwallPaper &data);
[[nodiscard]] QByteArray serialize() const;

View File

@@ -35,6 +35,7 @@ QString SiteNameFromUrl(const QString &url) {
}
WebPageCollage ExtractCollage(
not_null<Data::Session*> owner,
const QVector<MTPPageBlock> &items,
const QVector<MTPPhoto> &photos,
const QVector<MTPDocument> &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<Data::Session*> 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<Data::Session*> owner,
const MTPDwebPage &data)
: WebPageCollage(ExtractCollage(owner, data)) {
}
WebPageData::WebPageData(not_null<Data::Session*> 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;

View File

@@ -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<PhotoData*, DocumentData*>;
WebPageCollage() = default;
explicit WebPageCollage(const MTPDwebPage &data);
explicit WebPageCollage(
not_null<Data::Session*> owner,
const MTPDwebPage &data);
std::vector<Item> items;
};
struct WebPageData {
WebPageData(const WebPageId &id) : id(id) {
}
WebPageData(not_null<Data::Session*> 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<Data::Session*> _owner;
};