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

View file

@ -130,22 +130,6 @@ namespace App {
return nullptr; 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) { bool checkEntitiesAndViewsUpdate(const MTPDmessage &m) {
auto peerId = peerFromMTP(m.vto_id); auto peerId = peerFromMTP(m.vto_id);
if (m.has_from_id() && peerId == Auth().userPeerId()) { if (m.has_from_id() && peerId == Auth().userPeerId()) {
@ -337,13 +321,13 @@ namespace App {
} }
void feedInboxRead(const PeerId &peer, MsgId upTo) { 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); history->inboxRead(upTo);
} }
} }
void feedOutboxRead(const PeerId &peer, MsgId upTo, TimeId when) { 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); history->outboxRead(upTo);
if (const auto user = history->peer->asUser()) { if (const auto user = history->peer->asUser()) {
user->madeAction(when); user->madeAction(when);
@ -371,7 +355,7 @@ namespace App {
if (!data) return; if (!data) return;
const auto affectedHistory = (channelId != NoChannel) const auto affectedHistory = (channelId != NoChannel)
? App::history(peerFromChannel(channelId)).get() ? Auth().data().history(peerFromChannel(channelId)).get()
: nullptr; : nullptr;
auto historiesToCheck = base::flat_set<not_null<History*>>(); auto historiesToCheck = base::flat_set<not_null<History*>>();
@ -393,7 +377,7 @@ namespace App {
} }
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) { 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); const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd);
switch (myLink.type()) { switch (myLink.type()) {
case mtpc_contactLinkContact: 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) { QString peerName(const PeerData *peer, bool forDialogs) {
return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : lang(lng_deleted); 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) { HistoryItem *histItemById(ChannelId channelId, MsgId itemId) {
if (!itemId) return nullptr; if (!itemId) return nullptr;

View file

@ -65,11 +65,6 @@ namespace App {
QString formatPhone(QString phone); 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 bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
void updateEditedMessage(const MTPMessage &m); void updateEditedMessage(const MTPMessage &m);
void addSavedGif(DocumentData *doc); void addSavedGif(DocumentData *doc);
@ -83,22 +78,9 @@ namespace App {
ImagePtr image(const MTPPhotoSize &size); 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]] 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]] 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( [[nodiscard]] HistoryItem *histItemById(
const ChannelData *channel, const ChannelData *channel,
MsgId itemId); MsgId itemId);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
void ShareBotGame(not_null<UserData*> bot, not_null<PeerData*> chat) { 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 randomId = rand_value<uint64>();
const auto requestId = MTP::send( const auto requestId = MTP::send(
MTPmessages_SendMedia( MTPmessages_SendMedia(
@ -182,8 +182,8 @@ void PeerListGlobalSearchController::searchDone(
auto &contacts = result.c_contacts_found(); auto &contacts = result.c_contacts_found();
auto query = _query; auto query = _query;
if (requestId) { if (requestId) {
App::feedUsers(contacts.vusers); Auth().data().processUsers(contacts.vusers);
App::feedChats(contacts.vchats); Auth().data().processChats(contacts.vchats);
auto it = _queries.find(requestId); auto it = _queries.find(requestId);
if (it != _queries.cend()) { if (it != _queries.cend()) {
query = it->second; query = it->second;
@ -193,7 +193,7 @@ void PeerListGlobalSearchController::searchDone(
} }
const auto feedList = [&](const MTPVector<MTPPeer> &list) { const auto feedList = [&](const MTPVector<MTPPeer> &list) {
for (const auto &mtpPeer : list.v) { 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); delegate()->peerListSearchAddRow(peer);
} }
} }
@ -255,7 +255,7 @@ void ChatsListBoxController::rebuildRows() {
}; };
auto added = 0; auto added = 0;
if (respectSavedMessagesChat()) { if (respectSavedMessagesChat()) {
if (appendRow(App::history(Auth().user()))) { if (appendRow(Auth().data().history(Auth().user()))) {
++added; ++added;
} }
} }
@ -292,7 +292,7 @@ QString ChatsListBoxController::emptyBoxText() const {
} }
std::unique_ptr<PeerListRow> ChatsListBoxController::createSearchRow(not_null<PeerData*> peer) { 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) { 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_channel.h"
#include "data/data_chat.h" #include "data/data_chat.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "history/history.h" #include "history/history.h"
#include "dialogs/dialogs_indexed_list.h" #include "dialogs/dialogs_indexed_list.h"
#include "auth_session.h" #include "auth_session.h"
@ -435,7 +436,7 @@ bool AddSpecialBoxController::checkInfoLoaded(
Expects(result.type() == mtpc_channels_channelParticipant); Expects(result.type() == mtpc_channels_channelParticipant);
const auto &participant = result.c_channels_channelParticipant(); const auto &participant = result.c_channels_channelParticipant();
App::feedUsers(participant.vusers); channel->owner().processUsers(participant.vusers);
_additional.applyParticipant(participant.vparticipant); _additional.applyParticipant(participant.vparticipant);
callback(); callback();
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
@ -964,8 +965,8 @@ void AddSpecialBoxSearchController::searchGlobalDone(
auto &found = result.c_contacts_found(); auto &found = result.c_contacts_found();
auto query = _query; auto query = _query;
if (requestId) { if (requestId) {
App::feedUsers(found.vusers); _peer->owner().processUsers(found.vusers);
App::feedChats(found.vchats); _peer->owner().processChats(found.vchats);
auto it = _globalQueries.find(requestId); auto it = _globalQueries.find(requestId);
if (it != _globalQueries.cend()) { if (it != _globalQueries.cend()) {
query = it->second; query = it->second;
@ -977,7 +978,7 @@ void AddSpecialBoxSearchController::searchGlobalDone(
const auto feedList = [&](const MTPVector<MTPPeer> &list) { const auto feedList = [&](const MTPVector<MTPPeer> &list) {
for (const auto &mtpPeer : list.v) { for (const auto &mtpPeer : list.v) {
const auto peerId = peerFromMTP(mtpPeer); 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()) { if (const auto user = peer->asUser()) {
_additional->checkForLoaded(user); _additional->checkForLoaded(user);
delegate()->peerListSearchAddRow(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 "chat_helpers/emoji_suggestions_widget.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "auth_session.h" #include "auth_session.h"
#include "messenger.h" #include "messenger.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -220,7 +221,7 @@ void ShareBox::prepare() {
applyFilterUpdate(query); applyFilterUpdate(query);
}); });
_select->setItemRemovedCallback([=](uint64 itemId) { _select->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = App::peerLoaded(itemId)) { if (const auto peer = Auth().data().peerLoaded(itemId)) {
_inner->peerUnselected(peer); _inner->peerUnselected(peer);
selectedChanged(); selectedChanged();
update(); update();
@ -334,8 +335,8 @@ void ShareBox::peopleReceived(
switch (result.type()) { switch (result.type()) {
case mtpc_contacts_found: { case mtpc_contacts_found: {
auto &found = result.c_contacts_found(); auto &found = result.c_contacts_found();
App::feedUsers(found.vusers); Auth().data().processUsers(found.vusers);
App::feedChats(found.vchats); Auth().data().processChats(found.vchats);
_inner->peopleReceived( _inner->peopleReceived(
query, query,
found.vmy_results.v, found.vmy_results.v,
@ -491,7 +492,7 @@ ShareBox::Inner::Inner(
const auto dialogs = App::main()->dialogsList(); const auto dialogs = App::main()->dialogsList();
const auto self = Auth().user(); const auto self = Auth().user();
if (_filterCallback(self)) { if (_filterCallback(self)) {
_chatsIndexed->addToEnd(App::history(self)); _chatsIndexed->addToEnd(self->owner().history(self));
} }
for (const auto row : dialogs->all()) { for (const auto row : dialogs->all()) {
if (const auto history = row->history()) { if (const auto history = row->history()) {
@ -880,7 +881,7 @@ void ShareBox::Inner::changeCheckState(Chat *chat) {
if (!chat) return; if (!chat) return;
if (!_filter.isEmpty()) { if (!_filter.isEmpty()) {
const auto history = App::history(chat->peer); const auto history = chat->peer->owner().history(chat->peer);
auto row = _chatsIndexed->getRow(history); auto row = _chatsIndexed->getRow(history);
if (!row) { if (!row) {
const auto rowsByLetter = _chatsIndexed->addToEnd(history); const auto rowsByLetter = _chatsIndexed->addToEnd(history);
@ -1017,8 +1018,8 @@ void ShareBox::Inner::peopleReceived(
d_byUsernameFiltered.reserve(already + my.size() + people.size()); d_byUsernameFiltered.reserve(already + my.size() + people.size());
const auto feedList = [&](const QVector<MTPPeer> &list) { const auto feedList = [&](const QVector<MTPPeer> &list) {
for (const auto &data : list) { for (const auto &data : list) {
if (const auto peer = App::peerLoaded(peerFromMTP(data))) { if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) {
const auto history = App::historyLoaded(peer); const auto history = Auth().data().historyLoaded(peer);
if (!_filterCallback(peer)) { if (!_filterCallback(peer)) {
continue; continue;
} else if (history && _chatsIndexed->getRow(history)) { } else if (history && _chatsIndexed->getRow(history)) {
@ -1066,7 +1067,9 @@ QVector<PeerData*> ShareBox::Inner::selected() const {
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) { QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
auto shareHashData = QByteArray(0x10, Qt::Uninitialized); auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data()); 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 channelAccessHash = channel ? channel->access : 0ULL;
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash); auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
shareHashDataInts[0] = Auth().userId(); 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) { if (channel || !channelId) {
resolveMessageAndShareScore(channel); resolveMessageAndShareScore(channel);
} else { } else {
@ -1177,9 +1182,9 @@ void ShareGameScoreByHash(const QString &hash) {
auto requestChannel = MTPchannels_GetChannels(requestChannelIds); auto requestChannel = MTPchannels_GetChannels(requestChannelIds);
MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) { MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) {
result.match([](const auto &data) { 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); resolveMessageAndShareScore(channel);
} }
})); }));

View file

@ -201,11 +201,11 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) {
auto &v = d.vdocuments.v; auto &v = d.vdocuments.v;
_pack.reserve(v.size()); _pack.reserve(v.size());
_packOvers.reserve(v.size()); _packOvers.reserve(v.size());
for (int i = 0, l = v.size(); i < l; ++i) { for (const auto &item : v) {
auto doc = Auth().data().document(v.at(i)); const auto document = Auth().data().processDocument(item);
if (!doc->sticker()) continue; if (!document->sticker()) continue;
_pack.push_back(doc); _pack.push_back(document);
_packOvers.push_back(Animation()); _packOvers.push_back(Animation());
} }
auto &packs = d.vpacks.v; 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 "ui/toast/toast.h"
#include "messenger.h" #include "messenger.h"
#include "auth_session.h" #include "auth_session.h"
#include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -170,7 +171,7 @@ void UsernameBox::linkClick() {
} }
void UsernameBox::onUpdateDone(const MTPUser &user) { void UsernameBox::onUpdateDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(1, user)); Auth().data().processUser(user);
closeBox(); closeBox();
} }

View file

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

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/media_audio_track.h" #include "media/media_audio_track.h"
#include "calls/calls_panel.h" #include "calls/calls_panel.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#ifdef slots #ifdef slots
#undef slots #undef slots
@ -201,7 +202,7 @@ void Call::startOutgoing() {
setState(State::Waiting); setState(State::Waiting);
auto &call = result.c_phone_phoneCall(); auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers); Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCallWaiting) { if (call.vphone_call.type() != mtpc_phoneCallWaiting) {
LOG(("Call Error: Expected phoneCallWaiting in response to phone.requestCall()")); LOG(("Call Error: Expected phoneCallWaiting in response to phone.requestCall()"));
finish(FinishType::Failed); finish(FinishType::Failed);
@ -273,7 +274,7 @@ void Call::actuallyAnswer() {
)).done([this](const MTPphone_PhoneCall &result) { )).done([this](const MTPphone_PhoneCall &result) {
Expects(result.type() == mtpc_phone_phoneCall); Expects(result.type() == mtpc_phone_phoneCall);
auto &call = result.c_phone_phoneCall(); auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers); Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCallWaiting) { if (call.vphone_call.type() != mtpc_phoneCallWaiting) {
LOG(("Call Error: Expected phoneCallWaiting in response to phone.acceptCall()")); LOG(("Call Error: Expected phoneCallWaiting in response to phone.acceptCall()"));
finish(FinishType::Failed); finish(FinishType::Failed);
@ -487,8 +488,9 @@ void Call::confirmAcceptedCall(const MTPDphoneCallAccepted &call) {
MTP_int(tgvoip::VoIPController::GetConnectionMaxLayer())) MTP_int(tgvoip::VoIPController::GetConnectionMaxLayer()))
)).done([this](const MTPphone_PhoneCall &result) { )).done([this](const MTPphone_PhoneCall &result) {
Expects(result.type() == mtpc_phone_phoneCall); Expects(result.type() == mtpc_phone_phoneCall);
auto &call = result.c_phone_phoneCall(); auto &call = result.c_phone_phoneCall();
App::feedUsers(call.vusers); Auth().data().processUsers(call.vusers);
if (call.vphone_call.type() != mtpc_phoneCall) { if (call.vphone_call.type() != mtpc_phoneCall) {
LOG(("Call Error: Expected phoneCall in response to phone.confirmCall()")); LOG(("Call Error: Expected phoneCall in response to phone.confirmCall()"));
finish(FinishType::Failed); 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_call.h"
#include "calls/calls_panel.h" #include "calls/calls_panel.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "media/media_audio_track.h" #include "media/media_audio_track.h"
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "mainwidget.h" #include "mainwidget.h"
@ -222,7 +223,7 @@ bool Instance::isQuitPrevent() {
void Instance::handleCallUpdate(const MTPPhoneCall &call) { void Instance::handleCallUpdate(const MTPPhoneCall &call) {
if (call.type() == mtpc_phoneCallRequested) { if (call.type() == mtpc_phoneCallRequested) {
auto &phoneCall = call.c_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) { if (!user) {
LOG(("API Error: User not loaded for phoneCallRequested.")); LOG(("API Error: User not loaded for phoneCallRequested."));
} else if (user->isSelf()) { } else if (user->isSelf()) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -144,7 +144,7 @@ public:
return canShareThisContact() && !isContact(); 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 // When actually trying to share contact we perform
// a full check by canShareThisContact() call. // a full check by canShareThisContact() call.
bool canShareThisContactFast() const { bool canShareThisContactFast() const {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -128,7 +128,7 @@ PhotoData *GenerateChatPhoto(
photoSizes.reserve(2); 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("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))); 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_flags(0),
MTP_long(photoId), MTP_long(photoId),
MTP_long(0), MTP_long(0),
@ -253,7 +253,7 @@ TextWithEntities GenerateBannedChangeText(
auto GenerateUserString(MTPint userId) { auto GenerateUserString(MTPint userId) {
// User name in "User name (@username)" format with entities. // 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 name = TextWithEntities { App::peerName(user) };
auto entityData = QString::number(user->id) auto entityData = QString::number(user->id)
+ '.' + '.'
@ -377,7 +377,7 @@ void GenerateItems(
Expects(history->peer->isChannel()); Expects(history->peer->isChannel());
auto id = event.vid.v; 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 channel = history->peer->asChannel();
auto &action = event.vaction; auto &action = event.vaction;
auto date = event.vdate.v; 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 "boxes/confirm_box.h"
#include "base/timer.h" #include "base/timer.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_session.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "styles/style_history.h" #include "styles/style_history.h"
#include "styles/style_window.h" #include "styles/style_window.h"
@ -285,7 +286,7 @@ not_null<ChannelData*> Widget::channel() const {
Dialogs::RowDescriptor Widget::activeChat() const { Dialogs::RowDescriptor Widget::activeChat() const {
return { return {
App::history(channel()), channel()->owner().history(channel()),
FullMsgId(channel()->bareId(), ShowAtUnreadMsgId) FullMsgId(channel()->bareId(), ShowAtUnreadMsgId)
}; };
} }

View file

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

View file

@ -164,7 +164,7 @@ HistoryItem::HistoryItem(
UserId from) UserId from)
: id(id) : id(id)
, _history(history) , _history(history)
, _from(from ? App::user(from) : history->peer) , _from(from ? history->owner().user(from) : history->peer)
, _flags(flags) , _flags(flags)
, _date(date) { , _date(date) {
App::historyRegItem(this); 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_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "auth_session.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
#include "styles/style_history.h" #include "styles/style_history.h"
void HistoryMessageVia::create(UserId userId) { void HistoryMessageVia::create(UserId userId) {
bot = App::user(peerFromUser(userId)); bot = Auth().data().user(userId);
maxWidth = st::msgServiceNameFont->width( maxWidth = st::msgServiceNameFont->width(
lng_inline_bot_via(lt_inline_bot, '@' + bot->username)); lng_inline_bot_via(lt_inline_bot, '@' + bot->username));
link = std::make_shared<LambdaClickHandler>([bot = this->bot] { link = std::make_shared<LambdaClickHandler>([bot = this->bot] {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -99,9 +99,7 @@ private:
class AbstractController : public Window::Navigation { class AbstractController : public Window::Navigation {
public: public:
AbstractController(not_null<Window::Controller*> parent) AbstractController(not_null<Window::Controller*> parent);
: _parent(parent) {
}
virtual Key key() const = 0; virtual Key key() const = 0;
virtual PeerData *migrated() 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 "boxes/peer_list_box.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_chat.h" #include "data/data_chat.h"
#include "data/data_session.h"
#include "auth_session.h"
namespace Info { namespace Info {
@ -90,7 +92,7 @@ std::unique_ptr<ContentMemento> Memento::DefaultContent(
Section section) { Section section) {
Expects(peerId != 0); Expects(peerId != 0);
auto peer = App::peer(peerId); auto peer = Auth().data().peer(peerId);
if (auto to = peer->migrateTo()) { if (auto to = peer->migrateTo()) {
peer = to; peer = to;
} }

View file

@ -199,7 +199,7 @@ Key WrapWidget::key() const {
Dialogs::RowDescriptor WrapWidget::activeChat() const { Dialogs::RowDescriptor WrapWidget::activeChat() const {
if (const auto peer = key().peer()) { 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()) { } else if (const auto feed = key().feed()) {
return Dialogs::RowDescriptor(feed, FullMsgId()); return Dialogs::RowDescriptor(feed, FullMsgId());
} else if (key().settingsSelf()) { } 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_title()) result->_title = qs(r.vtitle);
if (r.has_description()) result->_description = qs(r.vdescription); if (r.has_description()) result->_description = qs(r.vdescription);
if (r.has_photo()) { if (r.has_photo()) {
result->_photo = Auth().data().photo(r.vphoto); result->_photo = Auth().data().processPhoto(r.vphoto);
} }
if (r.has_document()) { if (r.has_document()) {
result->_document = Auth().data().document(r.vdocument); result->_document = Auth().data().processDocument(r.vdocument);
} }
message = &r.vsend_message; message = &r.vsend_message;
} break; } break;

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
@ -1023,7 +1024,7 @@ void Widget::inlineResultsDone(const MTPmessages_BotResults &result) {
auto adding = (it != _inlineCache.cend()); auto adding = (it != _inlineCache.cend());
if (result.type() == mtpc_messages_botResults) { if (result.type() == mtpc_messages_botResults) {
auto &d = result.c_messages_botResults(); auto &d = result.c_messages_botResults();
App::feedUsers(d.vusers); Auth().data().processUsers(d.vusers);
auto &v = d.vresults.v; auto &v = d.vresults.v;
auto queryId = d.vquery_id.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 "media/player/media_player_float.h"
#include "data/data_pts_waiter.h" #include "data/data_pts_waiter.h"
class AuthSession;
struct HistoryMessageMarkupButton; struct HistoryMessageMarkupButton;
class MainWindow; class MainWindow;
class ConfirmBox; class ConfirmBox;
@ -97,6 +98,8 @@ public:
MainWidget(QWidget *parent, not_null<Window::Controller*> controller); MainWidget(QWidget *parent, not_null<Window::Controller*> controller);
AuthSession &session() const;
bool isMainSectionShown() const; bool isMainSectionShown() const;
bool isThirdSectionShown() 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)) { } else if (auto peer = base::get_if<not_null<PeerData*>>(&context)) {
_msgid = FullMsgId(); _msgid = FullMsgId();
_canForwardItem = _canDeleteItem = false; _canForwardItem = _canDeleteItem = false;
_history = App::history(*peer); _history = (*peer)->owner().history(*peer);
_peer = *peer; _peer = *peer;
} else { } else {
_msgid = FullMsgId(); _msgid = FullMsgId();
@ -2658,10 +2658,10 @@ void MediaView::setContext(base::optional_variant<
_migrated = nullptr; _migrated = nullptr;
if (_history) { if (_history) {
if (_history->peer->migrateFrom()) { if (_history->peer->migrateFrom()) {
_migrated = App::history(_history->peer->migrateFrom()->id); _migrated = _history->owner().history(_history->peer->migrateFrom());
} else if (_history->peer->migrateTo()) { } else if (_history->peer->migrateTo()) {
_migrated = _history; _migrated = _history;
_history = App::history(_history->peer->migrateTo()->id); _history = _history->owner().history(_history->peer->migrateTo());
} }
} }
_user = _peer ? _peer->asUser() : nullptr; _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(); const auto &data = result.c_account_authorizationForm();
App::feedUsers(data.vusers); Auth().data().processUsers(data.vusers);
for (const auto &value : data.vvalues.v) { for (const auto &value : data.vvalues.v) {
auto parsed = parseValue(value); auto parsed = parseValue(value);
@ -2525,7 +2525,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
if (!ValidateForm(_form)) { if (!ValidateForm(_form)) {
return false; return false;
} }
_bot = App::userLoaded(_request.botId); _bot = Auth().data().userLoaded(_request.botId);
_form.pendingErrors = data.verrors.v; _form.pendingErrors = data.verrors.v;
return true; 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_button.h"
#include "info/profile/info_profile_cover.h" #include "info/profile/info_profile_cover.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "auth_session.h" #include "auth_session.h"
@ -224,8 +225,7 @@ void SetupHelp(not_null<Ui::VerticalLayout*> container) {
st::settingsSectionButton); st::settingsSectionButton);
button->addClickHandler([=] { button->addClickHandler([=] {
const auto ready = crl::guard(button, [](const MTPUser &data) { const auto ready = crl::guard(button, [](const MTPUser &data) {
const auto users = MTP_vector<MTPUser>(1, data); if (const auto user = Auth().data().processUser(data)) {
if (const auto user = App::feedUsers(users)) {
Ui::showPeerHistory(user, ShowAtUnreadMsgId); Ui::showPeerHistory(user, ShowAtUnreadMsgId);
} }
}); });

View file

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

View file

@ -139,13 +139,16 @@ Uploader::Uploader() {
connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions())); 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) { if (media.type == SendMediaType::Photo) {
Auth().data().photo(media.photo, media.photoThumbs); Auth().data().processPhoto(media.photo, media.photoThumbs);
} else if (media.type == SendMediaType::File || media.type == SendMediaType::Audio) { } else if (media.type == SendMediaType::File
|| media.type == SendMediaType::Audio) {
const auto document = media.photoThumbs.isEmpty() const auto document = media.photoThumbs.isEmpty()
? Auth().data().document(media.document) ? Auth().data().processDocument(media.document)
: Auth().data().document( : Auth().data().processDocument(
media.document, media.document,
base::duplicate(media.photoThumbs.begin().value())); base::duplicate(media.photoThumbs.begin().value()));
if (!media.data.isEmpty()) { if (!media.data.isEmpty()) {
@ -171,15 +174,20 @@ void Uploader::upload(
const FullMsgId &msgId, const FullMsgId &msgId,
const std::shared_ptr<FileLoadResult> &file) { const std::shared_ptr<FileLoadResult> &file) {
if (file->type == SendMediaType::Photo) { if (file->type == SendMediaType::Photo) {
auto photo = Auth().data().photo(file->photo, file->photoThumbs); const auto photo = Auth().data().processPhoto(
photo->uploadingData = std::make_unique<Data::UploadState>(file->partssize); file->photo,
} else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) { file->photoThumbs);
auto document = file->thumb.isNull() photo->uploadingData = std::make_unique<Data::UploadState>(
? Auth().data().document(file->document) file->partssize);
: Auth().data().document( } 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, file->document,
std::move(file->thumb)); std::move(file->thumb));
document->uploadingData = std::make_unique<Data::UploadState>(document->size); document->uploadingData = std::make_unique<Data::UploadState>(
document->size);
document->setGoodThumbnail( document->setGoodThumbnail(
std::move(file->goodThumbnail), std::move(file->goodThumbnail),
std::move(file->goodThumbnailBytes)); 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_channel.h"
#include "data/data_chat.h" #include "data/data_chat.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "ui/image/image.h" #include "ui/image/image.h"
namespace Serialize { namespace Serialize {
@ -154,10 +155,10 @@ PeerData *readPeer(int streamAppVersion, QDataStream &stream) {
streamAppVersion, streamAppVersion,
stream); stream);
PeerData *result = App::peerLoaded(peerId); PeerData *result = Auth().data().peerLoaded(peerId);
bool wasLoaded = (result != nullptr); bool wasLoaded = (result != nullptr);
if (!wasLoaded) { if (!wasLoaded) {
result = App::peer(peerId); result = Auth().data().peer(peerId);
result->loadedStatus = PeerData::FullLoaded; result->loadedStatus = PeerData::FullLoaded;
} }
if (const auto user = result->asUser()) { if (const auto user = result->asUser()) {

View file

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

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h" #include "dialogs/dialogs_key.h"
#include "data/data_drafts.h" #include "data/data_drafts.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
#include "history/history.h" #include "history/history.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
@ -579,7 +580,7 @@ QString InterpretSendPath(const QString &path) {
return "App Error: Invalid command: " + line; return "App Error: Invalid command: " + line;
} }
} }
const auto history = App::historyLoaded(toId); const auto history = Auth().data().historyLoaded(toId);
if (!history) { if (!history) {
return "App Error: Could not find channel with id: " + QString::number(peerToChannel(toId)); 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 "base/qthelp_url.h"
#include "ui/emoji_config.h" #include "ui/emoji_config.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h"
namespace TextUtilities { namespace TextUtilities {
namespace { namespace {
@ -1472,7 +1473,7 @@ EntitiesInText EntitiesFromMTP(const QVector<MTPMessageEntity> &entities) {
case mtpc_messageEntityMentionName: { case mtpc_messageEntityMentionName: {
auto &d = entity.c_messageEntityMentionName(); auto &d = entity.c_messageEntityMentionName();
auto data = [&d] { auto data = [&d] {
if (auto user = App::userLoaded(peerFromUser(d.vuser_id))) { if (auto user = Auth().data().userLoaded(d.vuser_id.v)) {
return MentionNameDataFromFields({ return MentionNameDataFromFields({
d.vuser_id.v, d.vuser_id.v,
user->accessHash() }); user->accessHash() });

View file

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

View file

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

View file

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

View file

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

View file

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