2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Move some calls from App namespace.

This commit is contained in:
John Preston
2019-01-18 16:27:37 +04:00
parent e7804d014d
commit 4111da1dd0
74 changed files with 896 additions and 852 deletions

View File

@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "data/data_channel.h"
#include "data/data_session.h"
namespace Data {
@@ -29,7 +30,7 @@ void ChannelAdminChanges::feed(UserId userId, bool isAdmin) {
ChannelAdminChanges::~ChannelAdminChanges() {
if (!_changes.empty()) {
if (auto history = App::historyLoaded(_channel)) {
if (const auto history = _channel->owner().historyLoaded(_channel)) {
history->applyGroupAdminChanges(_changes);
}
}

View File

@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/message_field.h"
#include "history/history.h"
#include "history/history_widget.h"
#include "data/data_session.h"
#include "mainwidget.h"
#include "storage/localstorage.h"
#include "support/support_helper.h"
@@ -45,7 +46,7 @@ Draft::Draft(
}
void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
const auto history = App::history(peerId);
const auto history = Auth().data().history(peerId);
const auto textWithTags = TextWithTags {
qs(draft.vmessage),
ConvertEntitiesToTextTags(
@@ -79,7 +80,7 @@ void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) {
}
void clearPeerCloudDraft(PeerId peerId, TimeId date) {
const auto history = App::history(peerId);
const auto history = Auth().data().history(peerId);
if (history->skipCloudDraft(QString(), MsgId(0), date)) {
return;
}

View File

@@ -78,7 +78,7 @@ void Feed::indexNameParts() {
}
void Feed::registerOne(not_null<ChannelData*> channel) {
const auto history = App::history(channel);
const auto history = owner().history(channel);
if (!base::contains(_channels, history)) {
const auto invisible = (_channels.size() < 2);
_channels.push_back(history);
@@ -120,7 +120,7 @@ void Feed::registerOne(not_null<ChannelData*> channel) {
}
void Feed::unregisterOne(not_null<ChannelData*> channel) {
const auto history = App::history(channel);
const auto history = owner().history(channel);
const auto i = ranges::remove(_channels, history);
if (i != end(_channels)) {
const auto visible = (_channels.size() > 1);
@@ -339,7 +339,7 @@ bool Feed::unreadCountKnown() const {
// #feed
//void Feed::applyDialog(const MTPDdialogFeed &data) {
// const auto addChannel = [&](ChannelId channelId) {
// if (const auto channel = App::channelLoaded(channelId)) {
// if (const auto channel = owner().channelLoaded(channelId)) {
// channel->setFeed(this);
// }
// };

View File

@@ -338,7 +338,8 @@ bool MediaPhoto::updateInlineResultMedia(const MTPMessageMedia &media) {
}
auto &data = media.c_messageMediaPhoto();
if (data.has_photo() && !data.has_ttl_seconds()) {
const auto photo = parent()->history()->owner().photo(data.vphoto);
const auto photo = parent()->history()->owner().processPhoto(
data.vphoto);
if (photo == _photo) {
return true;
} else {
@@ -684,7 +685,7 @@ bool MediaFile::updateInlineResultMedia(const MTPMessageMedia &media) {
}
auto &data = media.c_messageMediaDocument();
if (data.has_document() && !data.has_ttl_seconds()) {
const auto document = parent()->history()->owner().document(
const auto document = parent()->history()->owner().processDocument(
data.vdocument);
if (document == _document) {
return false;

View File

@@ -179,7 +179,7 @@ void PeerData::setUserpic(
void PeerData::setUserpicPhoto(const MTPPhoto &data) {
const auto photoId = data.match([&](const MTPDphoto &data) {
const auto photo = owner().photo(data);
const auto photo = owner().processPhoto(data);
photo->peer = this;
return photo->id;
}, [](const MTPDphotoEmpty &data) {

View File

@@ -107,16 +107,16 @@ SearchResult ParseSearchResult(
switch (data.type()) {
case mtpc_messages_messages: {
auto &d = data.c_messages_messages();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
peer->owner().processUsers(d.vusers);
peer->owner().processChats(d.vchats);
result.fullCount = d.vmessages.v.size();
return &d.vmessages.v;
} break;
case mtpc_messages_messagesSlice: {
auto &d = data.c_messages_messagesSlice();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
peer->owner().processUsers(d.vusers);
peer->owner().processChats(d.vchats);
result.fullCount = d.vcount.v;
return &d.vmessages.v;
} break;
@@ -129,8 +129,8 @@ SearchResult ParseSearchResult(
LOG(("API Error: received messages.channelMessages when "
"no channel was passed! (ParseSearchResult)"));
}
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
peer->owner().processUsers(d.vusers);
peer->owner().processChats(d.vchats);
result.fullCount = d.vcount.v;
return &d.vmessages.v;
} break;
@@ -151,7 +151,7 @@ SearchResult ParseSearchResult(
auto addType = NewMessageExisting;
result.messageIds.reserve(messages->size());
for (const auto &message : *messages) {
if (auto item = Auth().data().addNewMessage(message, addType)) {
if (auto item = peer->owner().addNewMessage(message, addType)) {
auto itemId = item->id;
if ((type == Storage::SharedMediaType::kCount)
|| item->sharedMediaTypes().test(type)) {
@@ -178,9 +178,9 @@ SearchResult ParseSearchResult(
}
SearchController::CacheEntry::CacheEntry(const Query &query)
: peerData(App::peer(query.peerId))
: peerData(Auth().data().peer(query.peerId))
, migratedData(query.migratedPeerId
? base::make_optional(Data(App::peer(query.migratedPeerId)))
? base::make_optional(Data(Auth().data().peer(query.migratedPeerId)))
: std::nullopt) {
}

View File

@@ -233,7 +233,7 @@ ChannelData *Session::channelLoaded(ChannelId id) const {
return nullptr;
}
not_null<UserData*> Session::user(const MTPUser &data) {
not_null<UserData*> Session::processUser(const MTPUser &data) {
const auto result = user(data.match([](const auto &data) {
return data.vid.v;
}));
@@ -409,7 +409,7 @@ not_null<UserData*> Session::user(const MTPUser &data) {
return result;
}
not_null<PeerData*> Session::chat(const MTPChat &data) {
not_null<PeerData*> Session::processChat(const MTPChat &data) {
const auto result = data.match([&](const MTPDchat &data) {
return peer(peerFromChat(data.vid.v));
}, [&](const MTPDchatForbidden &data) {
@@ -621,7 +621,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
UserData *Session::processUsers(const MTPVector<MTPUser> &data) {
auto result = (UserData*)nullptr;
for (const auto &user : data.v) {
result = this->user(user);
result = processUser(user);
}
return result;
}
@@ -629,7 +629,7 @@ UserData *Session::processUsers(const MTPVector<MTPUser> &data) {
PeerData *Session::processChats(const MTPVector<MTPChat> &data) {
auto result = (PeerData*)nullptr;
for (const auto &chat : data.v) {
result = this->chat(chat);
result = processChat(chat);
}
return result;
}
@@ -1614,10 +1614,10 @@ not_null<PhotoData*> Session::photo(PhotoId id) {
return i->second.get();
}
not_null<PhotoData*> Session::photo(const MTPPhoto &data) {
not_null<PhotoData*> Session::processPhoto(const MTPPhoto &data) {
switch (data.type()) {
case mtpc_photo:
return photo(data.c_photo());
return processPhoto(data.c_photo());
case mtpc_photoEmpty:
return photo(data.c_photoEmpty().vid.v);
@@ -1625,13 +1625,13 @@ not_null<PhotoData*> Session::photo(const MTPPhoto &data) {
Unexpected("Type in Session::photo().");
}
not_null<PhotoData*> Session::photo(const MTPDphoto &data) {
not_null<PhotoData*> Session::processPhoto(const MTPDphoto &data) {
const auto result = photo(data.vid.v);
photoApplyFields(result, data);
return result;
}
not_null<PhotoData*> Session::photo(
not_null<PhotoData*> Session::processPhoto(
const MTPPhoto &data,
const PreparedPhotoThumbs &thumbs) {
auto thumb = (const QImage*)nullptr;
@@ -1846,10 +1846,10 @@ not_null<DocumentData*> Session::document(DocumentId id) {
return i->second.get();
}
not_null<DocumentData*> Session::document(const MTPDocument &data) {
not_null<DocumentData*> Session::processDocument(const MTPDocument &data) {
switch (data.type()) {
case mtpc_document:
return document(data.c_document());
return processDocument(data.c_document());
case mtpc_documentEmpty:
return document(data.c_documentEmpty().vid.v);
@@ -1857,13 +1857,13 @@ not_null<DocumentData*> Session::document(const MTPDocument &data) {
Unexpected("Type in Session::document().");
}
not_null<DocumentData*> Session::document(const MTPDdocument &data) {
not_null<DocumentData*> Session::processDocument(const MTPDdocument &data) {
const auto result = document(data.vid.v);
documentApplyFields(result, data);
return result;
}
not_null<DocumentData*> Session::document(
not_null<DocumentData*> Session::processDocument(
const MTPdocument &data,
QImage &&thumb) {
switch (data.type()) {
@@ -2077,10 +2077,10 @@ not_null<WebPageData*> Session::webpage(WebPageId id) {
return i->second.get();
}
not_null<WebPageData*> Session::webpage(const MTPWebPage &data) {
not_null<WebPageData*> Session::processWebpage(const MTPWebPage &data) {
switch (data.type()) {
case mtpc_webPage:
return webpage(data.c_webPage());
return processWebpage(data.c_webPage());
case mtpc_webPageEmpty: {
const auto result = webpage(data.c_webPageEmpty().vid.v);
if (result->pendingTill > 0) {
@@ -2089,7 +2089,7 @@ not_null<WebPageData*> Session::webpage(const MTPWebPage &data) {
return result;
} break;
case mtpc_webPagePending:
return webpage(data.c_webPagePending());
return processWebpage(data.c_webPagePending());
case mtpc_webPageNotModified:
LOG(("API Error: "
"webPageNotModified is unexpected in Session::webpage()."));
@@ -2098,13 +2098,13 @@ not_null<WebPageData*> Session::webpage(const MTPWebPage &data) {
Unexpected("Type in Session::webpage().");
}
not_null<WebPageData*> Session::webpage(const MTPDwebPage &data) {
not_null<WebPageData*> Session::processWebpage(const MTPDwebPage &data) {
const auto result = webpage(data.vid.v);
webpageApplyFields(result, data);
return result;
}
not_null<WebPageData*> Session::webpage(const MTPDwebPagePending &data) {
not_null<WebPageData*> Session::processWebpage(const MTPDwebPagePending &data) {
constexpr auto kDefaultPendingTimeout = 60;
const auto result = webpage(data.vid.v);
webpageApplyFields(
@@ -2203,8 +2203,10 @@ void Session::webpageApplyFields(
siteName,
data.has_title() ? qs(data.vtitle) : QString(),
description,
data.has_photo() ? photo(data.vphoto).get() : nullptr,
data.has_document() ? document(data.vdocument).get() : nullptr,
data.has_photo() ? processPhoto(data.vphoto).get() : nullptr,
(data.has_document()
? processDocument(data.vdocument).get()
: nullptr),
WebPageCollage(data),
data.has_duration() ? data.vduration.v : 0,
data.has_author() ? qs(data.vauthor) : QString(),
@@ -2255,7 +2257,7 @@ not_null<GameData*> Session::game(GameId id) {
return i->second.get();
}
not_null<GameData*> Session::game(const MTPDgame &data) {
not_null<GameData*> Session::processGame(const MTPDgame &data) {
const auto result = game(data.vid.v);
gameApplyFields(result, data);
return result;
@@ -2316,8 +2318,10 @@ void Session::gameApplyFields(
qs(data.vshort_name),
qs(data.vtitle),
qs(data.vdescription),
photo(data.vphoto),
data.has_document() ? document(data.vdocument).get() : nullptr);
processPhoto(data.vphoto),
(data.has_document()
? processDocument(data.vdocument).get()
: nullptr));
}
void Session::gameApplyFields(
@@ -2348,7 +2352,7 @@ not_null<PollData*> Session::poll(PollId id) {
return i->second.get();
}
not_null<PollData*> Session::poll(const MTPPoll &data) {
not_null<PollData*> Session::processPoll(const MTPPoll &data) {
return data.match([&](const MTPDpoll &data) {
const auto id = data.vid.v;
const auto result = poll(id);
@@ -2360,8 +2364,8 @@ not_null<PollData*> Session::poll(const MTPPoll &data) {
});
}
not_null<PollData*> Session::poll(const MTPDmessageMediaPoll &data) {
const auto result = poll(data.vpoll);
not_null<PollData*> Session::processPoll(const MTPDmessageMediaPoll &data) {
const auto result = processPoll(data.vpoll);
const auto changed = result->applyResults(data.vresults);
if (changed) {
notifyPollUpdateDelayed(result);
@@ -2375,7 +2379,7 @@ void Session::applyUpdate(const MTPDupdateMessagePoll &update) {
return (i == end(_polls))
? nullptr
: update.has_poll()
? poll(update.vpoll).get()
? processPoll(update.vpoll).get()
: i->second.get();
}();
if (updated && updated->applyResults(update.vresults)) {
@@ -2949,7 +2953,7 @@ void Session::serviceNotification(
const MTPMessageMedia &media) {
const auto date = unixtime();
if (!userLoaded(ServiceUserId)) {
user(MTP_user(
processUser(MTP_user(
MTP_flags(
MTPDuser::Flag::f_first_name
| MTPDuser::Flag::f_phone
@@ -3098,7 +3102,7 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
}
for (const auto &paper : data) {
paper.match([&](const MTPDwallPaper &paper) {
const auto document = this->document(paper.vdocument);
const auto document = processDocument(paper.vdocument);
if (document->checkWallPaperProperties()) {
_wallpapers.push_back({
paper.vid.v,

View File

@@ -84,17 +84,25 @@ public:
Storage::Cache::Database &cache();
[[nodiscard]] not_null<PeerData*> peer(PeerId id);
[[nodiscard]] not_null<PeerData*> peer(UserId id) = delete;
[[nodiscard]] not_null<UserData*> user(UserId id);
[[nodiscard]] not_null<ChatData*> chat(ChatId id);
[[nodiscard]] not_null<ChannelData*> channel(ChannelId id);
[[nodiscard]] not_null<UserData*> user(PeerId id) = delete;
[[nodiscard]] not_null<ChatData*> chat(PeerId id) = delete;
[[nodiscard]] not_null<ChannelData*> channel(PeerId id) = delete;
[[nodiscard]] PeerData *peerLoaded(PeerId id) const;
[[nodiscard]] PeerData *peerLoaded(UserId id) const = delete;
[[nodiscard]] UserData *userLoaded(UserId id) const;
[[nodiscard]] ChatData *chatLoaded(ChatId id) const;
[[nodiscard]] ChannelData *channelLoaded(ChannelId id) const;
[[nodiscard]] UserData *userLoaded(PeerId id) const = delete;
[[nodiscard]] ChatData *chatLoaded(PeerId id) const = delete;
[[nodiscard]] ChannelData *channelLoaded(PeerId id) const = delete;
not_null<UserData*> user(const MTPUser &data);
not_null<PeerData*> chat(const MTPChat &data);
not_null<UserData*> processUser(const MTPUser &data);
not_null<PeerData*> processChat(const MTPChat &data);
// Returns last user, if there were any.
UserData *processUsers(const MTPVector<MTPUser> &data);
@@ -107,10 +115,12 @@ public:
void enumerateChannels(Fn<void(not_null<ChannelData*>)> action) const;
[[nodiscard]] PeerData *peerByUsername(const QString &username) const;
not_null<History*> history(PeerId peerId);
History *historyLoaded(PeerId peerId) const;
not_null<History*> history(not_null<const PeerData*> peer);
History *historyLoaded(const PeerData *peer);
[[nodiscard]] not_null<History*> history(PeerId peerId);
[[nodiscard]] History *historyLoaded(PeerId peerId) const;
[[nodiscard]] not_null<History*> history(UserId userId) = delete;
[[nodiscard]] History *historyLoaded(UserId userId) const = delete;
[[nodiscard]] not_null<History*> history(not_null<const PeerData*> peer);
[[nodiscard]] History *historyLoaded(const PeerData *peer);
void registerSendAction(
not_null<History*> history,
@@ -307,8 +317,6 @@ public:
-> rpl::producer<SendActionAnimationUpdate>;
void updateSendActionAnimation(SendActionAnimationUpdate &&update);
void updateSendActionAnimation();
int unreadBadge() const;
bool unreadBadgeMuted() const;
int unreadBadgeIgnoreOne(History *history) const;
@@ -323,13 +331,13 @@ public:
void selfDestructIn(not_null<HistoryItem*> item, TimeMs delay);
not_null<PhotoData*> photo(PhotoId id);
not_null<PhotoData*> photo(const MTPPhoto &data);
not_null<PhotoData*> photo(const MTPDphoto &data);
not_null<PhotoData*> photo(
[[nodiscard]] not_null<PhotoData*> photo(PhotoId id);
not_null<PhotoData*> processPhoto(const MTPPhoto &data);
not_null<PhotoData*> processPhoto(const MTPDphoto &data);
not_null<PhotoData*> processPhoto(
const MTPPhoto &data,
const PreparedPhotoThumbs &thumbs);
not_null<PhotoData*> photo(
[[nodiscard]] not_null<PhotoData*> photo(
PhotoId id,
const uint64 &access,
const QByteArray &fileReference,
@@ -340,18 +348,18 @@ public:
void photoConvert(
not_null<PhotoData*> original,
const MTPPhoto &data);
PhotoData *photoFromWeb(
[[nodiscard]] PhotoData *photoFromWeb(
const MTPWebDocument &data,
ImagePtr thumb = ImagePtr(),
bool willBecomeNormal = false);
not_null<DocumentData*> document(DocumentId id);
not_null<DocumentData*> document(const MTPDocument &data);
not_null<DocumentData*> document(const MTPDdocument &data);
not_null<DocumentData*> document(
[[nodiscard]] not_null<DocumentData*> document(DocumentId id);
not_null<DocumentData*> processDocument(const MTPDocument &data);
not_null<DocumentData*> processDocument(const MTPDdocument &data);
not_null<DocumentData*> processDocument(
const MTPdocument &data,
QImage &&thumb);
not_null<DocumentData*> document(
[[nodiscard]] not_null<DocumentData*> document(
DocumentId id,
const uint64 &access,
const QByteArray &fileReference,
@@ -365,19 +373,19 @@ public:
void documentConvert(
not_null<DocumentData*> original,
const MTPDocument &data);
DocumentData *documentFromWeb(
[[nodiscard]] DocumentData *documentFromWeb(
const MTPWebDocument &data,
ImagePtr thumb);
not_null<WebPageData*> webpage(WebPageId id);
not_null<WebPageData*> webpage(const MTPWebPage &data);
not_null<WebPageData*> webpage(const MTPDwebPage &data);
not_null<WebPageData*> webpage(const MTPDwebPagePending &data);
not_null<WebPageData*> webpage(
[[nodiscard]] not_null<WebPageData*> webpage(WebPageId id);
not_null<WebPageData*> processWebpage(const MTPWebPage &data);
not_null<WebPageData*> processWebpage(const MTPDwebPage &data);
not_null<WebPageData*> processWebpage(const MTPDwebPagePending &data);
[[nodiscard]] not_null<WebPageData*> webpage(
WebPageId id,
const QString &siteName,
const TextWithEntities &content);
not_null<WebPageData*> webpage(
[[nodiscard]] not_null<WebPageData*> webpage(
WebPageId id,
WebPageType type,
const QString &url,
@@ -392,9 +400,9 @@ public:
const QString &author,
TimeId pendingTill);
not_null<GameData*> game(GameId id);
not_null<GameData*> game(const MTPDgame &data);
not_null<GameData*> game(
[[nodiscard]] not_null<GameData*> game(GameId id);
not_null<GameData*> processGame(const MTPDgame &data);
[[nodiscard]] not_null<GameData*> game(
GameId id,
const uint64 &accessHash,
const QString &shortName,
@@ -406,11 +414,12 @@ public:
not_null<GameData*> original,
const MTPGame &data);
not_null<PollData*> poll(PollId id);
not_null<PollData*> poll(const MTPPoll &data);
not_null<PollData*> poll(const MTPDmessageMediaPoll &data);
[[nodiscard]] not_null<PollData*> poll(PollId id);
not_null<PollData*> processPoll(const MTPPoll &data);
not_null<PollData*> processPoll(const MTPDmessageMediaPoll &data);
not_null<LocationData*> location(const LocationCoords &coords);
[[nodiscard]] not_null<LocationData*> location(
const LocationCoords &coords);
void registerPhotoItem(
not_null<const PhotoData*> photo,

View File

@@ -76,7 +76,7 @@ rpl::producer<SparseIdsSlice> SharedMediaViewer(
limitBefore,
limitAfter);
auto requestMediaAround = [
peer = App::peer(key.peerId),
peer = Auth().data().peer(key.peerId),
type = key.type
](const SparseIdsSliceBuilder::AroundData &data) {
Auth().api().requestSharedMedia(
@@ -313,7 +313,7 @@ void SharedMediaWithLastSlice::reverse() {
std::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId(
PeerId peerId) {
if (auto peer = App::peerLoaded(peerId)) {
if (const auto peer = Auth().data().peerLoaded(peerId)) {
return peer->userpicPhotoUnknown()
? std::nullopt
: base::make_optional(peer->userpicPhotoId());

View File

@@ -144,7 +144,7 @@ public:
return canShareThisContact() && !isContact();
}
// In feedUsers() we check only that.
// In Data::Session::processUsers() we check only that.
// When actually trying to share contact we perform
// a full check by canShareThisContact() call.
bool canShareThisContactFast() const {

View File

@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "auth_session.h"
#include "apiwrap.h"
#include "data/data_session.h"
#include "storage/storage_facade.h"
#include "storage/storage_user_photos.h"
@@ -207,7 +208,7 @@ rpl::producer<UserPhotosSlice> UserPhotosViewer(
consumer.put_next(builder->snapshot());
}
};
auto requestPhotosAround = [user = App::user(key.userId)](
auto requestPhotosAround = [user = Auth().data().user(key.userId)](
PhotoId photoId) {
Auth().api().requestUserPhotos(user, photoId);
};

View File

@@ -53,10 +53,10 @@ WebPageCollage ExtractCollage(
auto &storage = Auth().data();
for (const auto &photo : photos) {
storage.photo(photo);
storage.processPhoto(photo);
}
for (const auto &document : documents) {
storage.document(document);
storage.processDocument(document);
}
auto result = WebPageCollage();
result.items.reserve(count);
@@ -89,12 +89,12 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) {
if (!data.has_cached_page()) {
return {};
}
const auto parseMedia = [&] {
const auto processMedia = [&] {
if (data.has_photo()) {
Auth().data().photo(data.vphoto);
Auth().data().processPhoto(data.vphoto);
}
if (data.has_document()) {
Auth().data().document(data.vdocument);
Auth().data().processDocument(data.vdocument);
}
};
return data.vcached_page.match([&](const auto &page) {
@@ -108,13 +108,13 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) {
case mtpc_pageBlockAudio:
return WebPageCollage();
case mtpc_pageBlockSlideshow:
parseMedia();
processMedia();
return ExtractCollage(
block.c_pageBlockSlideshow().vitems.v,
page.vphotos.v,
page.vdocuments.v);
case mtpc_pageBlockCollage:
parseMedia();
processMedia();
return ExtractCollage(
block.c_pageBlockCollage().vitems.v,
page.vphotos.v,