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

@ -266,12 +266,12 @@ void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) {
proxy.match([&](const MTPDhelp_proxyDataEmpty &data) {
_session->data().setProxyPromoted(nullptr);
}, [&](const MTPDhelp_proxyDataPromo &data) {
App::feedChats(data.vchats);
App::feedUsers(data.vusers);
_session->data().processChats(data.vchats);
_session->data().processUsers(data.vusers);
const auto peerId = peerFromMTP(data.vpeer);
const auto peer = _session->data().peer(peerId);
_session->data().setProxyPromoted(peer);
if (const auto history = App::historyLoaded(peer)) {
if (const auto history = _session->data().historyLoaded(peer)) {
requestDialogEntry(history);
}
});
@ -378,7 +378,7 @@ void ApiWrap::importChatInvite(const QString &hash) {
}, [](auto&&) {
return PeerId(0);
});
if (const auto peer = App::peerLoaded(peerId)) {
if (const auto peer = _session->data().peerLoaded(peerId)) {
App::wnd()->controller()->showPeerHistory(
peer,
Window::SectionShow::Way::Forward);
@ -563,8 +563,8 @@ void ApiWrap::resolveMessageDatas() {
void ApiWrap::gotMessageDatas(ChannelData *channel, const MTPmessages_Messages &msgs, mtpRequestId requestId) {
auto handleResult = [&](auto &&result) {
App::feedUsers(result.vusers);
App::feedChats(result.vchats);
_session->data().processUsers(result.vusers);
_session->data().processChats(result.vchats);
App::feedMsgs(result.vmessages, NewMessageExisting);
};
switch (msgs.type()) {
@ -624,7 +624,7 @@ void ApiWrap::requestContacts() {
}
Assert(result.type() == mtpc_contacts_contacts);
const auto &d = result.c_contacts_contacts();
App::feedUsers(d.vusers);
_session->data().processUsers(d.vusers);
for (const auto &contact : d.vcontacts.v) {
if (contact.type() != mtpc_contact) continue;
@ -763,15 +763,15 @@ void ApiWrap::applyPeerDialogs(const MTPmessages_PeerDialogs &dialogs) {
Expects(dialogs.type() == mtpc_messages_peerDialogs);
const auto &data = dialogs.c_messages_peerDialogs();
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
_session->data().processUsers(data.vusers);
_session->data().processChats(data.vchats);
App::feedMsgs(data.vmessages, NewMessageLast);
for (const auto &dialog : data.vdialogs.v) {
switch (dialog.type()) {
case mtpc_dialog: {
const auto &fields = dialog.c_dialog();
if (const auto peerId = peerFromMTP(fields.vpeer)) {
App::history(peerId)->applyDialog(fields);
_session->data().history(peerId)->applyDialog(fields);
}
} break;
@ -798,15 +798,15 @@ void ApiWrap::applyFeedDialogs(
dialogs.match([&](const MTPDmessages_dialogsNotModified &) {
Unexpected("Type in ApiWrap::applyFeedDialogs.");
}, [&](const auto &data) {
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
_session->data().processUsers(data.vusers);
_session->data().processChats(data.vchats);
App::feedMsgs(data.vmessages.v, NewMessageLast);
channels.reserve(data.vdialogs.v.size());
for (const auto &dialog : data.vdialogs.v) {
dialog.match([&](const MTPDdialog &data) {
if (const auto peerId = peerFromMTP(data.vpeer)) {
if (peerIsChannel(peerId)) {
const auto history = App::history(peerId);
const auto history = _session->data().history(peerId);
history->applyDialog(dialog.c_dialog());
channels.emplace_back(history->peer->asChannel());
} else {
@ -886,7 +886,8 @@ void ApiWrap::requestWallPaper(
_wallPaperRequestId = 0;
_wallPaperSlug = QString();
result.match([&](const MTPDwallPaper &data) {
const auto document = _session->data().document(data.vdocument);
const auto document = _session->data().processDocument(
data.vdocument);
if (document->checkWallPaperProperties()) {
if (const auto done = base::take(_wallPaperDone)) {
done({
@ -972,8 +973,8 @@ void ApiWrap::gotChatFull(
const auto &d = result.c_messages_chatFull();
_session->data().applyMaximumChatVersions(d.vchats);
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_session->data().processUsers(d.vusers);
_session->data().processChats(d.vchats);
using UpdateFlag = Notify::PeerUpdate::Flag;
if (const auto chat = peer->asChat()) {
@ -987,7 +988,7 @@ void ApiWrap::gotChatFull(
if (f.has_bot_info()) {
for (const auto &item : f.vbot_info.v) {
item.match([&](const MTPDbotInfo &data) {
if (const auto bot = App::userLoaded(data.vuser_id.v)) {
if (const auto bot = _session->data().userLoaded(data.vuser_id.v)) {
bot->setBotInfo(item);
fullPeerUpdated().notify(bot);
}
@ -1029,7 +1030,7 @@ void ApiWrap::gotChatFull(
if (f.has_migrated_from_chat_id()) {
channel->addFlags(MTPDchannel::Flag::f_megagroup);
const auto chat = channel->owner().chat(
peerFromChat(f.vmigrated_from_chat_id));
f.vmigrated_from_chat_id.v);
Data::ApplyMigration(chat, channel);
}
for (const auto &item : f.vbot_info.v) {
@ -1047,7 +1048,7 @@ void ApiWrap::gotChatFull(
channel->setRestrictedCount(f.has_banned_count() ? f.vbanned_count.v : 0);
channel->setKickedCount(f.has_kicked_count() ? f.vkicked_count.v : 0);
channel->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString());
if (const auto history = App::historyLoaded(channel->id)) {
if (const auto history = _session->data().historyLoaded(channel)) {
history->clearUpTill(f.vavailable_min_id.v);
history->applyDialogFields(
f.vunread_count.v,
@ -1108,9 +1109,9 @@ void ApiWrap::gotUserFull(
});
return;
}
App::feedUsers(MTP_vector<MTPUser>(1, d.vuser));
_session->data().processUser(d.vuser);
if (d.has_profile_photo()) {
_session->data().photo(d.vprofile_photo);
_session->data().processPhoto(d.vprofile_photo);
}
App::feedUserLink(MTP_int(peerToUser(user->id)), d.vlink.c_contacts_link().vmy_link, d.vlink.c_contacts_link().vforeign_link);
if (App::main()) {
@ -1158,14 +1159,14 @@ void ApiWrap::requestPeer(not_null<PeerData*> peer) {
return data.vchats;
});
_session->data().applyMaximumChatVersions(chats);
App::feedChats(chats);
_session->data().processChats(chats);
};
if (const auto user = peer->asUser()) {
return request(MTPusers_GetUsers(
MTP_vector<MTPInputUser>(1, user->inputUser)
)).done([=](const MTPVector<MTPUser> &result) {
_peerRequests.remove(user);
App::feedUsers(result);
_session->data().processUsers(result);
}).fail(failHandler).send();
} else if (const auto chat = peer->asChat()) {
return request(MTPmessages_GetChats(
@ -1352,7 +1353,7 @@ void ApiWrap::requestPeers(const QList<PeerData*> &peers) {
}
}
const auto handleChats = [=](const MTPmessages_Chats &result) {
App::feedChats(result.match([](const auto &data) {
_session->data().processChats(result.match([](const auto &data) {
return data.vchats;
}));
};
@ -1370,7 +1371,7 @@ void ApiWrap::requestPeers(const QList<PeerData*> &peers) {
request(MTPusers_GetUsers(
MTP_vector<MTPInputUser>(users)
)).done([=](const MTPVector<MTPUser> &result) {
App::feedUsers(result);
_session->data().processUsers(result);
}).send();
}
}
@ -1452,7 +1453,7 @@ void ApiWrap::requestAdmins(not_null<ChannelData*> channel) {
)).done([this, channel](const MTPchannels_ChannelParticipants &result) {
_adminsRequests.remove(channel);
result.match([&](const MTPDchannels_channelParticipants &data) {
App::feedUsers(data.vusers);
_session->data().processUsers(data.vusers);
applyAdminsList(
channel,
data.vcount.v,
@ -1498,7 +1499,7 @@ void ApiWrap::applyLastParticipantsList(
continue;
}
auto user = App::user(userId);
auto user = _session->data().user(userId);
if (p.type() == mtpc_channelParticipantCreator) {
channel->mgInfo->creator = user;
if (!channel->mgInfo->admins.empty()
@ -1550,7 +1551,7 @@ void ApiWrap::applyBotsList(
not_null<ChannelData*> channel,
int availableCount,
const QVector<MTPChannelParticipant> &list) {
const auto history = App::historyLoaded(channel->id);
const auto history = _session->data().historyLoaded(channel);
channel->mgInfo->bots.clear();
channel->mgInfo->botStatus = -1;
@ -1565,7 +1566,7 @@ void ApiWrap::applyBotsList(
continue;
}
auto user = App::user(userId);
auto user = _session->data().user(userId);
if (user->botInfo) {
channel->mgInfo->bots.insert(user);
botStatus = 2;// (botStatus > 0/* || !i.key()->botInfo->readsAllHistory*/) ? 2 : 1;
@ -1629,7 +1630,7 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
const auto finalize = [=](UserId inviter, TimeId inviteDate) {
channel->inviter = inviter;
channel->inviteDate = inviteDate;
if (const auto history = App::historyLoaded(channel)) {
if (const auto history = _session->data().historyLoaded(channel)) {
if (history->lastMessageKnown()) {
history->checkJoinedMessage(true);
history->owner().sendHistoryChangeNotifications();
@ -1645,7 +1646,7 @@ void ApiWrap::requestSelfParticipant(not_null<ChannelData*> channel) {
)).done([=](const MTPchannels_ChannelParticipant &result) {
_selfParticipantRequests.erase(channel);
result.match([&](const MTPDchannels_channelParticipant &data) {
App::feedUsers(data.vusers);
_session->data().processUsers(data.vusers);
const auto &participant = data.vparticipant;
participant.match([&](const MTPDchannelParticipantSelf &data) {
@ -1778,7 +1779,7 @@ void ApiWrap::saveDefaultRestrictions(
void ApiWrap::deleteAllFromUser(
not_null<ChannelData*> channel,
not_null<UserData*> from) {
const auto history = App::historyLoaded(channel->id);
const auto history = _session->data().historyLoaded(channel);
const auto ids = history
? history->collectMessagesFromUserToDelete(from)
: QVector<MsgId>();
@ -1804,7 +1805,7 @@ void ApiWrap::deleteAllFromUserSend(
const auto offset = applyAffectedHistory(channel, result);
if (offset > 0) {
deleteAllFromUserSend(channel, from);
} else if (const auto history = App::historyLoaded(channel)) {
} else if (const auto history = _session->data().historyLoaded(channel)) {
history->requestChatListMessage();
}
}).send();
@ -2196,7 +2197,7 @@ void ApiWrap::savePrivacy(const MTPInputPrivacyKey &key, QVector<MTPInputPrivacy
Expects(result.type() == mtpc_account_privacyRules);
auto &rules = result.c_account_privacyRules();
App::feedUsers(rules.vusers);
_session->data().processUsers(rules.vusers);
_privacySaveRequests.remove(keyTypeId);
handlePrivacyChange(keyTypeId, rules.vrules);
}).fail([=](const RPCError &error) {
@ -2306,7 +2307,7 @@ void ApiWrap::updatePrivacyLastSeens(const QVector<MTPPrivacyRule> &rules) {
for_const (auto &item, result.v) {
Assert(item.type() == mtpc_contactStatus);
auto &data = item.c_contactStatus();
if (auto user = App::userLoaded(data.vuser_id.v)) {
if (auto user = _session->data().userLoaded(data.vuser_id.v)) {
auto oldOnlineTill = user->onlineTill;
auto newOnlineTill = OnlineTillFromStatus(data.vstatus, oldOnlineTill);
if (oldOnlineTill != newOnlineTill) {
@ -2338,7 +2339,7 @@ int ApiWrap::OnlineTillFromStatus(
void ApiWrap::clearHistory(not_null<PeerData*> peer) {
auto deleteTillId = MsgId(0);
if (const auto history = App::historyLoaded(peer->id)) {
if (const auto history = _session->data().historyLoaded(peer)) {
if (const auto last = history->lastMessage()) {
deleteTillId = last->id;
}
@ -2704,8 +2705,8 @@ void ApiWrap::channelRangeDifferenceDone(
case mtpc_updates_channelDifferenceTooLong: {
const auto &d = result.c_updates_channelDifferenceTooLong();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_session->data().processUsers(d.vusers);
_session->data().processChats(d.vchats);
nextRequestPts = d.vpts.v;
isFinal = d.is_final();
@ -2829,7 +2830,7 @@ void ApiWrap::refreshFileReference(
fail();
}
}, [&](Data::FileOriginUserPhoto data) {
if (const auto user = App::user(data.userId)) {
if (const auto user = _session->data().user(data.userId)) {
request(MTPphotos_GetUserPhotos(
user->inputUser,
MTP_int(-1),
@ -2839,7 +2840,7 @@ void ApiWrap::refreshFileReference(
fail();
}
}, [&](Data::FileOriginPeerPhoto data) {
if (const auto peer = App::peer(data.peerId)) {
if (const auto peer = _session->data().peer(data.peerId)) {
if (const auto user = peer->asUser()) {
request(MTPusers_GetUsers(
MTP_vector<MTPInputUser>(1, user->inputUser)));
@ -2895,15 +2896,15 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
switch (msgs.type()) {
case mtpc_messages_messages: {
auto &d = msgs.c_messages_messages();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_session->data().processUsers(d.vusers);
_session->data().processChats(d.vchats);
v = &d.vmessages.v;
} break;
case mtpc_messages_messagesSlice: {
auto &d = msgs.c_messages_messagesSlice();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_session->data().processUsers(d.vusers);
_session->data().processChats(d.vchats);
v = &d.vmessages.v;
} break;
@ -2914,8 +2915,8 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
} else {
LOG(("API Error: received messages.channelMessages when no channel was passed! (ApiWrap::gotWebPages)"));
}
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_session->data().processUsers(d.vusers);
_session->data().processChats(d.vchats);
v = &d.vmessages.v;
} break;
@ -3023,7 +3024,8 @@ std::vector<not_null<DocumentData*>> *ApiWrap::stickersByEmoji(
entry.list.clear();
entry.list.reserve(data.vstickers.v.size());
for (const auto &sticker : data.vstickers.v) {
const auto document = _session->data().document(sticker);
const auto document = _session->data().processDocument(
sticker);
if (document->sticker()) {
entry.list.push_back(document);
}
@ -3311,7 +3313,7 @@ void ApiWrap::parseChannelParticipants(
const QVector<MTPChannelParticipant> &list)> callbackList,
Fn<void()> callbackNotModified) {
result.match([&](const MTPDchannels_channelParticipants &data) {
App::feedUsers(data.vusers);
_session->data().processUsers(data.vusers);
if (channel->mgInfo) {
refreshChannelAdmins(channel, data.vparticipants.v);
}
@ -3557,14 +3559,13 @@ void ApiWrap::requestMessageAfterDate(
MTP_int(minId),
MTP_int(historyHash)
)).done([
peer,
offsetDate,
=,
callback = std::forward<Callback>(callback)
](const MTPmessages_Messages &result) {
auto getMessagesList = [&result, peer]() -> const QVector<MTPMessage>* {
auto handleMessages = [](auto &messages) {
App::feedUsers(messages.vusers);
App::feedChats(messages.vchats);
auto getMessagesList = [&]() -> const QVector<MTPMessage>* {
auto handleMessages = [&](auto &messages) {
_session->data().processUsers(messages.vusers);
_session->data().processChats(messages.vchats);
return &messages.vmessages.v;
};
switch (result.type()) {
@ -3660,8 +3661,8 @@ void ApiWrap::requestMessageAfterDate(
// const auto &data = result.c_messages_feedMessages();
// const auto &messages = data.vmessages.v;
// const auto type = NewMessageExisting;
// App::feedUsers(data.vusers);
// App::feedChats(data.vchats);
// _session->data().processUsers(data.vusers);
// _session->data().processChats(data.vchats);
// for (const auto &msg : messages) {
// if (const auto item = _session->data().addNewMessage(msg, type)) {
// if (item->date() >= offsetDate || true) {
@ -3863,14 +3864,14 @@ void ApiWrap::userPhotosDone(
switch (result.type()) {
case mtpc_photos_photos: {
auto &d = result.c_photos_photos();
App::feedUsers(d.vusers);
_session->data().processUsers(d.vusers);
fullCount = d.vphotos.v.size();
return &d.vphotos.v;
} break;
case mtpc_photos_photosSlice: {
auto &d = result.c_photos_photosSlice();
App::feedUsers(d.vusers);
_session->data().processUsers(d.vusers);
fullCount = d.vcount.v;
return &d.vphotos.v;
} break;
@ -3881,7 +3882,7 @@ void ApiWrap::userPhotosDone(
auto photoIds = std::vector<PhotoId>();
photoIds.reserve(photos.size());
for (auto &photo : photos) {
if (auto photoData = _session->data().photo(photo)) {
if (auto photoData = _session->data().processPhoto(photo)) {
photoIds.push_back(photoData->id);
}
}
@ -3943,14 +3944,14 @@ void ApiWrap::userPhotosDone(
// const auto feed = _session->data().feed(feedId);
// auto channels = std::vector<not_null<ChannelData*>>();
// for (const auto &channelId : list.vchannels.v) {
// channels.push_back(App::channel(channelId.v));
// channels.push_back(_session->data().channel(channelId.v));
// }
// feed->setChannels(std::move(channels));
// }
// }
//
// App::feedUsers(data.vusers);
// App::feedChats(data.vchats);
// _session->data().processUsers(data.vusers);
// _session->data().processChats(data.vchats);
//
// if (data.has_newly_joined_feed()) {
// _session->data().setDefaultFeedId(
@ -4085,8 +4086,8 @@ void ApiWrap::userPhotosDone(
// const auto tooSmallPosition = [&](const auto &position) {
// return (slice == SliceType::After) && !(messageId < position);
// };
// App::feedUsers(data.vusers);
// App::feedChats(data.vchats);
// _session->data().processUsers(data.vusers);
// _session->data().processChats(data.vchats);
// if (!messages.empty()) {
// ids.reserve(messages.size());
// for (const auto &msg : messages) {
@ -4662,7 +4663,7 @@ void ApiWrap::sendBotStart(not_null<UserData*> bot, PeerData *chat) {
auto &info = bot->botInfo;
auto &token = chat ? info->startGroupToken : info->startToken;
if (token.isEmpty()) {
auto message = ApiWrap::MessageToSend(App::history(bot));
auto message = ApiWrap::MessageToSend(_session->data().history(bot));
message.textWithTags = { qsl("/start"), TextWithTags::Tags() };
sendMessage(std::move(message));
return;
@ -5135,18 +5136,18 @@ void ApiWrap::photoUploadReady(
file
)).done([=](const MTPphotos_Photo &result) {
result.match([&](const MTPDphotos_photo &data) {
_session->data().photo(data.vphoto);
App::feedUsers(data.vusers);
_session->data().processPhoto(data.vphoto);
_session->data().processUsers(data.vusers);
});
}).send();
} else if (const auto chat = peer->asChat()) {
const auto history = App::history(chat);
const auto history = _session->data().history(chat);
history->sendRequestId = request(MTPmessages_EditChatPhoto(
chat->inputChat,
MTP_inputChatUploadedPhoto(file)
)).done(applier).afterRequest(history->sendRequestId).send();
} else if (const auto channel = peer->asChannel()) {
const auto history = App::history(channel);
const auto history = _session->data().history(channel);
history->sendRequestId = request(MTPchannels_EditPhoto(
channel->inputChannel,
MTP_inputChatUploadedPhoto(file)
@ -5298,7 +5299,7 @@ void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) {
)).done([=](const MTPUser &result) {
_saveBioRequestId = 0;
App::feedUsers(MTP_vector<MTPUser>(1, result));
_session->data().processUsers(MTP_vector<MTPUser>(1, result));
_session->user()->setAbout(_saveBioText);
if (_saveBioDone) {
_saveBioDone();
@ -5317,7 +5318,7 @@ void ApiWrap::reloadPrivacy(Privacy::Key key) {
)).done([=](const MTPaccount_PrivacyRules &result) {
_privacyRequestIds.erase(key);
result.match([&](const MTPDaccount_privacyRules &data) {
App::feedUsers(data.vusers);
_session->data().processUsers(data.vusers);
pushPrivacy(key, data.vrules.v);
});
}).fail([=](const RPCError &error) {
@ -5351,7 +5352,7 @@ auto ApiWrap::parsePrivacy(const QVector<MTPPrivacyRule> &rules)
const auto &users = data.vusers.v;
always.reserve(always.size() + users.size());
for (const auto userId : users) {
const auto user = App::user(UserId(userId.v));
const auto user = _session->data().user(UserId(userId.v));
if (!base::contains(never, user)
&& !base::contains(always, user)) {
always.push_back(user);
@ -5365,7 +5366,7 @@ auto ApiWrap::parsePrivacy(const QVector<MTPPrivacyRule> &rules)
const auto &users = data.vusers.v;
never.reserve(never.size() + users.size());
for (const auto userId : users) {
const auto user = App::user(UserId(userId.v));
const auto user = _session->data().user(UserId(userId.v));
if (!base::contains(always, user)
&& !base::contains(never, user)) {
never.push_back(user);
@ -5589,7 +5590,7 @@ void ApiWrap::readServerHistoryForce(not_null<History*> history) {
if (!channel->amIn()) {
return; // no read request for channels that I didn't join
} else if (const auto migrateFrom = channel->migrateFrom()) {
if (const auto migrated = App::historyLoaded(migrateFrom)) {
if (const auto migrated = _session->data().historyLoaded(migrateFrom)) {
readServerHistory(migrated);
}
}

View file

@ -130,22 +130,6 @@ namespace App {
return nullptr;
}
UserData *feedUser(const MTPUser &user) {
return Auth().data().user(user);
}
UserData *feedUsers(const MTPVector<MTPUser> &users) {
return Auth().data().processUsers(users);
}
PeerData *feedChat(const MTPChat &chat) {
return Auth().data().chat(chat);
}
PeerData *feedChats(const MTPVector<MTPChat> &chats) {
return Auth().data().processChats(chats);
}
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m) {
auto peerId = peerFromMTP(m.vto_id);
if (m.has_from_id() && peerId == Auth().userPeerId()) {
@ -337,13 +321,13 @@ namespace App {
}
void feedInboxRead(const PeerId &peer, MsgId upTo) {
if (const auto history = App::historyLoaded(peer)) {
if (const auto history = Auth().data().historyLoaded(peer)) {
history->inboxRead(upTo);
}
}
void feedOutboxRead(const PeerId &peer, MsgId upTo, TimeId when) {
if (auto history = App::historyLoaded(peer)) {
if (auto history = Auth().data().historyLoaded(peer)) {
history->outboxRead(upTo);
if (const auto user = history->peer->asUser()) {
user->madeAction(when);
@ -371,7 +355,7 @@ namespace App {
if (!data) return;
const auto affectedHistory = (channelId != NoChannel)
? App::history(peerFromChannel(channelId)).get()
? Auth().data().history(peerFromChannel(channelId)).get()
: nullptr;
auto historiesToCheck = base::flat_set<not_null<History*>>();
@ -393,7 +377,7 @@ namespace App {
}
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) {
if (const auto user = userLoaded(userId.v)) {
if (const auto user = Auth().data().userLoaded(userId.v)) {
const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd);
switch (myLink.type()) {
case mtpc_contactLinkContact:
@ -431,51 +415,10 @@ namespace App {
}
}
not_null<PeerData*> peer(PeerId id) {
return Auth().data().peer(id);
}
not_null<UserData*> user(UserId id) {
return Auth().data().user(id);
}
not_null<ChatData*> chat(ChatId id) {
return Auth().data().chat(id);
}
not_null<ChannelData*> channel(ChannelId id) {
return Auth().data().channel(id);
}
PeerData *peerLoaded(PeerId id) {
return Auth().data().peerLoaded(id);
}
UserData *userLoaded(UserId id) {
return Auth().data().userLoaded(id);
}
ChatData *chatLoaded(ChatId id) {
return Auth().data().chatLoaded(id);
}
ChannelData *channelLoaded(ChannelId id) {
return Auth().data().channelLoaded(id);
}
QString peerName(const PeerData *peer, bool forDialogs) {
return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : lang(lng_deleted);
}
not_null<History*> history(PeerId peer) {
return Auth().data().history(peer);
}
History *historyLoaded(PeerId peer) {
return Auth().data().historyLoaded(peer);
}
not_null<History*> history(not_null<const PeerData*> peer) {
return history(peer->id);
}
History *historyLoaded(const PeerData *peer) {
return peer ? historyLoaded(peer->id) : nullptr;
}
HistoryItem *histItemById(ChannelId channelId, MsgId itemId) {
if (!itemId) return nullptr;

View file

@ -65,11 +65,6 @@ namespace App {
QString formatPhone(QString phone);
UserData *feedUser(const MTPUser &user);
UserData *feedUsers(const MTPVector<MTPUser> &users); // returns last user
PeerData *feedChat(const MTPChat &chat);
PeerData *feedChats(const MTPVector<MTPChat> &chats); // returns last chat
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
void updateEditedMessage(const MTPMessage &m);
void addSavedGif(DocumentData *doc);
@ -83,22 +78,9 @@ namespace App {
ImagePtr image(const MTPPhotoSize &size);
[[nodiscard]] not_null<PeerData*> peer(PeerId id);
[[nodiscard]] not_null<UserData*> user(UserId userId);
[[nodiscard]] not_null<ChatData*> chat(ChatId chatId);
[[nodiscard]] not_null<ChannelData*> channel(ChannelId channelId);
[[nodiscard]] PeerData *peerLoaded(PeerId id);
[[nodiscard]] UserData *userLoaded(UserId userId);
[[nodiscard]] ChatData *chatLoaded(ChatId chatId);
[[nodiscard]] ChannelData *channelLoaded(ChannelId channelId);
[[nodiscard]] QString peerName(const PeerData *peer, bool forDialogs = false);
[[nodiscard]] not_null<History*> history(PeerId peer);
[[nodiscard]] History *historyLoaded(PeerId peer);
[[nodiscard]] HistoryItem *histItemById(ChannelId channelId, MsgId itemId);
[[nodiscard]] not_null<History*> history(not_null<const PeerData*> peer);
[[nodiscard]] History *historyLoaded(const PeerData *peer);
[[nodiscard]] HistoryItem *histItemById(
const ChannelData *channel,
MsgId itemId);

View file

@ -386,7 +386,7 @@ AuthSession::AuthSession(const MTPUser &user)
, _storage(std::make_unique<Storage::Facade>())
, _notifications(std::make_unique<Window::Notifications::System>(this))
, _data(std::make_unique<Data::Session>(this))
, _user(_data->user(user))
, _user(_data->processUser(user))
, _changelogs(Core::Changelogs::Create(this))
, _supportHelper(Support::Helper::Create(this)) {
_saveDataTimer.setCallback([=] {

View file

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "apiwrap.h"
@ -321,8 +322,9 @@ bool AddContactBox::onSaveUserFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
_addRequest = 0;
QString err(error.type());
QString firstName = _first->getLastText().trimmed(), lastName = _last->getLastText().trimmed();
const auto &err = error.type();
const auto firstName = _first->getLastText().trimmed();
const auto lastName = _last->getLastText().trimmed();
if (err == "CHAT_TITLE_NOT_MODIFIED") {
_user->setName(firstName, lastName, _user->nameOrPhone, _user->username);
closeBox();
@ -340,14 +342,14 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
if (!isBoxShown() || !App::main()) return;
const auto &d = res.c_contacts_importedContacts();
App::feedUsers(d.vusers);
Auth().data().processUsers(d.vusers);
const auto &v = d.vimported.v;
const auto user = [&]() -> UserData* {
if (!v.isEmpty()) {
auto &c = v.front().c_importedContact();
if (c.vclient_id.v == _contactId) {
return App::userLoaded(c.vuser_id.v);
return Auth().data().userLoaded(c.vuser_id.v);
}
}
return nullptr;
@ -368,7 +370,7 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) {
auto &d = res.c_contacts_importedContacts();
App::feedUsers(d.vusers);
Auth().data().processUsers(d.vusers);
closeBox();
}
@ -535,7 +537,7 @@ void GroupInfoBox::createGroup(
: std::nullopt;
}
| [](auto chats) {
return App::chat(chats->front().c_chat().vid.v);
return Auth().data().chat(chats->front().c_chat().vid.v);
}
| [&](not_null<ChatData*> chat) {
if (!image.isNull()) {
@ -643,7 +645,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
: std::nullopt;
}
| [](auto chats) {
return App::channel(chats->front().c_channel().vid.v);
return Auth().data().channel(chats->front().c_channel().vid.v);
}
| [&](not_null<ChannelData*> channel) {
auto image = _photo->takeResultImage();
@ -1153,7 +1155,7 @@ void EditNameBox::save() {
}
void EditNameBox::saveSelfDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(1, user));
_user->owner().processUsers(MTP_vector<MTPUser>(1, user));
closeBox();
}
@ -1194,7 +1196,7 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn<void()> revokeCallback) :
return data.vchats.v;
});
for (const auto &chat : chats) {
if (const auto peer = App::feedChat(chat)) {
if (const auto peer = Auth().data().processChat(chat)) {
if (!peer->isChannel() || peer->userName().isEmpty()) {
continue;
}

View file

@ -290,12 +290,12 @@ BackgroundPreviewBox::BackgroundPreviewBox(
const Data::WallPaper &paper)
: _text1(GenerateTextItem(
this,
App::history(App::user(ServiceUserId)),
Auth().data().history(peerFromUser(ServiceUserId)),
lang(lng_background_text1),
false))
, _text2(GenerateTextItem(
this,
App::history(App::user(ServiceUserId)),
Auth().data().history(peerFromUser(ServiceUserId)),
lang(lng_background_text2),
true))
, _paper(paper)

View file

@ -8,13 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/change_phone_box.h"
#include "lang/lang_keys.h"
#include "styles/style_boxes.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/input_fields.h"
#include "ui/wrap/fade_wrap.h"
#include "boxes/confirm_phone_box.h"
#include "ui/toast/toast.h"
#include "boxes/confirm_box.h"
#include "auth_session.h"
#include "data/data_session.h"
#include "styles/style_boxes.h"
namespace {
@ -260,7 +262,7 @@ void ChangePhoneBox::EnterCode::submit() {
MTP_string(_hash),
MTP_string(code)
), rpcDone([weak = make_weak(this)](const MTPUser &result) {
App::feedUser(result);
Auth().data().processUser(result);
if (weak) {
Ui::hideLayer();
}

View file

@ -689,7 +689,7 @@ std::vector<not_null<UserData*>> ConfirmInviteBox::GetParticipants(
auto result = std::vector<not_null<UserData*>>();
result.reserve(v.size());
for (const auto &participant : v) {
if (const auto user = App::feedUser(participant)) {
if (const auto user = Auth().data().processUser(participant)) {
result.push_back(user);
}
}

View file

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/file_download.h"
#include "data/data_peer_values.h"
#include "data/data_chat.h"
#include "data/data_session.h"
#include "window/themes/window_theme.h"
auto PaintUserpicCallback(
@ -64,7 +65,7 @@ void PeerListBox::createMultiSelect() {
_select->entity()->setSubmittedCallback([this](Qt::KeyboardModifiers) { content()->submitted(); });
_select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); });
_select->entity()->setItemRemovedCallback([this](uint64 itemId) {
if (auto peer = App::peerLoaded(itemId)) {
if (auto peer = Auth().data().peerLoaded(itemId)) {
if (auto row = peerListFindRow(peer->id)) {
content()->changeCheckState(row, false, PeerListRow::SetStyle::Animated);
update();
@ -327,7 +328,7 @@ auto PeerListBox::peerListCollectSelectedRows()
if (!items.empty()) {
result.reserve(items.size());
for (const auto itemId : items) {
result.push_back(App::peer(itemId));
result.push_back(Auth().data().peer(itemId));
}
}
return result;

View file

@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
void ShareBotGame(not_null<UserData*> bot, not_null<PeerData*> chat) {
const auto history = App::historyLoaded(chat);
const auto history = chat->owner().historyLoaded(chat);
const auto randomId = rand_value<uint64>();
const auto requestId = MTP::send(
MTPmessages_SendMedia(
@ -182,8 +182,8 @@ void PeerListGlobalSearchController::searchDone(
auto &contacts = result.c_contacts_found();
auto query = _query;
if (requestId) {
App::feedUsers(contacts.vusers);
App::feedChats(contacts.vchats);
Auth().data().processUsers(contacts.vusers);
Auth().data().processChats(contacts.vchats);
auto it = _queries.find(requestId);
if (it != _queries.cend()) {
query = it->second;
@ -193,7 +193,7 @@ void PeerListGlobalSearchController::searchDone(
}
const auto feedList = [&](const MTPVector<MTPPeer> &list) {
for (const auto &mtpPeer : list.v) {
if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) {
delegate()->peerListSearchAddRow(peer);
}
}
@ -255,7 +255,7 @@ void ChatsListBoxController::rebuildRows() {
};
auto added = 0;
if (respectSavedMessagesChat()) {
if (appendRow(App::history(Auth().user()))) {
if (appendRow(Auth().data().history(Auth().user()))) {
++added;
}
}
@ -292,7 +292,7 @@ QString ChatsListBoxController::emptyBoxText() const {
}
std::unique_ptr<PeerListRow> ChatsListBoxController::createSearchRow(not_null<PeerData*> peer) {
return createRow(App::history(peer));
return createRow(peer->owner().history(peer));
}
bool ChatsListBoxController::appendRow(not_null<History*> history) {

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "history/history.h"
#include "dialogs/dialogs_indexed_list.h"
#include "auth_session.h"
@ -435,7 +436,7 @@ bool AddSpecialBoxController::checkInfoLoaded(
Expects(result.type() == mtpc_channels_channelParticipant);
const auto &participant = result.c_channels_channelParticipant();
App::feedUsers(participant.vusers);
channel->owner().processUsers(participant.vusers);
_additional.applyParticipant(participant.vparticipant);
callback();
}).fail([=](const RPCError &error) {
@ -964,8 +965,8 @@ void AddSpecialBoxSearchController::searchGlobalDone(
auto &found = result.c_contacts_found();
auto query = _query;
if (requestId) {
App::feedUsers(found.vusers);
App::feedChats(found.vchats);
_peer->owner().processUsers(found.vusers);
_peer->owner().processChats(found.vchats);
auto it = _globalQueries.find(requestId);
if (it != _globalQueries.cend()) {
query = it->second;
@ -977,7 +978,7 @@ void AddSpecialBoxSearchController::searchGlobalDone(
const auto feedList = [&](const MTPVector<MTPPeer> &list) {
for (const auto &mtpPeer : list.v) {
const auto peerId = peerFromMTP(mtpPeer);
if (const auto peer = App::peerLoaded(peerId)) {
if (const auto peer = _peer->owner().peerLoaded(peerId)) {
if (const auto user = peer->asUser()) {
_additional->checkForLoaded(user);
delegate()->peerListSearchAddRow(user);

View file

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/emoji_suggestions_widget.h"
#include "data/data_channel.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "auth_session.h"
#include "messenger.h"
#include "styles/style_boxes.h"
@ -220,7 +221,7 @@ void ShareBox::prepare() {
applyFilterUpdate(query);
});
_select->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = App::peerLoaded(itemId)) {
if (const auto peer = Auth().data().peerLoaded(itemId)) {
_inner->peerUnselected(peer);
selectedChanged();
update();
@ -334,8 +335,8 @@ void ShareBox::peopleReceived(
switch (result.type()) {
case mtpc_contacts_found: {
auto &found = result.c_contacts_found();
App::feedUsers(found.vusers);
App::feedChats(found.vchats);
Auth().data().processUsers(found.vusers);
Auth().data().processChats(found.vchats);
_inner->peopleReceived(
query,
found.vmy_results.v,
@ -491,7 +492,7 @@ ShareBox::Inner::Inner(
const auto dialogs = App::main()->dialogsList();
const auto self = Auth().user();
if (_filterCallback(self)) {
_chatsIndexed->addToEnd(App::history(self));
_chatsIndexed->addToEnd(self->owner().history(self));
}
for (const auto row : dialogs->all()) {
if (const auto history = row->history()) {
@ -880,7 +881,7 @@ void ShareBox::Inner::changeCheckState(Chat *chat) {
if (!chat) return;
if (!_filter.isEmpty()) {
const auto history = App::history(chat->peer);
const auto history = chat->peer->owner().history(chat->peer);
auto row = _chatsIndexed->getRow(history);
if (!row) {
const auto rowsByLetter = _chatsIndexed->addToEnd(history);
@ -1017,8 +1018,8 @@ void ShareBox::Inner::peopleReceived(
d_byUsernameFiltered.reserve(already + my.size() + people.size());
const auto feedList = [&](const QVector<MTPPeer> &list) {
for (const auto &data : list) {
if (const auto peer = App::peerLoaded(peerFromMTP(data))) {
const auto history = App::historyLoaded(peer);
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) {
const auto history = Auth().data().historyLoaded(peer);
if (!_filterCallback(peer)) {
continue;
} else if (history && _chatsIndexed->getRow(history)) {
@ -1066,7 +1067,9 @@ QVector<PeerData*> ShareBox::Inner::selected() const {
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data());
auto channel = fullId.channel ? App::channelLoaded(fullId.channel) : static_cast<ChannelData*>(nullptr);
auto channel = fullId.channel
? Auth().data().channelLoaded(fullId.channel)
: static_cast<ChannelData*>(nullptr);
auto channelAccessHash = channel ? channel->access : 0ULL;
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
shareHashDataInts[0] = Auth().userId();
@ -1169,7 +1172,9 @@ void ShareGameScoreByHash(const QString &hash) {
});
};
auto channel = channelId ? App::channelLoaded(channelId) : nullptr;
const auto channel = channelId
? Auth().data().channelLoaded(channelId)
: nullptr;
if (channel || !channelId) {
resolveMessageAndShareScore(channel);
} else {
@ -1177,9 +1182,9 @@ void ShareGameScoreByHash(const QString &hash) {
auto requestChannel = MTPchannels_GetChannels(requestChannelIds);
MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) {
result.match([](const auto &data) {
App::feedChats(data.vchats);
Auth().data().processChats(data.vchats);
});
if (const auto channel = App::channelLoaded(channelId)) {
if (const auto channel = Auth().data().channelLoaded(channelId)) {
resolveMessageAndShareScore(channel);
}
}));

View file

@ -201,11 +201,11 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
auto &v = d.vdocuments.v;
_pack.reserve(v.size());
_packOvers.reserve(v.size());
for (int i = 0, l = v.size(); i < l; ++i) {
auto doc = Auth().data().document(v.at(i));
if (!doc->sticker()) continue;
for (const auto &item : v) {
const auto document = Auth().data().processDocument(item);
if (!document->sticker()) continue;
_pack.push_back(doc);
_pack.push_back(document);
_packOvers.push_back(Animation());
}
auto &packs = d.vpacks.v;

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/toast/toast.h"
#include "messenger.h"
#include "auth_session.h"
#include "data/data_session.h"
#include "data/data_user.h"
#include "styles/style_boxes.h"
@ -170,7 +171,7 @@ void UsernameBox::linkClick() {
}
void UsernameBox::onUpdateDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(1, user));
Auth().data().processUser(user);
closeBox();
}

View file

@ -255,9 +255,9 @@ void BoxController::loadMoreRows() {
)).done([this](const MTPmessages_Messages &result) {
_loadRequestId = 0;
auto handleResult = [this](auto &data) {
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
auto handleResult = [&](auto &data) {
Auth().data().processUsers(data.vusers);
Auth().data().processChats(data.vchats);
receivedCalls(data.vmessages.v);
};
@ -305,7 +305,7 @@ void BoxController::receivedCalls(const QVector<MTPMessage> &result) {
for (const auto &message : result) {
auto msgId = IdFromMessage(message);
auto peerId = PeerFromMessage(message);
if (auto peer = App::peerLoaded(peerId)) {
if (auto peer = Auth().data().peerLoaded(peerId)) {
auto item = Auth().data().addNewMessage(message, NewMessageExisting);
insertRow(item, InsertWay::Append);
} else {

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/media_audio_track.h"
#include "calls/calls_panel.h"
#include "data/data_user.h"
#include "data/data_session.h"
#ifdef slots
#undef slots
@ -201,7 +202,7 @@ void Call::startOutgoing() {
setState(State::Waiting);
auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers);
Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCallWaiting) {
LOG(("Call Error: Expected phoneCallWaiting in response to phone.requestCall()"));
finish(FinishType::Failed);
@ -273,7 +274,7 @@ void Call::actuallyAnswer() {
)).done([this](const MTPphone_PhoneCall &result) {
Expects(result.type() == mtpc_phone_phoneCall);
auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers);
Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCallWaiting) {
LOG(("Call Error: Expected phoneCallWaiting in response to phone.acceptCall()"));
finish(FinishType::Failed);
@ -487,8 +488,9 @@ void Call::confirmAcceptedCall(const MTPDphoneCallAccepted &call) {
MTP_int(tgvoip::VoIPController::GetConnectionMaxLayer()))
)).done([this](const MTPphone_PhoneCall &result) {
Expects(result.type() == mtpc_phone_phoneCall);
auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers);
Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCall) {
LOG(("Call Error: Expected phoneCall in response to phone.confirmCall()"));
finish(FinishType::Failed);

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "calls/calls_call.h"
#include "calls/calls_panel.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "media/media_audio_track.h"
#include "platform/platform_specific.h"
#include "mainwidget.h"
@ -222,7 +223,7 @@ bool Instance::isQuitPrevent() {
void Instance::handleCallUpdate(const MTPPhoneCall &call) {
if (call.type() == mtpc_phoneCallRequested) {
auto &phoneCall = call.c_phoneCallRequested();
auto user = App::userLoaded(phoneCall.vadmin_id.v);
auto user = Auth().data().userLoaded(phoneCall.vadmin_id.v);
if (!user) {
LOG(("API Error: User not loaded for phoneCallRequested."));
} else if (user->isSelf()) {

View file

@ -223,7 +223,7 @@ void GifsListWidget::inlineResultsDone(const MTPmessages_BotResults &result) {
auto adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) {
auto &d = result.c_messages_botResults();
App::feedUsers(d.vusers);
Auth().data().processUsers(d.vusers);
auto &v = d.vresults.v;
auto queryId = d.vquery_id.v;
@ -842,12 +842,15 @@ void GifsListWidget::searchForGifs(const QString &query) {
if (!_searchBot && !_searchBotRequestId) {
auto username = str_const_toString(kSearchBotUsername);
_searchBotRequestId = request(MTPcontacts_ResolveUsername(MTP_string(username))).done([this](const MTPcontacts_ResolvedPeer &result) {
_searchBotRequestId = request(MTPcontacts_ResolveUsername(
MTP_string(username)
)).done([=](const MTPcontacts_ResolvedPeer &result) {
Expects(result.type() == mtpc_contacts_resolvedPeer);
auto &data = result.c_contacts_resolvedPeer();
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
if (auto peer = App::peerLoaded(peerFromMTP(data.vpeer))) {
Auth().data().processUsers(data.vusers);
Auth().data().processChats(data.vchats);
if (auto peer = Auth().data().peerLoaded(peerFromMTP(data.vpeer))) {
if (auto user = peer->asUser()) {
_searchBot = user;
}

View file

@ -480,9 +480,9 @@ void SpecialSetReceived(
auto custom = sets.find(CustomSetId);
auto pack = Pack();
pack.reserve(items.size());
for_const (auto &mtpDocument, items) {
for (const auto &item : items) {
++dateIndex;
auto document = Auth().data().document(mtpDocument);
const auto document = Auth().data().processDocument(item);
if (!document->sticker()) {
continue;
}
@ -662,10 +662,11 @@ void GifsReceived(const QVector<MTPDocument> &items, int32 hash) {
saved.clear();
saved.reserve(items.size());
for_const (auto &gif, items) {
auto document = Auth().data().document(gif);
for (const auto &item : items) {
const auto document = Auth().data().processDocument(item);
if (!document->isGifv()) {
LOG(("API Error: bad document returned in HistoryWidget::savedGifsGot!"));
LOG(("API Error: "
"bad document returned in HistoryWidget::savedGifsGot!"));
continue;
}
@ -917,13 +918,13 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
auto pack = Pack();
pack.reserve(d_docs.size());
for (auto i = 0, l = d_docs.size(); i != l; ++i) {
auto doc = Auth().data().document(d_docs.at(i));
if (!doc->sticker()) continue;
for (const auto &item : d_docs) {
const auto document = Auth().data().processDocument(item);
if (!document->sticker()) continue;
pack.push_back(doc);
pack.push_back(document);
if (custom != sets.cend()) {
auto index = custom->stickers.indexOf(doc);
const auto index = custom->stickers.indexOf(document);
if (index >= 0) {
custom->stickers.removeAt(index);
}

View file

@ -1092,7 +1092,7 @@ void StickersListWidget::searchResultsDone(
setData = &d.vset.c_stickerSet();
}
for (const auto &cover : d.vcovers.v) {
const auto document = Auth().data().document(cover);
const auto document = Auth().data().processDocument(cover);
if (document->sticker()) {
covers.push_back(document);
}

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "messenger.h"
#include "mainwidget.h"
#include "auth_session.h"
#include "application.h"
#include "platform/platform_specific.h"
#include "history/view/history_view_element.h"
@ -21,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/tooltip.h"
#include "core/file_utilities.h"
#include "data/data_user.h"
#include "data/data_session.h"
namespace {
@ -247,7 +249,7 @@ TextWithEntities MentionClickHandler::getExpandedLinkTextWithEntities(ExpandLink
void MentionNameClickHandler::onClick(ClickContext context) const {
const auto button = context.button;
if (button == Qt::LeftButton || button == Qt::MiddleButton) {
if (auto user = App::userLoaded(_userId)) {
if (auto user = Auth().data().userLoaded(_userId)) {
Ui::showPeerProfile(user);
}
}
@ -259,7 +261,7 @@ TextWithEntities MentionNameClickHandler::getExpandedLinkTextWithEntities(Expand
}
QString MentionNameClickHandler::tooltip() const {
if (auto user = App::userLoaded(_userId)) {
if (auto user = Auth().data().userLoaded(_userId)) {
auto name = App::peerName(user);
if (name != _text) {
return name;

View file

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/sticker_set_box.h"
#include "passport/passport_form_controller.h"
#include "window/window_controller.h"
#include "data/data_session.h"
#include "mainwindow.h"
#include "mainwidget.h"
#include "messenger.h"
@ -43,7 +44,7 @@ bool JoinGroupByHash(const Match &match, const QVariant &context) {
Auth().api().importChatInvite(hash);
}));
}, [=](const MTPDchatInviteAlready &data) {
if (const auto chat = App::feedChat(data.vchat)) {
if (const auto chat = Auth().data().processChat(data.vchat)) {
App::wnd()->controller()->showPeerHistory(
chat,
Window::SectionShow::Way::Forward);

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,

View file

@ -95,7 +95,7 @@ void IndexedList::peerNameChanged(
const base::flat_set<QChar> &oldLetters) {
Expects(_sortMode != SortMode::Date);
if (const auto history = App::historyLoaded(peer)) {
if (const auto history = peer->owner().historyLoaded(peer)) {
if (_sortMode == SortMode::Name) {
adjustByName(history, oldLetters);
} else {
@ -110,7 +110,7 @@ void IndexedList::peerNameChanged(
const base::flat_set<QChar> &oldLetters) {
Expects(_sortMode == SortMode::Date);
if (const auto history = App::historyLoaded(peer)) {
if (const auto history = peer->owner().historyLoaded(peer)) {
adjustNames(list, history, oldLetters);
}
}

View file

@ -1410,7 +1410,7 @@ void DialogsInner::updateDialogRow(
if (IsServerMsgId(-row.fullId.msg)) {
if (const auto peer = row.key.peer()) {
if (const auto from = peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(from)) {
if (const auto migrated = from->owner().historyLoaded(from)) {
row = Dialogs::RowDescriptor(
migrated,
FullMsgId(0, -row.fullId.msg));
@ -1871,7 +1871,7 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) {
return;
}
const auto history = App::history(peerId);
const auto history = Auth().data().history(peerId);
history->applyDialog(dialog);
if (!history->useProxyPromotion() && !history->isPinnedDialog()) {
@ -1882,7 +1882,7 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) {
}
_contactsNoDialogs->del(history);
if (const auto from = history->peer->migrateFrom()) {
if (const auto historyFrom = App::historyLoaded(from)) {
if (const auto historyFrom = from->owner().historyLoaded(from)) {
removeDialog(historyFrom);
}
} else if (const auto to = history->peer->migrateTo()) {
@ -1912,7 +1912,7 @@ void DialogsInner::addSavedPeersAfter(const QDateTime &date) {
const auto lastPeer = saved.last();
saved.remove(lastDate, lastPeer);
const auto history = App::history(lastPeer);
const auto history = Auth().data().history(lastPeer);
history->setChatListTimeId(ServerTimeFromParsed(lastDate));
_contactsNoDialogs->del(history);
}
@ -1953,7 +1953,7 @@ bool DialogsInner::searchReceived(
auto msgId = IdFromMessage(message);
auto peerId = PeerFromMessage(message);
auto lastDate = DateFromMessage(message);
if (const auto peer = App::peerLoaded(peerId)) {
if (const auto peer = Auth().data().peerLoaded(peerId)) {
if (lastDate) {
const auto item = Auth().data().addNewMessage(
message,
@ -2025,14 +2025,14 @@ void DialogsInner::peerSearchReceived(
_peerSearchResults.clear();
_peerSearchResults.reserve(result.size());
for (const auto &mtpPeer : my) {
if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) {
if (alreadyAdded(peer)) {
continue;
}
const auto prev = nullptr, next = nullptr;
const auto position = 0;
auto row = std::make_unique<Dialogs::Row>(
App::history(peer),
peer->owner().history(peer),
prev,
next,
position);
@ -2047,8 +2047,8 @@ void DialogsInner::peerSearchReceived(
}
}
for (const auto &mtpPeer : result) {
if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) {
if (const auto history = App::historyLoaded(peer)) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) {
if (const auto history = peer->owner().historyLoaded(peer)) {
if (history->inChatList(Dialogs::Mode::All)) {
continue; // skip existing chats
}
@ -2071,13 +2071,13 @@ void DialogsInner::userIsContactUpdated(not_null<UserData*> user) {
return;
}
if (user->contactStatus() == UserData::ContactStatus::Contact) {
const auto history = App::history(user->id);
const auto history = user->owner().history(user->id);
_contacts->addByName(history);
if (!shownDialogs()->getRow(history)
&& !_dialogs->contains(history)) {
_contactsNoDialogs->addByName(history);
}
} else if (const auto history = App::historyLoaded(user)) {
} else if (const auto history = user->owner().historyLoaded(user)) {
if (_selected && _selected->history() == history) {
_selected = nullptr;
}
@ -2196,9 +2196,9 @@ void DialogsInner::searchInChat(Dialogs::Key key, UserData *from) {
_searchInMigrated = nullptr;
if (const auto peer = key.peer()) {
if (const auto migrateTo = peer->migrateTo()) {
return searchInChat(App::history(migrateTo), from);
return searchInChat(peer->owner().history(migrateTo), from);
} else if (const auto migrateFrom = peer->migrateFrom()) {
_searchInMigrated = App::history(migrateFrom);
_searchInMigrated = peer->owner().history(migrateFrom);
}
}
_searchInChat = key;
@ -2544,7 +2544,7 @@ DialogsInner::ChosenRow DialogsInner::computeChosenRow() const {
};
} else if (base::in_range(_peerSearchSelected, 0, _peerSearchResults.size())) {
return {
App::history(_peerSearchResults[_peerSearchSelected]->peer),
Auth().data().history(_peerSearchResults[_peerSearchSelected]->peer),
Data::UnreadMessagePosition
};
} else if (base::in_range(_searchedSelected, 0, _searchResults.size())) {
@ -2666,7 +2666,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryBefore(
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.back()->peer),
Auth().data().history(_peerSearchResults.back()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
}
@ -2683,7 +2683,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryBefore(
for (auto b = _peerSearchResults.cbegin(), i = b + 1, e = _peerSearchResults.cend(); i != e; ++i) {
if ((*i)->peer == whichHistory->peer) {
return Dialogs::RowDescriptor(
App::history((*(i - 1))->peer),
Auth().data().history((*(i - 1))->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
}
}
@ -2739,7 +2739,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryAfter(
++i;
if (i != e) {
return Dialogs::RowDescriptor(
App::history((*i)->peer),
Auth().data().history((*i)->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
@ -2758,7 +2758,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryAfter(
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_peerSearchResults.empty()) {
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.front()->peer),
Auth().data().history(_peerSearchResults.front()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
@ -2786,7 +2786,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryFirst() const {
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_peerSearchResults.empty()) {
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.front()->peer),
Auth().data().history(_peerSearchResults.front()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_searchResults.empty()) {
return Dialogs::RowDescriptor(
@ -2811,7 +2811,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryLast() const {
_searchResults.back()->item()->fullId());
} else if (!_peerSearchResults.empty()) {
return Dialogs::RowDescriptor(
App::history(_peerSearchResults.back()->peer),
Auth().data().history(_peerSearchResults.back()->peer),
FullMsgId(NoChannel, ShowAtUnreadMsgId));
} else if (!_filterResults.empty()) {
return Dialogs::RowDescriptor(

View file

@ -310,7 +310,7 @@ void DialogsWidget::createDialog(Dialogs::Key key) {
_inner->createDialog(key);
const auto history = key.history();
if (creating && history && history->peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(
if (const auto migrated = history->owner().historyLoaded(
history->peer->migrateFrom())) {
if (migrated->inChatList(Dialogs::Mode::All)) {
_inner->removeDialog(migrated);
@ -445,8 +445,8 @@ void DialogsWidget::dialogsReceived(
const auto [dialogsList, messagesList] = [&] {
const auto process = [&](const auto &data) {
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
Auth().data().processUsers(data.vusers);
Auth().data().processChats(data.vchats);
return std::make_tuple(&data.vdialogs.v, &data.vmessages.v);
};
switch (dialogs.type()) {
@ -514,7 +514,7 @@ void DialogsWidget::updateDialogsOffset(
if (lastDate) {
_dialogsOffsetDate = lastDate;
_dialogsOffsetId = lastMsgId;
_dialogsOffsetPeer = App::peer(lastPeer);
_dialogsOffsetPeer = Auth().data().peer(lastPeer);
} else {
_dialogsFull = true;
}
@ -564,8 +564,8 @@ void DialogsWidget::pinnedDialogsReceived(
if (_pinnedDialogsRequestId != requestId) return;
auto &data = result.c_messages_peerDialogs();
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
Auth().data().processUsers(data.vusers);
Auth().data().processChats(data.vchats);
Auth().data().applyPinnedDialogs(data.vdialogs.v);
applyReceivedDialogs(data.vdialogs.v, data.vmessages.v);
@ -932,8 +932,8 @@ void DialogsWidget::searchReceived(
auto &d = result.c_messages_messages();
if (_searchRequest != 0) {
// Don't apply cached data!
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
Auth().data().processUsers(d.vusers);
Auth().data().processChats(d.vchats);
}
auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, msgs.size())) {
@ -949,8 +949,8 @@ void DialogsWidget::searchReceived(
auto &d = result.c_messages_messagesSlice();
if (_searchRequest != 0) {
// Don't apply cached data!
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
Auth().data().processUsers(d.vusers);
Auth().data().processChats(d.vchats);
}
auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
@ -979,8 +979,8 @@ void DialogsWidget::searchReceived(
}
if (_searchRequest != 0) {
// Don't apply cached data!
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
Auth().data().processUsers(d.vusers);
Auth().data().processChats(d.vchats);
}
auto &msgs = d.vmessages.v;
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
@ -1026,8 +1026,8 @@ void DialogsWidget::peerSearchReceived(
switch (result.type()) {
case mtpc_contacts_found: {
auto &d = result.c_contacts_found();
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
Auth().data().processUsers(d.vusers);
Auth().data().processChats(d.vchats);
_inner->peerSearchReceived(q, d.vmy_results.v, d.vresults.v);
} break;
}
@ -1186,9 +1186,9 @@ void DialogsWidget::setSearchInChat(Dialogs::Key chat, UserData *from) {
_searchInMigrated = nullptr;
if (const auto peer = chat.peer()) {
if (const auto migrateTo = peer->migrateTo()) {
return setSearchInChat(App::history(migrateTo), from);
return setSearchInChat(peer->owner().history(migrateTo), from);
} else if (const auto migrateFrom = peer->migrateFrom()) {
_searchInMigrated = App::history(migrateFrom);
_searchInMigrated = peer->owner().history(migrateFrom);
}
}
const auto searchInPeerUpdated = (_searchInChat != chat);

View file

@ -160,7 +160,7 @@ void searchByHashtag(const QString &tag, PeerData *inPeer) {
m->searchMessages(
tag + ' ',
(inPeer
? App::history(inPeer).get()
? inPeer->owner().history(inPeer).get()
: Dialogs::Key()));
}
}
@ -799,7 +799,7 @@ DefineRefVar(Global, base::Variable<DBIWorkMode>, WorkMode);
DefineRefVar(Global, base::Observable<void>, UnreadCounterUpdate);
DefineRefVar(Global, base::Observable<void>, PeerChooseCancel);
DefineVar(Global, QString, CallOutputDeviceID);
DefineVar(Global, QString, CallInputDeviceID);
DefineVar(Global, int, CallOutputVolume);

View file

@ -216,7 +216,7 @@ InnerWidget::InnerWidget(
: RpWidget(parent)
, _controller(controller)
, _channel(channel)
, _history(App::history(channel))
, _history(channel->owner().history(channel))
, _scrollDateCheck([this] { scrollDateCheck(); })
, _emptyText(
st::historyAdminLogEmptyWidth
@ -405,7 +405,7 @@ void InnerWidget::requestAdmins() {
return std::make_pair(userId, canEdit);
}) | ranges::view::transform([&](auto &&pair) {
return std::make_pair(
App::userLoaded(pair.first),
Auth().data().userLoaded(pair.first),
pair.second);
}) | ranges::view::filter([&](auto &&pair) {
return (pair.first != nullptr);
@ -588,13 +588,23 @@ void InnerWidget::preloadMore(Direction direction) {
auto maxId = (direction == Direction::Up) ? _minId : 0;
auto minId = (direction == Direction::Up) ? 0 : _maxId;
auto perPage = _items.empty() ? kEventsFirstPage : kEventsPerPage;
requestId = request(MTPchannels_GetAdminLog(MTP_flags(flags), _channel->inputChannel, MTP_string(_searchQuery), filter, MTP_vector<MTPInputUser>(admins), MTP_long(maxId), MTP_long(minId), MTP_int(perPage))).done([this, &requestId, &loadedFlag, direction](const MTPchannels_AdminLogResults &result) {
requestId = request(MTPchannels_GetAdminLog(
MTP_flags(flags),
_channel->inputChannel,
MTP_string(_searchQuery),
filter,
MTP_vector<MTPInputUser>(admins),
MTP_long(maxId),
MTP_long(minId),
MTP_int(perPage)
)).done([=, &requestId, &loadedFlag](const MTPchannels_AdminLogResults &result) {
Expects(result.type() == mtpc_channels_adminLogResults);
requestId = 0;
auto &results = result.c_channels_adminLogResults();
App::feedUsers(results.vusers);
App::feedChats(results.vchats);
_channel->owner().processUsers(results.vusers);
_channel->owner().processChats(results.vchats);
if (!loadedFlag) {
addEvents(direction, results.vevents.v);
}
@ -1167,7 +1177,7 @@ void InnerWidget::suggestRestrictUser(not_null<UserData*> user) {
Expects(result.type() == mtpc_channels_channelParticipant);
auto &participant = result.c_channels_channelParticipant();
App::feedUsers(participant.vusers);
_channel->owner().processUsers(participant.vusers);
auto type = participant.vparticipant.type();
if (type == mtpc_channelParticipantBanned) {
auto &banned = participant.vparticipant.c_channelParticipantBanned();

View file

@ -128,7 +128,7 @@ PhotoData *GenerateChatPhoto(
photoSizes.reserve(2);
photoSizes.push_back(MTP_photoSize(MTP_string("a"), photo.vphoto_small, MTP_int(160), MTP_int(160), MTP_int(0)));
photoSizes.push_back(MTP_photoSize(MTP_string("c"), photo.vphoto_big, MTP_int(640), MTP_int(640), MTP_int(0)));
return Auth().data().photo(MTP_photo(
return Auth().data().processPhoto(MTP_photo(
MTP_flags(0),
MTP_long(photoId),
MTP_long(0),
@ -253,7 +253,7 @@ TextWithEntities GenerateBannedChangeText(
auto GenerateUserString(MTPint userId) {
// User name in "User name (@username)" format with entities.
auto user = App::user(userId.v);
auto user = Auth().data().user(userId.v);
auto name = TextWithEntities { App::peerName(user) };
auto entityData = QString::number(user->id)
+ '.'
@ -377,7 +377,7 @@ void GenerateItems(
Expects(history->peer->isChannel());
auto id = event.vid.v;
auto from = App::user(event.vuser_id.v);
auto from = Auth().data().user(event.vuser_id.v);
auto channel = history->peer->asChannel();
auto &action = event.vaction;
auto date = event.vdate.v;

View file

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/confirm_box.h"
#include "base/timer.h"
#include "data/data_channel.h"
#include "data/data_session.h"
#include "lang/lang_keys.h"
#include "styles/style_history.h"
#include "styles/style_window.h"
@ -285,7 +286,7 @@ not_null<ChannelData*> Widget::channel() const {
Dialogs::RowDescriptor Widget::activeChat() const {
return {
App::history(channel()),
channel()->owner().history(channel()),
FullMsgId(channel()->bareId(), ShowAtUnreadMsgId)
};
}

View file

@ -766,9 +766,9 @@ void History::eraseFromUnreadMentions(MsgId msgId) {
void History::addUnreadMentionsSlice(const MTPmessages_Messages &result) {
auto count = 0;
auto messages = (const QVector<MTPMessage>*)nullptr;
auto getMessages = [](auto &list) {
App::feedUsers(list.vusers);
App::feedChats(list.vchats);
auto getMessages = [&](auto &list) {
owner().processUsers(list.vusers);
owner().processChats(list.vchats);
return &list.vmessages.v;
};
switch (result.type()) {
@ -952,12 +952,11 @@ void History::applyServiceChanges(
switch (action.type()) {
case mtpc_messageActionChatAddUser: {
auto &d = action.c_messageActionChatAddUser();
if (auto megagroup = peer->asMegagroup()) {
auto mgInfo = megagroup->mgInfo.get();
if (const auto megagroup = peer->asMegagroup()) {
const auto mgInfo = megagroup->mgInfo.get();
Assert(mgInfo != nullptr);
auto &v = d.vusers.v;
for (auto i = 0, l = v.size(); i != l; ++i) {
if (auto user = App::userLoaded(peerFromUser(v[i]))) {
for (const auto &userId : d.vusers.v) {
if (const auto user = owner().userLoaded(userId.v)) {
if (!base::contains(mgInfo->lastParticipants, user)) {
mgInfo->lastParticipants.push_front(user);
Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged);
@ -1003,12 +1002,12 @@ void History::applyServiceChanges(
case mtpc_messageActionChatDeleteUser: {
auto &d = action.c_messageActionChatDeleteUser();
auto uid = peerFromUser(d.vuser_id);
if (lastKeyboardFrom == uid) {
auto uid = d.vuser_id.v;
if (lastKeyboardFrom == peerFromUser(uid)) {
clearLastKeyboard();
}
if (auto megagroup = peer->asMegagroup()) {
if (auto user = App::userLoaded(uid)) {
if (auto user = owner().userLoaded(uid)) {
auto mgInfo = megagroup->mgInfo.get();
Assert(mgInfo != nullptr);
auto i = ranges::find(
@ -1047,7 +1046,7 @@ void History::applyServiceChanges(
if (d.vphoto.type() == mtpc_photo) {
auto &sizes = d.vphoto.c_photo().vsizes.v;
if (!sizes.isEmpty()) {
auto photo = _owner->photo(d.vphoto.c_photo());
auto photo = _owner->processPhoto(d.vphoto.c_photo());
if (photo) photo->peer = peer;
auto &smallSize = sizes.front();
auto &bigSize = sizes.back();
@ -1084,7 +1083,7 @@ void History::applyServiceChanges(
if (const auto chat = peer->asChat()) {
chat->addFlags(MTPDchat::Flag::f_deactivated);
const auto &d = action.c_messageActionChatMigrateTo();
if (const auto channel = App::channelLoaded(d.vchannel_id.v)) {
if (const auto channel = owner().channelLoaded(d.vchannel_id.v)) {
Data::ApplyMigration(chat, channel);
}
}
@ -1094,7 +1093,7 @@ void History::applyServiceChanges(
if (const auto channel = peer->asChannel()) {
channel->addFlags(MTPDchannel::Flag::f_megagroup);
const auto &d = action.c_messageActionChannelMigrateFrom();
if (const auto chat = App::chatLoaded(d.vchat_id.v)) {
if (const auto chat = owner().chatLoaded(d.vchat_id.v)) {
Data::ApplyMigration(chat, channel);
}
}
@ -1482,7 +1481,7 @@ void History::inboxRead(MsgId upTo) {
setInboxReadTill(upTo);
updateChatListEntry();
if (peer->migrateTo()) {
if (auto migrateTo = App::historyLoaded(peer->migrateTo()->id)) {
if (auto migrateTo = peer->owner().historyLoaded(peer->migrateTo()->id)) {
migrateTo->updateChatListEntry();
}
}
@ -1899,7 +1898,7 @@ History *History::migrateSibling() const {
}
return PeerId(0);
}();
return App::historyLoaded(addFromId);
return owner().historyLoaded(addFromId);
}
int History::chatListUnreadCount() const {
@ -1997,7 +1996,7 @@ bool History::loadedAtTop() const {
bool History::isReadyFor(MsgId msgId) {
if (msgId < 0 && -msgId < ServerMaxMsgId && peer->migrateFrom()) {
// Old group history.
return App::history(peer->migrateFrom()->id)->isReadyFor(-msgId);
return owner().history(peer->migrateFrom()->id)->isReadyFor(-msgId);
}
if (msgId == ShowAtTheEndMsgId) {
@ -2005,7 +2004,7 @@ bool History::isReadyFor(MsgId msgId) {
}
if (msgId == ShowAtUnreadMsgId) {
if (const auto migratePeer = peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(migratePeer)) {
if (const auto migrated = owner().historyLoaded(migratePeer)) {
if (migrated->unreadCount()) {
return migrated->isReadyFor(msgId);
}
@ -2026,7 +2025,7 @@ bool History::isReadyFor(MsgId msgId) {
void History::getReadyFor(MsgId msgId) {
if (msgId < 0 && -msgId < ServerMaxMsgId && peer->migrateFrom()) {
const auto migrated = App::history(peer->migrateFrom()->id);
const auto migrated = owner().history(peer->migrateFrom()->id);
migrated->getReadyFor(-msgId);
if (migrated->isEmpty()) {
unloadBlocks();
@ -2035,7 +2034,7 @@ void History::getReadyFor(MsgId msgId) {
}
if (msgId == ShowAtUnreadMsgId) {
if (const auto migratePeer = peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(migratePeer)) {
if (const auto migrated = owner().historyLoaded(migratePeer)) {
if (migrated->unreadCount()) {
unloadBlocks();
migrated->getReadyFor(msgId);
@ -2047,7 +2046,7 @@ void History::getReadyFor(MsgId msgId) {
if (!isReadyFor(msgId)) {
unloadBlocks();
if (const auto migratePeer = peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(migratePeer)) {
if (const auto migrated = owner().historyLoaded(migratePeer)) {
migrated->unloadBlocks();
}
}
@ -2383,7 +2382,7 @@ void History::dialogEntryApplied() {
} else if (const auto channel = peer->asChannel()) {
const auto inviter = channel->inviter;
if (inviter != 0 && channel->amIn()) {
if (const auto from = App::userLoaded(inviter)) {
if (const auto from = owner().userLoaded(inviter)) {
unloadBlocks();
addNewerSlice(QVector<MTPMessage>());
insertJoinedMessage(true);
@ -2401,7 +2400,7 @@ void History::dialogEntryApplied() {
if (inviter > 0
&& chatListTimeId() <= channel->inviteDate
&& channel->amIn()) {
if (const auto from = App::userLoaded(inviter)) {
if (const auto from = owner().userLoaded(inviter)) {
insertJoinedMessage(true);
}
}
@ -2582,15 +2581,15 @@ bool History::isMegagroup() const {
not_null<History*> History::migrateToOrMe() const {
if (const auto to = peer->migrateTo()) {
return App::history(to);
return owner().history(to);
}
// We could get it by App::history(peer), but we optimize.
// We could get it by owner().history(peer), but we optimize.
return const_cast<History*>(this);
}
History *History::migrateFrom() const {
if (const auto from = peer->migrateFrom()) {
return App::history(from);
return owner().history(from);
}
return nullptr;
}
@ -2636,7 +2635,7 @@ HistoryService *History::insertJoinedMessage(bool unread) {
}
const auto inviter = (peer->asChannel()->inviter > 0)
? App::userLoaded(peer->asChannel()->inviter)
? owner().userLoaded(peer->asChannel()->inviter)
: nullptr;
if (!inviter) {
return nullptr;

View file

@ -164,7 +164,7 @@ HistoryItem::HistoryItem(
UserId from)
: id(id)
, _history(history)
, _from(from ? App::user(from) : history->peer)
, _from(from ? history->owner().user(from) : history->peer)
, _flags(flags)
, _date(date) {
App::historyRegItem(this);

View file

@ -21,11 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_user.h"
#include "data/data_file_origin.h"
#include "auth_session.h"
#include "styles/style_widgets.h"
#include "styles/style_history.h"
void HistoryMessageVia::create(UserId userId) {
bot = App::user(peerFromUser(userId));
bot = Auth().data().user(userId);
maxWidth = st::msgServiceNameFont->width(
lng_inline_bot_via(lt_inline_bot, '@' + bot->username));
link = std::make_shared<LambdaClickHandler>([bot = this->bot] {

View file

@ -185,7 +185,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
continue;
}
const auto history = App::history(peer);
const auto history = peer->owner().history(peer);
if (!comment.text.isEmpty()) {
auto message = ApiWrap::MessageToSend(history);
message.textWithTags = comment;
@ -673,10 +673,12 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
}
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
forwarded->originalDate = config.originalDate;
forwarded->originalSender = App::peer(config.senderOriginal);
forwarded->originalSender = history()->owner().peer(
config.senderOriginal);
forwarded->originalId = config.originalId;
forwarded->originalAuthor = config.authorOriginal;
forwarded->savedFromPeer = App::peerLoaded(config.savedFromPeer);
forwarded->savedFromPeer = history()->owner().peerLoaded(
config.savedFromPeer);
forwarded->savedFromMsgId = config.savedFromMsgId;
}
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
@ -789,7 +791,7 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
return media.vphoto.match([&](const MTPDphoto &photo) -> Result {
return std::make_unique<Data::MediaPhoto>(
item,
item->history()->owner().photo(photo));
item->history()->owner().processPhoto(photo));
}, [](const MTPDphotoEmpty &) -> Result {
return nullptr;
});
@ -809,7 +811,7 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
return document.match([&](const MTPDdocument &document) -> Result {
return std::make_unique<Data::MediaFile>(
item,
item->history()->owner().document(document));
item->history()->owner().processDocument(document));
}, [](const MTPDdocumentEmpty &) -> Result {
return nullptr;
});
@ -819,11 +821,11 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
}, [&](const MTPDwebPagePending &webpage) -> Result {
return std::make_unique<Data::MediaWebPage>(
item,
item->history()->owner().webpage(webpage));
item->history()->owner().processWebpage(webpage));
}, [&](const MTPDwebPage &webpage) -> Result {
return std::make_unique<Data::MediaWebPage>(
item,
item->history()->owner().webpage(webpage));
item->history()->owner().processWebpage(webpage));
}, [](const MTPDwebPageNotModified &) -> Result {
LOG(("API Error: "
"webPageNotModified is unexpected in message media."));
@ -833,14 +835,14 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
return media.vgame.match([&](const MTPDgame &game) {
return std::make_unique<Data::MediaGame>(
item,
item->history()->owner().game(game));
item->history()->owner().processGame(game));
});
}, [&](const MTPDmessageMediaInvoice &media) -> Result {
return std::make_unique<Data::MediaInvoice>(item, media);
}, [&](const MTPDmessageMediaPoll &media) -> Result {
return std::make_unique<Data::MediaPoll>(
item,
item->history()->owner().poll(media));
item->history()->owner().processPoll(media));
}, [](const MTPDmessageMediaEmpty &) -> Result {
return nullptr;
}, [](const MTPDmessageMediaUnsupported &) -> Result {

View file

@ -39,7 +39,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
auto result = PreparedText{};
auto &users = action.vusers.v;
if (users.size() == 1) {
auto u = App::user(peerFromUser(users[0]));
auto u = history()->owner().user(users[0].v);
if (u == _from) {
result.links.push_back(fromLink());
result.text = lng_action_user_joined(lt_from, fromLinkText());
@ -54,7 +54,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
} else {
result.links.push_back(fromLink());
for (auto i = 0, l = users.size(); i != l; ++i) {
auto user = App::user(peerFromUser(users[i]));
auto user = history()->owner().user(users[i].v);
result.links.push_back(user->createOpenLink());
auto linkText = textcmdLink(i + 2, user->name);
@ -113,7 +113,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
result.links.push_back(fromLink());
result.text = lng_action_user_left(lt_from, fromLinkText());
} else {
auto user = App::user(peerFromUser(action.vuser_id));
auto user = history()->owner().user(action.vuser_id.v);
result.links.push_back(fromLink());
result.links.push_back(user->createOpenLink());
result.text = lng_action_kick_user(lt_from, fromLinkText(), lt_user, textcmdLink(2, user->name));
@ -293,7 +293,7 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
_media = std::make_unique<Data::MediaPhoto>(
this,
history()->peer,
history()->owner().photo(photo));
history()->owner().processPhoto(photo));
}, [](const MTPDphotoEmpty &) {
});
}, [&](const MTPDmessageActionChatCreate &) {

View file

@ -1290,7 +1290,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U
return false;
}
bot->botInfo->inlineReturnPeerId = 0;
History *h = App::history(toPeerId);
const auto h = bot->owner().history(toPeerId);
TextWithTags textWithTags = { '@' + bot->username + ' ' + query, TextWithTags::Tags() };
MessageCursor cursor = { textWithTags.text.size(), textWithTags.text.size(), QFIXED_MAX };
h->setLocalDraft(std::make_unique<Data::Draft>(textWithTags, 0, cursor, false));
@ -1596,7 +1596,7 @@ void HistoryWidget::showHistory(
_historyInited = false;
if (peerId) {
_peer = App::peer(peerId);
_peer = Auth().data().peer(peerId);
_channel = peerToChannel(_peer->id);
_canSendMessages = _peer->canWrite();
_tabbedSelector->setCurrentPeer(_peer);
@ -1626,7 +1626,7 @@ void HistoryWidget::showHistory(
if (_peer) {
Auth().downloader().clearPriorities();
_history = App::history(_peer);
_history = _peer->owner().history(_peer);
_migrated = _history->migrateFrom();
if (_migrated
&& !_migrated->isEmpty()
@ -2153,7 +2153,7 @@ void HistoryWidget::newUnreadMsg(
void HistoryWidget::historyToDown(History *history) {
history->forgetScrollState();
if (auto migrated = App::historyLoaded(history->peer->migrateFrom())) {
if (auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) {
migrated->forgetScrollState();
}
if (history == _history) {
@ -2218,15 +2218,15 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
switch (messages.type()) {
case mtpc_messages_messages: {
auto &d(messages.c_messages_messages());
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_history->owner().processUsers(d.vusers);
_history->owner().processChats(d.vchats);
histList = &d.vmessages.v;
count = histList->size();
} break;
case mtpc_messages_messagesSlice: {
auto &d(messages.c_messages_messagesSlice());
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_history->owner().processUsers(d.vusers);
_history->owner().processChats(d.vchats);
histList = &d.vmessages.v;
count = d.vcount.v;
} break;
@ -2237,8 +2237,8 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
} else {
LOG(("API Error: received messages.channelMessages when no channel was passed! (HistoryWidget::messagesReceived)"));
}
App::feedUsers(d.vusers);
App::feedChats(d.vchats);
_history->owner().processUsers(d.vusers);
_history->owner().processChats(d.vchats);
histList = &d.vmessages.v;
count = d.vcount.v;
} break;
@ -3449,7 +3449,7 @@ void HistoryWidget::inlineBotResolveDone(
const auto &data = result.c_contacts_resolvedPeer();
// Notify::inlineBotRequesting(false);
const auto resolvedBot = [&]() -> UserData* {
if (const auto result = App::feedUsers(data.vusers)) {
if (const auto result = Auth().data().processUsers(data.vusers)) {
if (result->botInfo
&& !result->botInfo->inlinePlaceholder.isEmpty()) {
return result;
@ -3457,7 +3457,7 @@ void HistoryWidget::inlineBotResolveDone(
}
return nullptr;
}();
App::feedChats(data.vchats);
Auth().data().processChats(data.vchats);
const auto query = ParseInlineBotQuery(_field);
if (_inlineBotUsername == query.username) {
@ -4200,7 +4200,7 @@ void HistoryWidget::sendFileConfirmed(
Auth().uploader().upload(newId, file);
const auto history = App::history(file->to.peer);
const auto history = Auth().data().history(file->to.peer);
const auto peer = history->peer;
auto options = ApiWrap::SendOptions(history);
@ -5897,7 +5897,7 @@ void HistoryWidget::gotPreview(QString links, const MTPMessageMedia &result, mtp
}
if (result.type() == mtpc_messageMediaWebPage) {
const auto &data = result.c_messageMediaWebPage().vwebpage;
const auto page = Auth().data().webpage(data);
const auto page = Auth().data().processWebpage(data);
_previewCache.insert(links, page->id);
if (page->pendingTill > 0 && page->pendingTill <= unixtime()) {
page->pendingTill = -1;

View file

@ -93,7 +93,9 @@ QSize HistoryContact::countOptimalSize() {
const auto item = _parent->data();
auto maxWidth = st::msgFileMinWidth;
_contact = _userId ? App::userLoaded(_userId) : nullptr;
_contact = _userId
? item->history()->owner().userLoaded(_userId)
: nullptr;
if (_contact) {
_contact->loadUserpic();
} else {

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/scroll_area.h"
#include "ui/search_field_controller.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "apiwrap.h"
#include "styles/style_info.h"
#include "styles/style_widgets.h"
@ -101,13 +102,13 @@ void ListController::loadMoreRows() {
return data.vchats.v;
});
if (!chats.empty()) {
for (const auto &chatData : chats) {
if (const auto chat = App::feedChat(chatData)) {
if (!chat->migrateTo()) {
for (const auto &chat : chats) {
if (const auto peer = _user->owner().processChat(chat)) {
if (!peer->migrateTo()) {
delegate()->peerListAppendRow(
createRow(chat));
createRow(peer));
}
_preloadGroupId = chat->bareId();
_preloadGroupId = peer->bareId();
_allLoaded = false;
}
}

View file

@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/search_field_controller.h"
#include "ui/widgets/scroll_area.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "auth_session.h"
#include "styles/style_info.h"
namespace Info {
@ -28,7 +30,7 @@ object_ptr<ContentWidget> Memento::createWidget(
auto result = object_ptr<Widget>(
parent,
controller,
App::user(userId()));
Auth().data().user(userId()));
result->setInternalState(geometry, this);
return std::move(result);
}

View file

@ -111,7 +111,7 @@ auto ChannelsController::createRow(not_null<History*> history)
std::unique_ptr<PeerListRow> ChannelsController::createRestoredRow(
not_null<PeerData*> peer) {
return createRow(App::history(peer));
return createRow(peer->owner().history(peer));
}
void ChannelsController::prepare() {
@ -274,8 +274,8 @@ void NotificationsController::applyFeedDialogs(
const MTPmessages_Dialogs &result) {
const auto [dialogsList, messagesList] = [&] {
const auto process = [&](const auto &data) {
App::feedUsers(data.vusers);
App::feedChats(data.vchats);
_feed->owner().processUsers(data.vusers);
_feed->owner().processChats(data.vchats);
return std::make_tuple(&data.vdialogs.v, &data.vmessages.v);
};
switch (result.type()) {
@ -303,7 +303,7 @@ void NotificationsController::applyFeedDialogs(
case mtpc_dialog: {
if (const auto peerId = peerFromMTP(dialog.c_dialog().vpeer)) {
if (peerIsChannel(peerId)) {
const auto history = App::history(peerId);
const auto history = Auth().data().history(peerId);
const auto channel = history->peer->asChannel();
history->applyDialog(dialog.c_dialog());
channels.emplace_back(channel);
@ -422,7 +422,7 @@ void EditController::loadMoreRows() {
//
// for (const auto &chat : data.vchats.v) {
// if (chat.type() == mtpc_channel) {
// channels.push_back(App::channel(chat.c_channel().vid.v));
// channels.push_back(_feed->owner().channel(chat.c_channel().vid.v));
// }
// }
// } break;

View file

@ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_section_widget.h"
#include "info/info_controller.h"
#include "boxes/peer_list_box.h"
#include "data/data_session.h"
#include "auth_session.h"
#include "styles/style_info.h"
#include "styles/style_profile.h"
@ -259,7 +261,7 @@ void ContentWidget::refreshSearchField(bool shown) {
Key ContentMemento::key() const {
if (const auto peerId = this->peerId()) {
return Key(App::peer(peerId));
return Key(Auth().data().peer(peerId));
} else if (const auto feed = this->feed()) {
return Key(feed);
} else {

View file

@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_peer.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_session.h"
#include "auth_session.h"
#include "window/window_controller.h"
namespace Info {
@ -26,7 +28,7 @@ namespace {
not_null<PeerData*> CorrectPeer(PeerId peerId) {
Expects(peerId != 0);
auto result = App::peer(peerId);
const auto result = Auth().data().peer(peerId);
if (const auto to = result->migrateTo()) {
return to;
}
@ -84,6 +86,11 @@ rpl::producer<QString> AbstractController::mediaSourceQueryValue() const {
return rpl::single(QString());
}
AbstractController::AbstractController(not_null<Window::Controller*> parent)
: Navigation(&parent->session())
, _parent(parent) {
}
PeerId AbstractController::peerId() const {
if (const auto peer = key().peer()) {
return peer->id;
@ -117,7 +124,7 @@ Controller::Controller(
, _widget(widget)
, _key(memento->key())
, _migrated(memento->migratedPeerId()
? App::peer(memento->migratedPeerId()).get()
? Auth().data().peer(memento->migratedPeerId()).get()
: nullptr)
, _section(memento->section()) {
updateSearchControllers(memento);

View file

@ -99,9 +99,7 @@ private:
class AbstractController : public Window::Navigation {
public:
AbstractController(not_null<Window::Controller*> parent)
: _parent(parent) {
}
AbstractController(not_null<Window::Controller*> parent);
virtual Key key() const = 0;
virtual PeerData *migrated() const = 0;

View file

@ -20,6 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peer_list_box.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_session.h"
#include "auth_session.h"
namespace Info {
@ -90,7 +92,7 @@ std::unique_ptr<ContentMemento> Memento::DefaultContent(
Section section) {
Expects(peerId != 0);
auto peer = App::peer(peerId);
auto peer = Auth().data().peer(peerId);
if (auto to = peer->migrateTo()) {
peer = to;
}

View file

@ -199,7 +199,7 @@ Key WrapWidget::key() const {
Dialogs::RowDescriptor WrapWidget::activeChat() const {
if (const auto peer = key().peer()) {
return Dialogs::RowDescriptor(App::history(peer), FullMsgId());
return Dialogs::RowDescriptor(peer->owner().history(peer), FullMsgId());
} else if (const auto feed = key().feed()) {
return Dialogs::RowDescriptor(feed, FullMsgId());
} else if (key().settingsSelf()) {

View file

@ -102,10 +102,10 @@ std::unique_ptr<Result> Result::create(uint64 queryId, const MTPBotInlineResult
if (r.has_title()) result->_title = qs(r.vtitle);
if (r.has_description()) result->_description = qs(r.vdescription);
if (r.has_photo()) {
result->_photo = Auth().data().photo(r.vphoto);
result->_photo = Auth().data().processPhoto(r.vphoto);
}
if (r.has_document()) {
result->_document = Auth().data().document(r.vdocument);
result->_document = Auth().data().processDocument(r.vdocument);
}
message = &r.vsend_message;
} break;

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_channel.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "styles/style_chat_helpers.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h"
@ -1023,7 +1024,7 @@ void Widget::inlineResultsDone(const MTPmessages_BotResults &result) {
auto adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) {
auto &d = result.c_messages_botResults();
App::feedUsers(d.vusers);
Auth().data().processUsers(d.vusers);
auto &v = d.vresults.v;
auto queryId = d.vquery_id.v;

File diff suppressed because it is too large Load diff

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/player/media_player_float.h"
#include "data/data_pts_waiter.h"
class AuthSession;
struct HistoryMessageMarkupButton;
class MainWindow;
class ConfirmBox;
@ -97,6 +98,8 @@ public:
MainWidget(QWidget *parent, not_null<Window::Controller*> controller);
AuthSession &session() const;
bool isMainSectionShown() const;
bool isThirdSectionShown() const;

View file

@ -2647,7 +2647,7 @@ void MediaView::setContext(base::optional_variant<
} else if (auto peer = base::get_if<not_null<PeerData*>>(&context)) {
_msgid = FullMsgId();
_canForwardItem = _canDeleteItem = false;
_history = App::history(*peer);
_history = (*peer)->owner().history(*peer);
_peer = *peer;
} else {
_msgid = FullMsgId();
@ -2658,10 +2658,10 @@ void MediaView::setContext(base::optional_variant<
_migrated = nullptr;
if (_history) {
if (_history->peer->migrateFrom()) {
_migrated = App::history(_history->peer->migrateFrom()->id);
_migrated = _history->owner().history(_history->peer->migrateFrom());
} else if (_history->peer->migrateTo()) {
_migrated = _history;
_history = App::history(_history->peer->migrateTo()->id);
_history = _history->owner().history(_history->peer->migrateTo());
}
}
_user = _peer ? _peer->asUser() : nullptr;

View file

@ -2491,7 +2491,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
const auto &data = result.c_account_authorizationForm();
App::feedUsers(data.vusers);
Auth().data().processUsers(data.vusers);
for (const auto &value : data.vvalues.v) {
auto parsed = parseValue(value);
@ -2525,7 +2525,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
if (!ValidateForm(_form)) {
return false;
}
_bot = App::userLoaded(_request.botId);
_bot = Auth().data().userLoaded(_request.botId);
_form.pendingErrors = data.verrors.v;
return true;
}

View file

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/profile/info_profile_button.h"
#include "info/profile/info_profile_cover.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "lang/lang_keys.h"
#include "storage/localstorage.h"
#include "auth_session.h"
@ -224,8 +225,7 @@ void SetupHelp(not_null<Ui::VerticalLayout*> container) {
st::settingsSectionButton);
button->addClickHandler([=] {
const auto ready = crl::guard(button, [](const MTPUser &data) {
const auto users = MTP_vector<MTPUser>(1, data);
if (const auto user = App::feedUsers(users)) {
if (const auto user = Auth().data().processUser(data)) {
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
}
});

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "auth_session.h"
#include "storage/localstorage.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "history/history.h"
#include "calls/calls_instance.h"
#include "ui/widgets/checkbox.h"
@ -111,7 +112,10 @@ void BlockedBoxController::loadMoreRows() {
return;
}
_loadRequestId = request(MTPcontacts_GetBlocked(MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPcontacts_Blocked &result) {
_loadRequestId = request(MTPcontacts_GetBlocked(
MTP_int(_offset),
MTP_int(kBlockedPerPage)
)).done([=](const MTPcontacts_Blocked &result) {
_loadRequestId = 0;
if (!_offset) {
@ -119,7 +123,7 @@ void BlockedBoxController::loadMoreRows() {
}
auto handleContactsBlocked = [](auto &list) {
App::feedUsers(list.vusers);
Auth().data().processUsers(list.vusers);
return list.vblocked.v;
};
switch (result.type()) {
@ -162,7 +166,7 @@ void BlockedBoxController::receivedUsers(const QVector<MTPContactBlocked> &resul
}
auto &contactBlocked = item.c_contactBlocked();
auto userId = contactBlocked.vuser_id.v;
if (auto user = App::userLoaded(userId)) {
if (auto user = Auth().data().userLoaded(userId)) {
appendRow(user);
user->setBlockStatus(UserData::BlockStatus::Blocked);
}

View file

@ -139,13 +139,16 @@ Uploader::Uploader() {
connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions()));
}
void Uploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &media) {
void Uploader::uploadMedia(
const FullMsgId &msgId,
const SendMediaReady &media) {
if (media.type == SendMediaType::Photo) {
Auth().data().photo(media.photo, media.photoThumbs);
} else if (media.type == SendMediaType::File || media.type == SendMediaType::Audio) {
Auth().data().processPhoto(media.photo, media.photoThumbs);
} else if (media.type == SendMediaType::File
|| media.type == SendMediaType::Audio) {
const auto document = media.photoThumbs.isEmpty()
? Auth().data().document(media.document)
: Auth().data().document(
? Auth().data().processDocument(media.document)
: Auth().data().processDocument(
media.document,
base::duplicate(media.photoThumbs.begin().value()));
if (!media.data.isEmpty()) {
@ -171,15 +174,20 @@ void Uploader::upload(
const FullMsgId &msgId,
const std::shared_ptr<FileLoadResult> &file) {
if (file->type == SendMediaType::Photo) {
auto photo = Auth().data().photo(file->photo, file->photoThumbs);
photo->uploadingData = std::make_unique<Data::UploadState>(file->partssize);
} else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) {
auto document = file->thumb.isNull()
? Auth().data().document(file->document)
: Auth().data().document(
const auto photo = Auth().data().processPhoto(
file->photo,
file->photoThumbs);
photo->uploadingData = std::make_unique<Data::UploadState>(
file->partssize);
} else if (file->type == SendMediaType::File
|| file->type == SendMediaType::Audio) {
const auto document = file->thumb.isNull()
? Auth().data().processDocument(file->document)
: Auth().data().processDocument(
file->document,
std::move(file->thumb));
document->uploadingData = std::make_unique<Data::UploadState>(document->size);
document->uploadingData = std::make_unique<Data::UploadState>(
document->size);
document->setGoodThumbnail(
std::move(file->goodThumbnail),
std::move(file->goodThumbnailBytes));

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "ui/image/image.h"
namespace Serialize {
@ -154,10 +155,10 @@ PeerData *readPeer(int streamAppVersion, QDataStream &stream) {
streamAppVersion,
stream);
PeerData *result = App::peerLoaded(peerId);
PeerData *result = Auth().data().peerLoaded(peerId);
bool wasLoaded = (result != nullptr);
if (!wasLoaded) {
result = App::peer(peerId);
result = Auth().data().peer(peerId);
result->loadedStatus = PeerData::FullLoaded;
}
if (const auto user = result->asUser()) {

View file

@ -80,7 +80,7 @@ struct UserPhotosKey {
return !(*this == other);
}
PeerId userId = 0;
UserId userId = 0;
PhotoId photoId = 0;
};

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h"
#include "data/data_drafts.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "history/history.h"
#include "boxes/abstract_box.h"
#include "ui/toast/toast.h"
@ -579,7 +580,7 @@ QString InterpretSendPath(const QString &path) {
return "App Error: Invalid command: " + line;
}
}
const auto history = App::historyLoaded(toId);
const auto history = Auth().data().historyLoaded(toId);
if (!history) {
return "App Error: Could not find channel with id: " + QString::number(peerToChannel(toId));
}

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/qthelp_url.h"
#include "ui/emoji_config.h"
#include "data/data_user.h"
#include "data/data_session.h"
namespace TextUtilities {
namespace {
@ -1472,7 +1473,7 @@ EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
case mtpc_messageEntityMentionName: {
auto &d = entity.c_messageEntityMentionName();
auto data = [&d] {
if (auto user = App::userLoaded(peerFromUser(d.vuser_id))) {
if (auto user = Auth().data().userLoaded(d.vuser_id.v)) {
return MentionNameDataFromFields({
d.vuser_id.v,
user->accessHash() });

View file

@ -586,7 +586,7 @@ void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
void MainWindow::checkAuthSession() {
if (AuthSession::Exists()) {
_controller = std::make_unique<Window::Controller>(this);
_controller = std::make_unique<Window::Controller>(&Auth(), this);
} else {
_controller = nullptr;
}

View file

@ -396,7 +396,7 @@ Manager::DisplayOptions Manager::getNotificationOptions(HistoryItem *item) {
void Manager::notificationActivated(PeerId peerId, MsgId msgId) {
onBeforeNotificationActivated(peerId, msgId);
if (auto window = App::wnd()) {
auto history = App::history(peerId);
auto history = Auth().data().history(peerId);
window->showFromTray();
window->reActivateWindow();
if (Messenger::Instance().locked()) {
@ -447,7 +447,7 @@ void Manager::notificationReplied(
const TextWithTags &reply) {
if (!peerId) return;
const auto history = App::history(peerId);
const auto history = Auth().data().history(peerId);
auto message = ApiWrap::MessageToSend(history);
message.textWithTags = reply;

View file

@ -50,10 +50,61 @@ void DateClickHandler::onClick(ClickContext context) const {
App::wnd()->controller()->showJumpToDate(_chat, _date);
}
Controller::Controller(not_null<MainWindow*> window)
: _window(window) {
Auth().data().animationPlayInlineRequest(
) | rpl::start_with_next([this](auto item) {
Navigation::Navigation(not_null<AuthSession*> session) : _session(session) {
}
AuthSession &Navigation::session() const {
return *_session;
}
void Navigation::showPeerInfo(
PeerId peerId,
const SectionShow &params) {
//if (Adaptive::ThreeColumn()
// && !_session->settings().thirdSectionInfoEnabled()) {
// _session->settings().setThirdSectionInfoEnabled(true);
// _session->saveSettingsDelayed();
//}
showSection(Info::Memento(peerId), params);
}
void Navigation::showPeerInfo(
not_null<PeerData*> peer,
const SectionShow &params) {
showPeerInfo(peer->id, params);
}
void Navigation::showPeerInfo(
not_null<History*> history,
const SectionShow &params) {
showPeerInfo(history->peer->id, params);
}
void Navigation::showSettings(
Settings::Type type,
const SectionShow &params) {
showSection(
Info::Memento(
Info::Settings::Tag{ _session->user() },
Info::Section(type)),
params);
}
void Navigation::showSettings(const SectionShow &params) {
showSettings(Settings::Type::Main, params);
}
Controller::Controller(
not_null<AuthSession*> session,
not_null<MainWindow*> window)
: Navigation(session)
, _window(window) {
init();
}
void Controller::init() {
session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](auto item) {
if (const auto video = roundVideo(item)) {
video->pauseResume();
} else {
@ -61,13 +112,13 @@ Controller::Controller(not_null<MainWindow*> window)
}
}, lifetime());
if (Auth().supportMode()) {
if (session().supportMode()) {
initSupportMode();
}
}
void Controller::initSupportMode() {
Auth().supportHelper().registerWindow(this);
session().supportHelper().registerWindow(this);
Shortcuts::Requests(
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
@ -84,7 +135,7 @@ void Controller::initSupportMode() {
void Controller::setActiveChatEntry(Dialogs::RowDescriptor row) {
_activeChatEntry = row;
if (Auth().supportMode()) {
if (session().supportMode()) {
pushToChatEntryHistory(row);
}
}
@ -229,8 +280,8 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
if (bodyWidth < minimalThreeColumnWidth()) {
return true;
}
if (!Auth().settings().tabbedSelectorSectionEnabled()
&& !Auth().settings().thirdSectionInfoEnabled()) {
if (!session().settings().tabbedSelectorSectionEnabled()
&& !session().settings().thirdSectionInfoEnabled()) {
return true;
}
return false;
@ -260,14 +311,14 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
}
int Controller::countDialogsWidthFromRatio(int bodyWidth) const {
auto result = qRound(bodyWidth * Auth().settings().dialogsWidthRatio());
auto result = qRound(bodyWidth * session().settings().dialogsWidthRatio());
accumulate_max(result, st::columnMinimalWidthLeft);
// accumulate_min(result, st::columnMaximalWidthLeft);
return result;
}
int Controller::countThirdColumnWidthFromRatio(int bodyWidth) const {
auto result = Auth().settings().thirdColumnWidth();
auto result = session().settings().thirdColumnWidth();
accumulate_max(result, st::columnMinimalWidthThird);
accumulate_min(result, st::columnMaximalWidthThird);
return result;
@ -320,11 +371,11 @@ void Controller::resizeForThirdSection() {
auto layout = computeColumnLayout();
auto tabbedSelectorSectionEnabled =
Auth().settings().tabbedSelectorSectionEnabled();
session().settings().tabbedSelectorSectionEnabled();
auto thirdSectionInfoEnabled =
Auth().settings().thirdSectionInfoEnabled();
Auth().settings().setTabbedSelectorSectionEnabled(false);
Auth().settings().setThirdSectionInfoEnabled(false);
session().settings().thirdSectionInfoEnabled();
session().settings().setTabbedSelectorSectionEnabled(false);
session().settings().setThirdSectionInfoEnabled(false);
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
auto minimal = st::columnMinimalWidthThird;
@ -345,20 +396,20 @@ void Controller::resizeForThirdSection() {
return window()->tryToExtendWidthBy(minimal);
}();
if (extendedBy) {
if (extendBy != Auth().settings().thirdColumnWidth()) {
Auth().settings().setThirdColumnWidth(extendBy);
if (extendBy != session().settings().thirdColumnWidth()) {
session().settings().setThirdColumnWidth(extendBy);
}
auto newBodyWidth = layout.bodyWidth + extendedBy;
auto currentRatio = Auth().settings().dialogsWidthRatio();
Auth().settings().setDialogsWidthRatio(
auto currentRatio = session().settings().dialogsWidthRatio();
session().settings().setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth);
}
auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
Auth().settings().setThirdSectionExtendedBy(savedValue);
session().settings().setThirdSectionExtendedBy(savedValue);
Auth().settings().setTabbedSelectorSectionEnabled(
session().settings().setTabbedSelectorSectionEnabled(
tabbedSelectorSectionEnabled);
Auth().settings().setThirdSectionInfoEnabled(
session().settings().setThirdSectionInfoEnabled(
thirdSectionInfoEnabled);
}
@ -368,23 +419,23 @@ void Controller::closeThirdSection() {
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
auto noResize = window()->isFullScreen()
|| window()->isMaximized();
auto savedValue = Auth().settings().thirdSectionExtendedBy();
auto savedValue = session().settings().thirdSectionExtendedBy();
auto extendedBy = (savedValue == -1)
? layout.thirdWidth
: savedValue;
auto newBodyWidth = noResize
? layout.bodyWidth
: (layout.bodyWidth - extendedBy);
auto currentRatio = Auth().settings().dialogsWidthRatio();
Auth().settings().setDialogsWidthRatio(
auto currentRatio = session().settings().dialogsWidthRatio();
session().settings().setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth);
newWindowSize = QSize(
window()->width() + (newBodyWidth - layout.bodyWidth),
window()->height());
}
Auth().settings().setTabbedSelectorSectionEnabled(false);
Auth().settings().setThirdSectionInfoEnabled(false);
Auth().saveSettingsDelayed();
session().settings().setTabbedSelectorSectionEnabled(false);
session().settings().setThirdSectionInfoEnabled(false);
session().saveSettingsDelayed();
if (window()->size() != newWindowSize) {
window()->resize(newWindowSize);
} else {
@ -400,7 +451,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
} else if (history->loadedAtTop()
&& !history->isEmpty()
&& history->peer->migrateFrom()) {
if (const auto migrated = App::historyLoaded(history->peer->migrateFrom())) {
if (const auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) {
if (migrated->scrollTopItem) {
// We're up in the migrated history.
// So current date is the date of first message here.
@ -422,7 +473,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
const auto maxPeerDate = [](Dialogs::Key chat) {
if (auto history = chat.history()) {
if (const auto channel = history->peer->migrateTo()) {
history = App::historyLoaded(channel);
history = channel->owner().historyLoaded(channel);
}
if (history && history->chatListTimeId() != 0) {
return ParseDateTime(history->chatListTimeId()).date();
@ -441,7 +492,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
};
if (const auto history = chat.history()) {
if (const auto chat = history->peer->migrateFrom()) {
if (const auto history = App::historyLoaded(chat)) {
if (const auto history = chat->owner().historyLoaded(chat)) {
if (history->loadedAtTop()) {
if (!history->isEmpty()) {
return history->blocks.front()->messages.front()->dateTime().date();
@ -467,7 +518,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
: requestedDate;
const auto month = highlighted;
auto callback = [=](const QDate &date) {
Auth().api().jumpToDate(chat, date);
session().api().jumpToDate(chat, date);
};
auto box = Box<CalendarBox>(
month,
@ -523,43 +574,6 @@ void Controller::showPeerHistory(
msgId);
}
void Navigation::showPeerInfo(
PeerId peerId,
const SectionShow &params) {
//if (Adaptive::ThreeColumn()
// && !Auth().settings().thirdSectionInfoEnabled()) {
// Auth().settings().setThirdSectionInfoEnabled(true);
// Auth().saveSettingsDelayed();
//}
showSection(Info::Memento(peerId), params);
}
void Navigation::showPeerInfo(
not_null<PeerData*> peer,
const SectionShow &params) {
showPeerInfo(peer->id, params);
}
void Navigation::showPeerInfo(
not_null<History*> history,
const SectionShow &params) {
showPeerInfo(history->peer->id, params);
}
void Navigation::showSettings(
Settings::Type type,
const SectionShow &params) {
showSection(
Info::Memento(
Info::Settings::Tag{ Auth().user() },
Info::Section(type)),
params);
}
void Navigation::showSettings(const SectionShow &params) {
showSettings(Settings::Type::Main, params);
}
void Controller::showSection(
SectionMemento &&memento,
const SectionShow &params) {

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/flags.h"
#include "dialogs/dialogs_key.h"
class AuthSession;
class MainWidget;
class HistoryMessage;
class HistoryService;
@ -103,6 +104,10 @@ class Controller;
class Navigation {
public:
explicit Navigation(not_null<AuthSession*> session);
AuthSession &session() const;
virtual void showSection(
SectionMemento &&memento,
const SectionShow &params = SectionShow()) = 0;
@ -127,11 +132,16 @@ public:
virtual ~Navigation() = default;
private:
const not_null<AuthSession*> _session;
};
class Controller : public Navigation {
public:
Controller(not_null<MainWindow*> window);
Controller(
not_null<AuthSession*> session,
not_null<MainWindow*> window);
not_null<MainWindow*> window() const {
return _window;
@ -260,6 +270,7 @@ public:
~Controller();
private:
void init();
void initSupportMode();
int minimalThreeColumnWidth() const;
@ -278,7 +289,7 @@ private:
void pushToChatEntryHistory(Dialogs::RowDescriptor row);
bool chatEntryHistoryMove(int steps);
not_null<MainWindow*> _window;
const not_null<MainWindow*> _window;
std::unique_ptr<Passport::FormController> _passportForm;

View file

@ -188,7 +188,7 @@ bool Filler::showInfo() {
void Filler::addPinToggle() {
auto peer = _peer;
auto isPinned = false;
if (auto history = App::historyLoaded(peer)) {
if (auto history = peer->owner().historyLoaded(peer)) {
isPinned = history->isPinnedDialog();
}
auto pinText = [](bool isPinned) {
@ -197,7 +197,7 @@ void Filler::addPinToggle() {
: lng_context_pin_to_top);
};
auto pinToggle = [=] {
TogglePinnedDialog(App::history(peer));
TogglePinnedDialog(peer->owner().history(peer));
};
auto pinAction = _addAction(pinText(isPinned), pinToggle);
@ -206,7 +206,7 @@ void Filler::addPinToggle() {
peer,
Notify::PeerUpdate::Flag::ChatPinnedChanged
) | rpl::start_with_next([peer, pinAction, pinText] {
auto isPinned = App::history(peer)->isPinnedDialog();
auto isPinned = peer->owner().history(peer)->isPinnedDialog();
pinAction->setText(pinText(isPinned));
}, *lifetime);
}
@ -226,14 +226,14 @@ void Filler::addInfo() {
void Filler::addSearch() {
_addAction(lang(lng_profile_search_messages), [peer = _peer] {
App::main()->searchInChat(App::history(peer));
App::main()->searchInChat(peer->owner().history(peer));
});
}
void Filler::addToggleUnreadMark() {
const auto peer = _peer;
const auto isUnread = [](not_null<PeerData*> peer) {
if (const auto history = App::historyLoaded(peer)) {
if (const auto history = peer->owner().historyLoaded(peer)) {
return (history->chatListUnreadCount() > 0)
|| (history->chatListUnreadMark());
}
@ -253,7 +253,7 @@ void Filler::addToggleUnreadMark() {
Auth().api().changeDialogUnreadMark(history, !markAsRead);
}
};
const auto history = App::history(peer);
const auto history = peer->owner().history(peer);
handle(history);
if (markAsRead) {
if (const auto migrated = history->migrateSibling()) {
@ -447,7 +447,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
void Filler::fill() {
if (_source == PeerMenuSource::ChatsList) {
if (const auto history = App::historyLoaded(_peer)) {
if (const auto history = _peer->owner().historyLoaded(_peer)) {
if (!history->useProxyPromotion()) {
addPinToggle();
}
@ -598,7 +598,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
LayerOption::KeepOther);
return;
} else if (peer->isSelf()) {
auto options = ApiWrap::SendOptions(App::history(peer));
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
Auth().api().shareContact(user, options);
Ui::Toast::Show(lang(lng_share_done));
if (auto strong = *weak) {
@ -613,7 +613,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
lng_forward_share_contact(lt_recipient, recipient),
lang(lng_forward_send),
[peer, user] {
const auto history = App::history(peer);
const auto history = peer->owner().history(peer);
Ui::showPeerHistory(history, ShowAtTheEndMsgId);
auto options = ApiWrap::SendOptions(history);
Auth().api().shareContact(user, options);
@ -636,7 +636,7 @@ void PeerMenuCreatePoll(not_null<PeerData*> peer) {
if (std::exchange(*lock, true)) {
return;
}
const auto options = ApiWrap::SendOptions(App::history(peer));
const auto options = ApiWrap::SendOptions(peer->owner().history(peer));
Auth().api().createPoll(result, options, crl::guard(box, [=] {
box->closeBox();
}), crl::guard(box, [=](const RPCError &error) {
@ -658,7 +658,7 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
if (peer->isSelf()) {
auto items = Auth().data().idsToItems(ids);
if (!items.empty()) {
auto options = ApiWrap::SendOptions(App::history(peer));
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
options.generateLocal = false;
Auth().api().forwardMessages(std::move(items), options, [] {
Ui::Toast::Show(lang(lng_share_done));
@ -704,7 +704,7 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
return data.vuser_id.v;
});
}) | ranges::view::transform([](UserId userId) {
return App::userLoaded(userId);
return Auth().data().userLoaded(userId);
}) | ranges::view::filter([](UserData *user) {
return (user != nullptr);
}) | ranges::to_vector;