Move App::histories to Data::Session.

This commit is contained in:
John Preston 2019-01-03 16:36:01 +04:00
parent 0d6a36e187
commit 1f8626b383
49 changed files with 1479 additions and 1366 deletions

View File

@ -629,7 +629,7 @@ void ApiWrap::requestContacts() {
const auto userId = contact.c_contact().vuser_id.v; const auto userId = contact.c_contact().vuser_id.v;
if (userId == _session->userId()) { if (userId == _session->userId()) {
Auth().user()->setContactStatus( _session->user()->setContactStatus(
UserData::ContactStatus::Contact); UserData::ContactStatus::Contact);
} }
} }
@ -1026,6 +1026,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
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 = App::historyLoaded(channel->id)) {
history->clearUpTill(f.vavailable_min_id.v);
history->applyDialogFields( history->applyDialogFields(
f.vunread_count.v, f.vunread_count.v,
f.vread_inbox_max_id.v, f.vread_inbox_max_id.v,
@ -1546,7 +1547,7 @@ void ApiWrap::requestSelfParticipant(ChannelData *channel) {
channel->inviter = _session->userId(); channel->inviter = _session->userId();
channel->inviteDate = channel->date; channel->inviteDate = channel->date;
if (channel->mgInfo) { if (channel->mgInfo) {
channel->mgInfo->creator = Auth().user(); channel->mgInfo->creator = _session->user();
} }
} break; } break;
case mtpc_channelParticipantAdmin: { case mtpc_channelParticipantAdmin: {
@ -2144,7 +2145,7 @@ void ApiWrap::updatePrivacyLastSeens(const QVector<MTPPrivacyRule> &rules) {
} }
auto now = unixtime(); auto now = unixtime();
App::enumerateUsers([&](UserData *user) { _session->data().enumerateUsers([&](UserData *user) {
if (user->isSelf() || user->loadedStatus != PeerData::FullLoaded) { if (user->isSelf() || user->loadedStatus != PeerData::FullLoaded) {
return; return;
} }
@ -2276,7 +2277,7 @@ void ApiWrap::saveDraftsToCloud() {
if (cloudDraft && cloudDraft->saveRequestId) { if (cloudDraft && cloudDraft->saveRequestId) {
request(base::take(cloudDraft->saveRequestId)).cancel(); request(base::take(cloudDraft->saveRequestId)).cancel();
} }
if (!Auth().supportMode()) { if (!_session->supportMode()) {
cloudDraft = history->createCloudDraft(localDraft); cloudDraft = history->createCloudDraft(localDraft);
} else if (!cloudDraft) { } else if (!cloudDraft) {
cloudDraft = history->createCloudDraft(nullptr); cloudDraft = history->createCloudDraft(nullptr);
@ -2793,7 +2794,7 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
} }
for (const auto [position, index] : indices) { for (const auto [position, index] : indices) {
const auto item = App::histories().addNewMessage( const auto item = _session->data().addNewMessage(
v->at(index), v->at(index),
NewMessageExisting); NewMessageExisting);
if (item) { if (item) {
@ -3230,7 +3231,7 @@ void ApiWrap::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
const auto peerUserId = d.is_out() const auto peerUserId = d.is_out()
? d.vuser_id ? d.vuser_id
: MTP_int(_session->userId()); : MTP_int(_session->userId());
App::histories().addNewMessage( _session->data().addNewMessage(
MTP_message( MTP_message(
MTP_flags(flags), MTP_flags(flags),
d.vid, d.vid,
@ -3254,7 +3255,7 @@ void ApiWrap::applyUpdatesNoPtsCheck(const MTPUpdates &updates) {
case mtpc_updateShortChatMessage: { case mtpc_updateShortChatMessage: {
auto &d = updates.c_updateShortChatMessage(); auto &d = updates.c_updateShortChatMessage();
auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id; auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id;
App::histories().addNewMessage( _session->data().addNewMessage(
MTP_message( MTP_message(
MTP_flags(flags), MTP_flags(flags),
d.vid, d.vid,
@ -3296,7 +3297,7 @@ void ApiWrap::applyUpdateNoPtsCheck(const MTPUpdate &update) {
} }
} }
if (needToAdd) { if (needToAdd) {
App::histories().addNewMessage(d.vmessage, NewMessageUnread); _session->data().addNewMessage(d.vmessage, NewMessageUnread);
} }
} break; } break;
@ -3354,7 +3355,7 @@ void ApiWrap::applyUpdateNoPtsCheck(const MTPUpdate &update) {
} }
} }
if (needToAdd) { if (needToAdd) {
App::histories().addNewMessage(d.vmessage, NewMessageUnread); _session->data().addNewMessage(d.vmessage, NewMessageUnread);
} }
} break; } break;
@ -3521,7 +3522,7 @@ void ApiWrap::requestMessageAfterDate(
// App::feedUsers(data.vusers); // App::feedUsers(data.vusers);
// App::feedChats(data.vchats); // App::feedChats(data.vchats);
// for (const auto &msg : messages) { // for (const auto &msg : messages) {
// if (const auto item = App::histories().addNewMessage(msg, type)) { // if (const auto item = _session->data().addNewMessage(msg, type)) {
// if (item->date() >= offsetDate || true) { // if (item->date() >= offsetDate || true) {
// callback(item->position()); // callback(item->position());
// return; // return;
@ -4060,7 +4061,7 @@ void ApiWrap::userPhotosDone(
// if (!messages.empty()) { // if (!messages.empty()) {
// ids.reserve(messages.size()); // ids.reserve(messages.size());
// for (const auto &msg : messages) { // for (const auto &msg : messages) {
// if (const auto item = App::histories().addNewMessage(msg, type)) { // if (const auto item = _session->data().addNewMessage(msg, type)) {
// const auto position = item->position(); // const auto position = item->position();
// if (tooLargePosition(position)) { // if (tooLargePosition(position)) {
// accumulateTill(noSkipRange.till, position); // accumulateTill(noSkipRange.till, position);
@ -5126,7 +5127,7 @@ void ApiWrap::photoUploadReady(
} }
void ApiWrap::clearPeerPhoto(not_null<PhotoData*> photo) { void ApiWrap::clearPeerPhoto(not_null<PhotoData*> photo) {
const auto self = Auth().user(); const auto self = _session->user();
if (self->userpicPhotoId() == photo->id) { if (self->userpicPhotoId() == photo->id) {
request(MTPphotos_UpdateProfilePhoto( request(MTPphotos_UpdateProfilePhoto(
MTP_inputPhotoEmpty() MTP_inputPhotoEmpty()
@ -5226,7 +5227,7 @@ void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) {
_saveBioRequestId = 0; _saveBioRequestId = 0;
App::feedUsers(MTP_vector<MTPUser>(1, result)); App::feedUsers(MTP_vector<MTPUser>(1, result));
Auth().user()->setAbout(_saveBioText); _session->user()->setAbout(_saveBioText);
if (_saveBioDone) { if (_saveBioDone) {
_saveBioDone(); _saveBioDone();
} }

View File

@ -50,14 +50,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
App::LaunchState _launchState = App::Launched; App::LaunchState _launchState = App::Launched;
std::unordered_map<PeerId, std::unique_ptr<PeerData>> peersData;
using DependentItemsSet = OrderedSet<HistoryItem*>; using DependentItemsSet = OrderedSet<HistoryItem*>;
using DependentItems = QMap<HistoryItem*, DependentItemsSet>; using DependentItems = QMap<HistoryItem*, DependentItemsSet>;
DependentItems dependentItems; DependentItems dependentItems;
Histories histories;
using MsgsData = QHash<MsgId, HistoryItem*>; using MsgsData = QHash<MsgId, HistoryItem*>;
MsgsData msgsData; MsgsData msgsData;
using ChannelMsgsData = QMap<ChannelId, MsgsData>; using ChannelMsgsData = QMap<ChannelId, MsgsData>;
@ -131,468 +127,20 @@ namespace App {
return nullptr; return nullptr;
} }
namespace {
// we should get a full restriction in "{fulltype}: {reason}" format and we
// need to find a "-all" tag in {fulltype}, otherwise ignore this restriction
QString extractRestrictionReason(const QString &fullRestriction) {
int fullTypeEnd = fullRestriction.indexOf(':');
if (fullTypeEnd <= 0) {
return QString();
}
// {fulltype} is in "{type}-{tag}-{tag}-{tag}" format
// if we find "all" tag we return the restriction string
auto typeTags = fullRestriction.mid(0, fullTypeEnd).split('-').mid(1);
#ifndef OS_MAC_STORE
auto restrictionApplies = typeTags.contains(qsl("all"));
#else // OS_MAC_STORE
auto restrictionApplies = typeTags.contains(qsl("all")) || typeTags.contains(qsl("ios"));
#endif // OS_MAC_STORE
if (restrictionApplies) {
return fullRestriction.midRef(fullTypeEnd + 1).trimmed().toString();
}
return QString();
}
}
UserData *feedUser(const MTPUser &user) { UserData *feedUser(const MTPUser &user) {
UserData *data = nullptr; return Auth().data().user(user);
bool minimal = false;
const MTPUserStatus *status = 0, emptyStatus = MTP_userStatusEmpty();
Notify::PeerUpdate update;
using UpdateFlag = Notify::PeerUpdate::Flag;
switch (user.type()) {
case mtpc_userEmpty: {
auto &d = user.c_userEmpty();
auto peer = peerFromUser(d.vid.v);
data = App::user(peer);
auto canShareThisContact = data->canShareThisContactFast();
data->input = MTP_inputPeerUser(d.vid, MTP_long(0));
data->inputUser = MTP_inputUser(d.vid, MTP_long(0));
data->setName(lang(lng_deleted), QString(), QString(), QString());
data->setPhoto(MTP_userProfilePhotoEmpty());
//data->setFlags(MTPDuser_ClientFlag::f_inaccessible | 0);
data->setFlags(MTPDuser::Flag::f_deleted);
if (!data->phone().isEmpty()) {
data->setPhone(QString());
update.flags |= UpdateFlag::UserPhoneChanged;
}
data->setBotInfoVersion(-1);
status = &emptyStatus;
data->setContactStatus(UserData::ContactStatus::PhoneUnknown);
if (canShareThisContact != data->canShareThisContactFast()) {
update.flags |= UpdateFlag::UserCanShareContact;
}
} break;
case mtpc_user: {
auto &d = user.c_user();
minimal = d.is_min();
auto peer = peerFromUser(d.vid.v);
data = App::user(peer);
auto canShareThisContact = data->canShareThisContactFast();
if (minimal) {
auto mask = 0
//| MTPDuser_ClientFlag::f_inaccessible
| MTPDuser::Flag::f_deleted;
data->setFlags((data->flags() & ~mask) | (d.vflags.v & mask));
} else {
data->setFlags(d.vflags.v);
if (d.is_self()) {
data->input = MTP_inputPeerSelf();
data->inputUser = MTP_inputUserSelf();
} else if (!d.has_access_hash()) {
data->input = MTP_inputPeerUser(d.vid, MTP_long(data->accessHash()));
data->inputUser = MTP_inputUser(d.vid, MTP_long(data->accessHash()));
} else {
data->input = MTP_inputPeerUser(d.vid, d.vaccess_hash);
data->inputUser = MTP_inputUser(d.vid, d.vaccess_hash);
}
if (d.is_restricted()) {
data->setRestrictionReason(extractRestrictionReason(qs(d.vrestriction_reason)));
} else {
data->setRestrictionReason(QString());
}
}
if (d.is_deleted()) {
if (!data->phone().isEmpty()) {
data->setPhone(QString());
update.flags |= UpdateFlag::UserPhoneChanged;
}
data->setName(lang(lng_deleted), QString(), QString(), QString());
data->setPhoto(MTP_userProfilePhotoEmpty());
status = &emptyStatus;
} else {
// apply first_name and last_name from minimal user only if we don't have
// local values for first name and last name already, otherwise skip
bool noLocalName = data->firstName.isEmpty() && data->lastName.isEmpty();
QString fname = (!minimal || noLocalName) ? (d.has_first_name() ? TextUtilities::SingleLine(qs(d.vfirst_name)) : QString()) : data->firstName;
QString lname = (!minimal || noLocalName) ? (d.has_last_name() ? TextUtilities::SingleLine(qs(d.vlast_name)) : QString()) : data->lastName;
QString phone = minimal ? data->phone() : (d.has_phone() ? qs(d.vphone) : QString());
QString uname = minimal ? data->username : (d.has_username() ? TextUtilities::SingleLine(qs(d.vusername)) : QString());
bool phoneChanged = (data->phone() != phone);
if (phoneChanged) {
data->setPhone(phone);
update.flags |= UpdateFlag::UserPhoneChanged;
}
bool nameChanged = (data->firstName != fname) || (data->lastName != lname);
bool showPhone = !isServiceUser(data->id)
&& !d.is_self()
&& !d.is_contact()
&& !d.is_mutual_contact();
bool showPhoneChanged = !isServiceUser(data->id)
&& !d.is_self()
&& ((showPhone
&& data->contactStatus() == UserData::ContactStatus::Contact)
|| (!showPhone
&& data->contactStatus() == UserData::ContactStatus::CanAdd));
if (minimal) {
showPhoneChanged = false;
showPhone = !isServiceUser(data->id)
&& (data->id != Auth().userPeerId())
&& (data->contactStatus() == UserData::ContactStatus::CanAdd);
}
// see also Local::readPeer
const auto pname = (showPhoneChanged || phoneChanged || nameChanged)
? ((showPhone && !phone.isEmpty())
? formatPhone(phone)
: QString())
: data->nameOrPhone;
if (!minimal && d.is_self() && uname != data->username) {
CrashReports::SetAnnotation("Username", uname);
}
data->setName(fname, lname, pname, uname);
if (d.has_photo()) {
data->setPhoto(d.vphoto);
} else {
data->setPhoto(MTP_userProfilePhotoEmpty());
}
if (d.has_access_hash()) {
data->setAccessHash(d.vaccess_hash.v);
}
status = d.has_status() ? &d.vstatus : &emptyStatus;
}
if (!minimal) {
if (d.has_bot_info_version()) {
data->setBotInfoVersion(d.vbot_info_version.v);
data->botInfo->readsAllHistory = d.is_bot_chat_history();
if (data->botInfo->cantJoinGroups != d.is_bot_nochats()) {
data->botInfo->cantJoinGroups = d.is_bot_nochats();
update.flags |= UpdateFlag::BotCanAddToGroups;
}
data->botInfo->inlinePlaceholder = d.has_bot_inline_placeholder() ? '_' + qs(d.vbot_inline_placeholder) : QString();
} else {
data->setBotInfoVersion(-1);
}
data->setContactStatus((d.is_contact() || d.is_mutual_contact())
? UserData::ContactStatus::Contact
: data->phone().isEmpty()
? UserData::ContactStatus::PhoneUnknown
: UserData::ContactStatus::CanAdd);
}
if (canShareThisContact != data->canShareThisContactFast()) {
update.flags |= UpdateFlag::UserCanShareContact;
}
} break;
}
if (!data) {
return nullptr;
}
if (minimal) {
if (data->loadedStatus == PeerData::NotLoaded) {
data->loadedStatus = PeerData::MinimalLoaded;
}
} else if (data->loadedStatus != PeerData::FullLoaded
&& (!data->isSelf() || !data->phone().isEmpty())) {
data->loadedStatus = PeerData::FullLoaded;
}
if (status && !minimal) {
const auto oldOnlineTill = data->onlineTill;
const auto newOnlineTill = ApiWrap::OnlineTillFromStatus(
*status,
oldOnlineTill);
if (oldOnlineTill != newOnlineTill) {
data->onlineTill = newOnlineTill;
update.flags |= UpdateFlag::UserOnlineChanged;
}
}
if (data->contactStatus() == UserData::ContactStatus::PhoneUnknown
&& !data->phone().isEmpty()
&& !data->isSelf()) {
data->setContactStatus(UserData::ContactStatus::CanAdd);
}
if (App::main()) {
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
}
}
return data;
} }
UserData *feedUsers(const MTPVector<MTPUser> &users) { UserData *feedUsers(const MTPVector<MTPUser> &users) {
UserData *result = nullptr; return Auth().data().processUsers(users);
for_const (auto &user, users.v) {
if (auto feededUser = feedUser(user)) {
result = feededUser;
}
}
return result;
} }
PeerData *feedChat(const MTPChat &chat) { PeerData *feedChat(const MTPChat &chat) {
PeerData *data = nullptr; return Auth().data().chat(chat);
bool minimal = false;
Notify::PeerUpdate update;
using UpdateFlag = Notify::PeerUpdate::Flag;
switch (chat.type()) {
case mtpc_chat: {
auto &d(chat.c_chat());
data = App::chat(peerFromChat(d.vid.v));
auto cdata = data->asChat();
auto canEdit = cdata->canEdit();
if (cdata->version < d.vversion.v) {
cdata->version = d.vversion.v;
cdata->invalidateParticipants();
}
data->input = MTP_inputPeerChat(d.vid);
cdata->setName(qs(d.vtitle));
cdata->setPhoto(d.vphoto);
cdata->date = d.vdate.v;
if (d.has_migrated_to() && d.vmigrated_to.type() == mtpc_inputChannel) {
auto &c = d.vmigrated_to.c_inputChannel();
auto channel = App::channel(peerFromChannel(c.vchannel_id));
channel->addFlags(MTPDchannel::Flag::f_megagroup);
if (!channel->access) {
channel->input = MTP_inputPeerChannel(c.vchannel_id, c.vaccess_hash);
channel->inputChannel = d.vmigrated_to;
channel->access = d.vmigrated_to.c_inputChannel().vaccess_hash.v;
}
bool updatedTo = (cdata->migrateToPtr != channel), updatedFrom = (channel->mgInfo->migrateFromPtr != cdata);
if (updatedTo) {
cdata->migrateToPtr = channel;
}
if (updatedFrom) {
channel->mgInfo->migrateFromPtr = cdata;
if (auto h = App::historyLoaded(cdata->id)) {
if (auto hto = App::historyLoaded(channel->id)) {
if (!h->isEmpty()) {
h->unloadBlocks();
}
if (hto->inChatList(Dialogs::Mode::All) && h->inChatList(Dialogs::Mode::All)) {
App::main()->removeDialog(h);
}
}
}
Notify::migrateUpdated(channel);
update.flags |= UpdateFlag::MigrationChanged;
}
if (updatedTo) {
Notify::migrateUpdated(cdata);
update.flags |= UpdateFlag::MigrationChanged;
}
}
if (!(cdata->flags() & MTPDchat::Flag::f_admins_enabled) && (d.vflags.v & MTPDchat::Flag::f_admins_enabled)) {
cdata->invalidateParticipants();
}
cdata->setFlags(d.vflags.v);
cdata->count = d.vparticipants_count.v;
if (canEdit != cdata->canEdit()) {
update.flags |= UpdateFlag::ChatCanEdit;
}
} break;
case mtpc_chatForbidden: {
auto &d(chat.c_chatForbidden());
data = App::chat(peerFromChat(d.vid.v));
auto cdata = data->asChat();
auto canEdit = cdata->canEdit();
data->input = MTP_inputPeerChat(d.vid);
cdata->setName(qs(d.vtitle));
cdata->setPhoto(MTP_chatPhotoEmpty());
cdata->date = 0;
cdata->count = -1;
cdata->invalidateParticipants();
cdata->setFlags(MTPDchat_ClientFlag::f_forbidden | 0);
if (canEdit != cdata->canEdit()) {
update.flags |= UpdateFlag::ChatCanEdit;
}
} break;
case mtpc_channel: {
const auto &d = chat.c_channel();
const auto peerId = peerFromChannel(d.vid.v);
minimal = d.is_min();
if (minimal) {
data = App::channelLoaded(peerId);
if (!data) {
// Can't apply minimal to a not loaded channel.
// Need to make getDifference.
return nullptr;
}
} else {
data = App::channel(peerId);
const auto accessHash = d.has_access_hash()
? d.vaccess_hash
: MTP_long(0);
data->input = MTP_inputPeerChannel(d.vid, accessHash);
}
const auto cdata = data->asChannel();
const auto wasInChannel = cdata->amIn();
const auto canViewAdmins = cdata->canViewAdmins();
const auto canViewMembers = cdata->canViewMembers();
const auto canAddMembers = cdata->canAddMembers();
if (d.has_participants_count()) {
cdata->setMembersCount(d.vparticipants_count.v);
}
if (minimal) {
auto mask = 0
| MTPDchannel::Flag::f_broadcast
| MTPDchannel::Flag::f_verified
| MTPDchannel::Flag::f_megagroup
| MTPDchannel::Flag::f_democracy
| MTPDchannel_ClientFlag::f_forbidden;
cdata->setFlags((cdata->flags() & ~mask) | (d.vflags.v & mask));
} else {
if (d.has_admin_rights()) {
cdata->setAdminRights(d.vadmin_rights);
} else if (cdata->hasAdminRights()) {
cdata->setAdminRights(MTP_channelAdminRights(MTP_flags(0)));
}
if (d.has_banned_rights()) {
cdata->setRestrictedRights(d.vbanned_rights);
} else if (cdata->hasRestrictions()) {
cdata->setRestrictedRights(MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));
}
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
cdata->access = d.vaccess_hash.v;
cdata->date = d.vdate.v;
if (cdata->version < d.vversion.v) {
cdata->version = d.vversion.v;
}
if (d.is_restricted()) {
cdata->setRestrictionReason(extractRestrictionReason(qs(d.vrestriction_reason)));
} else {
cdata->setRestrictionReason(QString());
}
cdata->setFlags(d.vflags.v);
//if (d.has_feed_id()) { // #feed
// cdata->setFeed(Auth().data().feed(d.vfeed_id.v));
//} else {
// cdata->clearFeed();
//}
}
QString uname = d.has_username() ? TextUtilities::SingleLine(qs(d.vusername)) : QString();
cdata->setName(qs(d.vtitle), uname);
cdata->setPhoto(d.vphoto);
if (wasInChannel != cdata->amIn()) {
update.flags |= UpdateFlag::ChannelAmIn;
}
if (canViewAdmins != cdata->canViewAdmins()
|| canViewMembers != cdata->canViewMembers()
|| canAddMembers != cdata->canAddMembers()) {
update.flags |= UpdateFlag::ChannelRightsChanged;
}
} break;
case mtpc_channelForbidden: {
auto &d(chat.c_channelForbidden());
auto peerId = peerFromChannel(d.vid.v);
data = App::channel(peerId);
data->input = MTP_inputPeerChannel(d.vid, d.vaccess_hash);
auto cdata = data->asChannel();
auto wasInChannel = cdata->amIn();
auto canViewAdmins = cdata->canViewAdmins();
auto canViewMembers = cdata->canViewMembers();
auto canAddMembers = cdata->canAddMembers();
cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash);
auto mask = mtpCastFlags(MTPDchannelForbidden::Flag::f_broadcast | MTPDchannelForbidden::Flag::f_megagroup);
cdata->setFlags((cdata->flags() & ~mask) | (mtpCastFlags(d.vflags) & mask) | MTPDchannel_ClientFlag::f_forbidden);
if (cdata->hasAdminRights()) {
cdata->setAdminRights(MTP_channelAdminRights(MTP_flags(0)));
}
if (cdata->hasRestrictions()) {
cdata->setRestrictedRights(MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));
}
cdata->setName(qs(d.vtitle), QString());
cdata->access = d.vaccess_hash.v;
cdata->setPhoto(MTP_chatPhotoEmpty());
cdata->date = 0;
cdata->setMembersCount(0);
if (wasInChannel != cdata->amIn()) {
update.flags |= UpdateFlag::ChannelAmIn;
}
if (canViewAdmins != cdata->canViewAdmins()
|| canViewMembers != cdata->canViewMembers()
|| canAddMembers != cdata->canAddMembers()) {
update.flags |= UpdateFlag::ChannelRightsChanged;
}
} break;
}
if (!data) {
return nullptr;
}
if (minimal) {
if (data->loadedStatus == PeerData::NotLoaded) {
data->loadedStatus = PeerData::MinimalLoaded;
}
} else if (data->loadedStatus != PeerData::FullLoaded) {
data->loadedStatus = PeerData::FullLoaded;
}
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
}
return data;
} }
PeerData *feedChats(const MTPVector<MTPChat> &chats) { PeerData *feedChats(const MTPVector<MTPChat> &chats) {
PeerData *result = nullptr; return Auth().data().processChats(chats);
for_const (auto &chat, chats.v) {
if (auto feededChat = feedChat(chat)) {
result = feededChat;
}
}
return result;
} }
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos) { void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos) {
@ -934,7 +482,7 @@ namespace App {
indices.emplace((uint64(uint32(msgId)) << 32) | uint64(i), i); indices.emplace((uint64(uint32(msgId)) << 32) | uint64(i), i);
} }
for (const auto [position, index] : indices) { for (const auto [position, index] : indices) {
histories().addNewMessage(msgs[index], type); Auth().data().addNewMessage(msgs[index], type);
} }
} }
@ -1088,95 +636,41 @@ namespace App {
} }
} }
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) { not_null<PeerData*> peer(PeerId id) {
if (!id) { return Auth().data().peer(id);
return nullptr;
}
auto i = peersData.find(id);
if (i == peersData.cend()) {
auto newData = [&]() -> std::unique_ptr<PeerData> {
if (peerIsUser(id)) {
return std::make_unique<UserData>(id);
} else if (peerIsChat(id)) {
return std::make_unique<ChatData>(id);
} else if (peerIsChannel(id)) {
return std::make_unique<ChannelData>(id);
}
Unexpected("Peer id type.");
}();
newData->input = MTPinputPeer(MTP_inputPeerEmpty());
i = peersData.emplace(id, std::move(newData)).first;
}
switch (restriction) {
case PeerData::MinimalLoaded: {
if (i->second->loadedStatus == PeerData::NotLoaded) {
return nullptr;
}
} break;
case PeerData::FullLoaded: {
if (i->second->loadedStatus != PeerData::FullLoaded) {
return nullptr;
}
} break;
}
return i->second.get();
} }
not_null<UserData*> user(UserId id) {
void enumerateUsers(Fn<void(not_null<UserData*>)> action) { return Auth().data().user(id);
for (const auto &[peerId, peer] : peersData) {
if (const auto user = peer->asUser()) {
action(user);
}
}
} }
not_null<ChatData*> chat(ChatId id) {
void enumerateGroups(Fn<void(not_null<PeerData*>)> action) { return Auth().data().chat(id);
for (const auto &[peerId, peer] : peersData) {
if (peer->isChat() || peer->isMegagroup()) {
action(peer.get());
}
}
} }
not_null<ChannelData*> channel(ChannelId id) {
void enumerateChannels(Fn<void(not_null<ChannelData*>)> action) { return Auth().data().channel(id);
for (const auto &[peerId, peer] : peersData) {
if (const auto channel = peer->asChannel()) {
if (!channel->isMegagroup()) {
action(channel);
}
}
}
} }
PeerData *peerLoaded(PeerId id) {
PeerData *peerByName(const QString &username) { return Auth().data().peerLoaded(id);
const auto uname = username.trimmed(); }
for (const auto &[peerId, peer] : peersData) { UserData *userLoaded(UserId id) {
if (!peer->userName().compare(uname, Qt::CaseInsensitive)) { return Auth().data().userLoaded(id);
return peer.get(); }
} ChatData *chatLoaded(ChatId id) {
} return Auth().data().chatLoaded(id);
return nullptr; }
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);
} }
Histories &histories() { not_null<History*> history(PeerId peer) {
return ::histories; return Auth().data().history(peer);
} }
not_null<History*> history(const PeerId &peer) { History *historyLoaded(PeerId peer) {
return ::histories.findOrInsert(peer); return Auth().data().historyLoaded(peer);
}
History *historyLoaded(const PeerId &peer) {
if (!peer) {
return nullptr;
}
return ::histories.find(peer);
} }
HistoryItem *histItemById(ChannelId channelId, MsgId itemId) { HistoryItem *histItemById(ChannelId channelId, MsgId itemId) {
@ -1224,7 +718,7 @@ namespace App {
dependent->dependencyItemRemoved(item); dependent->dependencyItemRemoved(item);
} }
} }
Auth().notifications().clearFromItem(item); item->history()->session().notifications().clearFromItem(item);
} }
void historyUpdateDependent(not_null<HistoryItem*> item) { void historyUpdateDependent(not_null<HistoryItem*> item) {
@ -1261,12 +755,6 @@ namespace App {
cSetSavedPeers(SavedPeers()); cSetSavedPeers(SavedPeers());
cSetSavedPeersByTime(SavedPeersByTime()); cSetSavedPeersByTime(SavedPeersByTime());
cSetRecentInlineBots(RecentInlineBots()); cSetRecentInlineBots(RecentInlineBots());
peersData.clear();
if (AuthSession::Exists()) {
Auth().api().clearWebPageRequests();
}
cSetRecentStickers(RecentStickerPack()); cSetRecentStickers(RecentStickerPack());
cSetReportSpamStatuses(ReportSpamStatuses()); cSetReportSpamStatuses(ReportSpamStatuses());
} }
@ -1444,21 +932,6 @@ namespace App {
}); });
} }
void clearHistories() {
ClickHandler::clearActive();
ClickHandler::unpressed();
if (AuthSession::Exists()) {
// Clear notifications to prevent any showNotification() calls while destroying items.
Auth().notifications().clearAllFast();
}
histories().clear();
Images::ClearRemote();
cSetServerBackgrounds(WallPapers());
}
void deinitMedia() { void deinitMedia() {
clearCorners(); clearCorners();
@ -1772,6 +1245,4 @@ namespace App {
roundRect(p, x, y, w, h, bg, i.value(), nullptr, parts); roundRect(p, x, y, w, h, bg, i.value(), nullptr, parts);
} }
WallPapers gServerBackgrounds;
} }

View File

@ -17,7 +17,6 @@ class MainWindow;
class MainWidget; class MainWidget;
class HistoryItem; class HistoryItem;
class History; class History;
class Histories;
namespace HistoryView { namespace HistoryView {
class Element; class Element;
} // namespace HistoryView } // namespace HistoryView
@ -90,68 +89,31 @@ namespace App {
ImagePtr image(const MTPPhotoSize &size); ImagePtr image(const MTPPhotoSize &size);
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded); [[nodiscard]] not_null<PeerData*> peer(PeerId id);
inline UserData *user(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) { [[nodiscard]] not_null<UserData*> user(UserId userId);
return asUser(peer(id, restriction)); [[nodiscard]] not_null<ChatData*> chat(ChatId chatId);
} [[nodiscard]] not_null<ChannelData*> channel(ChannelId channelId);
inline ChatData *chat(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) { [[nodiscard]] PeerData *peerLoaded(PeerId id);
return asChat(peer(id, restriction)); [[nodiscard]] UserData *userLoaded(UserId userId);
} [[nodiscard]] ChatData *chatLoaded(ChatId chatId);
inline ChannelData *channel(const PeerId &id, PeerData::LoadedStatus restriction = PeerData::NotLoaded) { [[nodiscard]] ChannelData *channelLoaded(ChannelId channelId);
return asChannel(peer(id, restriction));
}
inline UserData *user(UserId userId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
return asUser(peer(peerFromUser(userId), restriction));
}
inline ChatData *chat(ChatId chatId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
return asChat(peer(peerFromChat(chatId), restriction));
}
inline ChannelData *channel(ChannelId channelId, PeerData::LoadedStatus restriction = PeerData::NotLoaded) {
return asChannel(peer(peerFromChannel(channelId), restriction));
}
inline PeerData *peerLoaded(const PeerId &id) {
return peer(id, PeerData::FullLoaded);
}
inline UserData *userLoaded(const PeerId &id) {
return user(id, PeerData::FullLoaded);
}
inline ChatData *chatLoaded(const PeerId &id) {
return chat(id, PeerData::FullLoaded);
}
inline ChannelData *channelLoaded(const PeerId &id) {
return channel(id, PeerData::FullLoaded);
}
inline UserData *userLoaded(UserId userId) {
return user(userId, PeerData::FullLoaded);
}
inline ChatData *chatLoaded(ChatId chatId) {
return chat(chatId, PeerData::FullLoaded);
}
inline ChannelData *channelLoaded(ChannelId channelId) {
return channel(channelId, PeerData::FullLoaded);
}
void enumerateUsers(Fn<void(not_null<UserData*>)> action);
void enumerateGroups(Fn<void(not_null<PeerData*>)> action);
void enumerateChannels(Fn<void(not_null<ChannelData*>)> action);
PeerData *peerByName(const QString &username); [[nodiscard]] QString peerName(const PeerData *peer, bool forDialogs = false);
QString peerName(const PeerData *peer, bool forDialogs = false);
Histories &histories(); [[nodiscard]] not_null<History*> history(PeerId peer);
not_null<History*> history(const PeerId &peer); [[nodiscard]] History *historyLoaded(PeerId peer);
History *historyLoaded(const PeerId &peer); [[nodiscard]] HistoryItem *histItemById(ChannelId channelId, MsgId itemId);
HistoryItem *histItemById(ChannelId channelId, MsgId itemId); [[nodiscard]] inline not_null<History*> history(const PeerData *peer) {
inline not_null<History*> history(const PeerData *peer) {
Assert(peer != nullptr); Assert(peer != nullptr);
return history(peer->id); return history(peer->id);
} }
inline History *historyLoaded(const PeerData *peer) { [[nodiscard]] inline History *historyLoaded(const PeerData *peer) {
return peer ? historyLoaded(peer->id) : nullptr; return peer ? historyLoaded(peer->id) : nullptr;
} }
inline HistoryItem *histItemById(const ChannelData *channel, MsgId itemId) { [[nodiscard]] inline HistoryItem *histItemById(const ChannelData *channel, MsgId itemId) {
return histItemById(channel ? peerToChannel(channel->id) : 0, itemId); return histItemById(channel ? peerToChannel(channel->id) : 0, itemId);
} }
inline HistoryItem *histItemById(const FullMsgId &msgId) { [[nodiscard]] inline HistoryItem *histItemById(const FullMsgId &msgId) {
return histItemById(msgId.channel, msgId.msg); return histItemById(msgId.channel, msgId.msg);
} }
void historyRegItem(not_null<HistoryItem*> item); void historyRegItem(not_null<HistoryItem*> item);
@ -183,8 +145,6 @@ namespace App {
const style::font &monofont(); const style::font &monofont();
void clearHistories();
void initMedia(); void initMedia();
void deinitMedia(); void deinitMedia();
@ -222,14 +182,4 @@ namespace App {
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, radius, parts); return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, radius, parts);
} }
struct WallPaper {
WallPaper(int32 id, ImagePtr thumb, ImagePtr full) : id(id), thumb(thumb), full(full) {
}
int32 id;
ImagePtr thumb;
ImagePtr full;
};
typedef QList<WallPaper> WallPapers;
DeclareSetting(WallPapers, ServerBackgrounds);
}; };

View File

@ -377,8 +377,7 @@ AuthSession &Auth() {
} }
AuthSession::AuthSession(const MTPUser &user) AuthSession::AuthSession(const MTPUser &user)
: _user(App::user(user.match([](const auto &data) { return data.vid.v; }))) : _autoLockTimer([this] { checkAutoLock(); })
, _autoLockTimer([this] { checkAutoLock(); })
, _api(std::make_unique<ApiWrap>(this)) , _api(std::make_unique<ApiWrap>(this))
, _calls(std::make_unique<Calls::Instance>()) , _calls(std::make_unique<Calls::Instance>())
, _downloader(std::make_unique<Storage::Downloader>()) , _downloader(std::make_unique<Storage::Downloader>())
@ -386,13 +385,9 @@ 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))
, _changelogs(Core::Changelogs::Create(this)) , _changelogs(Core::Changelogs::Create(this))
, _supportHelper( , _supportHelper(Support::Helper::Create(this)) {
(Support::ValidateAccount(user)
? std::make_unique<Support::Helper>(this)
: nullptr)) {
App::feedUser(user);
_saveDataTimer.setCallback([=] { _saveDataTimer.setCallback([=] {
Local::writeUserSettings(); Local::writeUserSettings();
}); });
@ -515,4 +510,7 @@ Support::Templates& AuthSession::supportTemplates() const {
return supportHelper().templates(); return supportHelper().templates();
} }
AuthSession::~AuthSession() = default; AuthSession::~AuthSession() {
ClickHandler::clearActive();
ClickHandler::unpressed();
}

View File

@ -345,7 +345,6 @@ public:
private: private:
static constexpr auto kDefaultSaveDelay = TimeMs(1000); static constexpr auto kDefaultSaveDelay = TimeMs(1000);
const not_null<UserData*> _user;
AuthSessionSettings _settings; AuthSessionSettings _settings;
base::Timer _saveDataTimer; base::Timer _saveDataTimer;
@ -359,8 +358,9 @@ private:
const std::unique_ptr<Storage::Facade> _storage; const std::unique_ptr<Storage::Facade> _storage;
const std::unique_ptr<Window::Notifications::System> _notifications; const std::unique_ptr<Window::Notifications::System> _notifications;
// _data depends on _downloader / _uploader, including destructor. // _data depends on _downloader / _uploader / _notifications.
const std::unique_ptr<Data::Session> _data; const std::unique_ptr<Data::Session> _data;
const not_null<UserData*> _user;
// _changelogs depends on _data, subscribes on chats loading event. // _changelogs depends on _data, subscribes on chats loading event.
const std::unique_ptr<Core::Changelogs> _changelogs; const std::unique_ptr<Core::Changelogs> _changelogs;

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/round_checkbox.h" #include "ui/effects/round_checkbox.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "auth_session.h" #include "auth_session.h"
#include "data/data_session.h"
#include "styles/style_overview.h" #include "styles/style_overview.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -53,18 +54,20 @@ BackgroundBox::BackgroundBox(QWidget*) {
void BackgroundBox::prepare() { void BackgroundBox::prepare() {
setTitle(langFactory(lng_backgrounds_header)); setTitle(langFactory(lng_backgrounds_header));
addButton(langFactory(lng_close), [this] { closeBox(); }); addButton(langFactory(lng_close), [=] { closeBox(); });
setDimensions(st::boxWideWidth, st::boxMaxListHeight); setDimensions(st::boxWideWidth, st::boxMaxListHeight);
_inner = setInnerWidget(object_ptr<Inner>(this), st::backgroundScroll); _inner = setInnerWidget(object_ptr<Inner>(this), st::backgroundScroll);
_inner->setBackgroundChosenCallback([this](int index) { backgroundChosen(index); }); _inner->setBackgroundChosenCallback([=](int index) {
backgroundChosen(index);
});
} }
void BackgroundBox::backgroundChosen(int index) { void BackgroundBox::backgroundChosen(int index) {
if (index >= 0 && index < App::cServerBackgrounds().size()) { if (index >= 0 && index < Auth().data().wallpapersCount()) {
auto &paper = App::cServerBackgrounds()[index]; const auto &paper = Auth().data().wallpaper(index);
if (App::main()) App::main()->setChatBackground(paper); App::main()->setChatBackground(paper);
using Update = Window::Theme::BackgroundUpdate; using Update = Window::Theme::BackgroundUpdate;
Window::Theme::Background()->notify(Update(Update::Type::Start, !paper.id)); Window::Theme::Background()->notify(Update(Update::Type::Start, !paper.id));
@ -75,7 +78,7 @@ void BackgroundBox::backgroundChosen(int index) {
BackgroundBox::Inner::Inner(QWidget *parent) : TWidget(parent) BackgroundBox::Inner::Inner(QWidget *parent) : TWidget(parent)
, _check(std::make_unique<Ui::RoundCheckbox>(st::overviewCheck, [this] { update(); })) { , _check(std::make_unique<Ui::RoundCheckbox>(st::overviewCheck, [this] { update(); })) {
_check->setChecked(true, Ui::RoundCheckbox::SetStyle::Fast); _check->setChecked(true, Ui::RoundCheckbox::SetStyle::Fast);
if (App::cServerBackgrounds().isEmpty()) { if (!Auth().data().wallpapersCount()) {
resize(BackgroundsInRow * (st::backgroundSize.width() + st::backgroundPadding) + st::backgroundPadding, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding); resize(BackgroundsInRow * (st::backgroundSize.width() + st::backgroundPadding) + st::backgroundPadding, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding);
MTP::send(MTPaccount_GetWallPapers(), rpcDone(&Inner::gotWallpapers)); MTP::send(MTPaccount_GetWallPapers(), rpcDone(&Inner::gotWallpapers));
} else { } else {
@ -92,65 +95,12 @@ BackgroundBox::Inner::Inner(QWidget *parent) : TWidget(parent)
} }
void BackgroundBox::Inner::gotWallpapers(const MTPVector<MTPWallPaper> &result) { void BackgroundBox::Inner::gotWallpapers(const MTPVector<MTPWallPaper> &result) {
App::WallPapers wallpapers; Auth().data().setWallpapers(result.v);
auto oldBackground = Images::Create(qsl(":/gui/art/bg_initial.jpg"), "JPG");
wallpapers.push_back(App::WallPaper(Window::Theme::kInitialBackground, oldBackground, oldBackground));
auto &v = result.v;
for_const (auto &w, v) {
switch (w.type()) {
case mtpc_wallPaper: {
auto &d = w.c_wallPaper();
auto &sizes = d.vsizes.v;
const MTPPhotoSize *thumb = 0, *full = 0;
int32 thumbLevel = -1, fullLevel = -1;
for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) {
char size = 0;
int32 w = 0, h = 0;
switch (j->type()) {
case mtpc_photoSize: {
auto &s = j->c_photoSize().vtype.v;
if (s.size()) size = s[0];
w = j->c_photoSize().vw.v;
h = j->c_photoSize().vh.v;
} break;
case mtpc_photoCachedSize: {
auto &s = j->c_photoCachedSize().vtype.v;
if (s.size()) size = s[0];
w = j->c_photoCachedSize().vw.v;
h = j->c_photoCachedSize().vh.v;
} break;
}
if (!size || !w || !h) continue;
int32 newThumbLevel = qAbs((st::backgroundSize.width() * cIntRetinaFactor()) - w), newFullLevel = qAbs(2560 - w);
if (thumbLevel < 0 || newThumbLevel < thumbLevel) {
thumbLevel = newThumbLevel;
thumb = &(*j);
}
if (fullLevel < 0 || newFullLevel < fullLevel) {
fullLevel = newFullLevel;
full = &(*j);
}
}
if (thumb && full && full->type() != mtpc_photoSizeEmpty) {
wallpapers.push_back(App::WallPaper(d.vid.v ? d.vid.v : INT_MAX, App::image(*thumb), App::image(*full)));
}
} break;
case mtpc_wallPaperSolid: {
auto &d = w.c_wallPaperSolid();
} break;
}
}
App::cSetServerBackgrounds(wallpapers);
updateWallpapers(); updateWallpapers();
} }
void BackgroundBox::Inner::updateWallpapers() { void BackgroundBox::Inner::updateWallpapers() {
_bgCount = App::cServerBackgrounds().size(); _bgCount = Auth().data().wallpapersCount();
_rows = _bgCount / BackgroundsInRow; _rows = _bgCount / BackgroundsInRow;
if (_bgCount % BackgroundsInRow) ++_rows; if (_bgCount % BackgroundsInRow) ++_rows;
@ -158,7 +108,7 @@ void BackgroundBox::Inner::updateWallpapers() {
for (int i = 0; i < BackgroundsInRow * 3; ++i) { for (int i = 0; i < BackgroundsInRow * 3; ++i) {
if (i >= _bgCount) break; if (i >= _bgCount) break;
App::cServerBackgrounds()[i].thumb->load(Data::FileOrigin()); Auth().data().wallpaper(i).thumb->load(Data::FileOrigin());
} }
} }
@ -173,7 +123,7 @@ void BackgroundBox::Inner::paintEvent(QPaintEvent *e) {
int index = i * BackgroundsInRow + j; int index = i * BackgroundsInRow + j;
if (index >= _bgCount) break; if (index >= _bgCount) break;
const auto &paper = App::cServerBackgrounds()[index]; const auto &paper = Auth().data().wallpaper(index);
paper.thumb->load(Data::FileOrigin()); paper.thumb->load(Data::FileOrigin());
int x = st::backgroundPadding + j * (st::backgroundSize.width() + st::backgroundPadding); int x = st::backgroundPadding + j * (st::backgroundSize.width() + st::backgroundPadding);

View File

@ -302,11 +302,11 @@ void BoxController::receivedCalls(const QVector<MTPMessage> &result) {
_allLoaded = true; _allLoaded = true;
} }
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 = App::peerLoaded(peerId)) {
auto item = App::histories().addNewMessage(message, NewMessageExisting); auto item = Auth().data().addNewMessage(message, NewMessageExisting);
insertRow(item, InsertWay::Append); insertRow(item, InsertWay::Append);
} else { } else {
LOG(("API Error: a search results with not loaded peer %1").arg(peerId)); LOG(("API Error: a search results with not loaded peer %1").arg(peerId));

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 "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "data/data_session.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
@ -376,7 +377,7 @@ InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field) {
auto username = text.midRef(inlineUsernameStart, inlineUsernameLength); auto username = text.midRef(inlineUsernameStart, inlineUsernameLength);
if (username != result.username) { if (username != result.username) {
result.username = username.toString(); result.username = username.toString();
if (const auto peer = App::peerByName(result.username)) { if (const auto peer = Auth().data().peerByUsername(result.username)) {
if (const auto user = peer->asUser()) { if (const auto user = peer->asUser()) {
result.bot = peer->asUser(); result.bot = peer->asUser();
} else { } else {

View File

@ -369,15 +369,15 @@ void Feed::changedInChatListHook(Dialogs::Mode list, bool added) {
const auto nonMutedCount = count - mutedCount; const auto nonMutedCount = count - mutedCount;
const auto mutedDelta = added ? mutedCount : -mutedCount; const auto mutedDelta = added ? mutedCount : -mutedCount;
const auto nonMutedDelta = added ? nonMutedCount : -nonMutedCount; const auto nonMutedDelta = added ? nonMutedCount : -nonMutedCount;
App::histories().unreadIncrement(nonMutedDelta, false); Auth().data().unreadIncrement(nonMutedDelta, false);
App::histories().unreadIncrement(mutedDelta, true); Auth().data().unreadIncrement(mutedDelta, true);
const auto fullMuted = (nonMutedCount == 0); const auto fullMuted = (nonMutedCount == 0);
const auto entriesWithUnreadDelta = added ? 1 : -1; const auto entriesWithUnreadDelta = added ? 1 : -1;
const auto mutedEntriesWithUnreadDelta = fullMuted const auto mutedEntriesWithUnreadDelta = fullMuted
? entriesWithUnreadDelta ? entriesWithUnreadDelta
: 0; : 0;
App::histories().unreadEntriesChanged( Auth().data().unreadEntriesChanged(
entriesWithUnreadDelta, entriesWithUnreadDelta,
mutedEntriesWithUnreadDelta); mutedEntriesWithUnreadDelta);
} }
@ -402,11 +402,11 @@ void Feed::updateUnreadCounts(PerformUpdate &&performUpdate) {
const auto nowFullMuted = (nowUnreadMutedCount > 0) const auto nowFullMuted = (nowUnreadMutedCount > 0)
&& (nowUnreadCount == nowUnreadMutedCount); && (nowUnreadCount == nowUnreadMutedCount);
App::histories().unreadIncrement( Auth().data().unreadIncrement(
(nowUnreadCount - nowUnreadMutedCount) (nowUnreadCount - nowUnreadMutedCount)
- (wasUnreadCount - wasUnreadMutedCount), - (wasUnreadCount - wasUnreadMutedCount),
false); false);
App::histories().unreadIncrement( Auth().data().unreadIncrement(
nowUnreadMutedCount - wasUnreadMutedCount, nowUnreadMutedCount - wasUnreadMutedCount,
true); true);
@ -420,7 +420,7 @@ void Feed::updateUnreadCounts(PerformUpdate &&performUpdate) {
: (wasFullMuted && !nowFullMuted) : (wasFullMuted && !nowFullMuted)
? -1 ? -1
: 0; : 0;
App::histories().unreadEntriesChanged( Auth().data().unreadEntriesChanged(
entriesDelta, entriesDelta,
mutedEntriesDelta); mutedEntriesDelta);
} }

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_location_manager.h" #include "history/history_location_manager.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
@ -35,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_web_page.h" #include "data/data_web_page.h"
#include "data/data_poll.h" #include "data/data_poll.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "auth_session.h"
#include "layout.h" #include "layout.h"
namespace Data { namespace Data {
@ -63,7 +63,9 @@ Call ComputeCallData(const MTPDmessageActionPhoneCall &call) {
return result; return result;
} }
Invoice ComputeInvoiceData(const MTPDmessageMediaInvoice &data) { Invoice ComputeInvoiceData(
not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data) {
auto result = Invoice(); auto result = Invoice();
result.isTest = data.is_test(); result.isTest = data.is_test();
result.amount = data.vtotal_amount.v; result.amount = data.vtotal_amount.v;
@ -74,7 +76,7 @@ Invoice ComputeInvoiceData(const MTPDmessageMediaInvoice &data) {
result.receiptMsgId = data.vreceipt_msg_id.v; result.receiptMsgId = data.vreceipt_msg_id.v;
} }
if (data.has_photo()) { if (data.has_photo()) {
result.photo = Auth().data().photoFromWeb(data.vphoto); result.photo = item->history()->owner().photoFromWeb(data.vphoto);
} }
return result; return result;
} }
@ -241,7 +243,7 @@ MediaPhoto::MediaPhoto(
not_null<PhotoData*> photo) not_null<PhotoData*> photo)
: Media(parent) : Media(parent)
, _photo(photo) { , _photo(photo) {
Auth().data().registerPhotoItem(_photo, parent); parent->history()->owner().registerPhotoItem(_photo, parent);
} }
MediaPhoto::MediaPhoto( MediaPhoto::MediaPhoto(
@ -251,11 +253,11 @@ MediaPhoto::MediaPhoto(
: Media(parent) : Media(parent)
, _photo(photo) , _photo(photo)
, _chat(chat) { , _chat(chat) {
Auth().data().registerPhotoItem(_photo, parent); parent->history()->owner().registerPhotoItem(_photo, parent);
} }
MediaPhoto::~MediaPhoto() { MediaPhoto::~MediaPhoto() {
Auth().data().unregisterPhotoItem(_photo, parent()); parent()->history()->owner().unregisterPhotoItem(_photo, parent());
} }
std::unique_ptr<Media> MediaPhoto::clone(not_null<HistoryItem*> parent) { std::unique_ptr<Media> MediaPhoto::clone(not_null<HistoryItem*> parent) {
@ -336,7 +338,7 @@ 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 = Auth().data().photo(data.vphoto); const auto photo = parent()->history()->owner().photo(data.vphoto);
if (photo == _photo) { if (photo == _photo) {
return true; return true;
} else { } else {
@ -362,7 +364,7 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
const auto &photo = mediaPhoto.vphoto; const auto &photo = mediaPhoto.vphoto;
Auth().data().photoConvert(_photo, photo); parent()->history()->owner().photoConvert(_photo, photo);
if (photo.type() != mtpc_photo) { if (photo.type() != mtpc_photo) {
return false; return false;
@ -374,7 +376,7 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
const MTPFileLocation *location = nullptr; const MTPFileLocation *location = nullptr;
QByteArray bytes; QByteArray bytes;
}; };
const auto saveImageToCache = []( const auto saveImageToCache = [&](
const ImagePtr &image, const ImagePtr &image,
SizeData size) { SizeData size) {
Expects(size.location != nullptr); Expects(size.location != nullptr);
@ -394,7 +396,7 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
LOG(("App Error: Bad photo data for saving to cache.")); LOG(("App Error: Bad photo data for saving to cache."));
return; return;
} }
Auth().data().cache().putIfEmpty( parent()->history()->owner().cache().putIfEmpty(
Data::StorageCacheKey(key), Data::StorageCacheKey(key),
Storage::Cache::Database::TaggedValue( Storage::Cache::Database::TaggedValue(
std::move(size.bytes), std::move(size.bytes),
@ -471,7 +473,7 @@ MediaFile::MediaFile(
: Media(parent) : Media(parent)
, _document(document) , _document(document)
, _emoji(document->sticker() ? document->sticker()->alt : QString()) { , _emoji(document->sticker() ? document->sticker()->alt : QString()) {
Auth().data().registerDocumentItem(_document, parent); parent->history()->owner().registerDocumentItem(_document, parent);
if (!_emoji.isEmpty()) { if (!_emoji.isEmpty()) {
if (const auto emoji = Ui::Emoji::Find(_emoji)) { if (const auto emoji = Ui::Emoji::Find(_emoji)) {
@ -481,7 +483,9 @@ MediaFile::MediaFile(
} }
MediaFile::~MediaFile() { MediaFile::~MediaFile() {
Auth().data().unregisterDocumentItem(_document, parent()); parent()->history()->owner().unregisterDocumentItem(
_document,
parent());
} }
std::unique_ptr<Media> MediaFile::clone(not_null<HistoryItem*> parent) { std::unique_ptr<Media> MediaFile::clone(not_null<HistoryItem*> parent) {
@ -670,7 +674,8 @@ 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 = Auth().data().document(data.vdocument); const auto document = parent()->history()->owner().document(
data.vdocument);
if (document == _document) { if (document == _document) {
return false; return false;
} else { } else {
@ -695,7 +700,7 @@ bool MediaFile::updateSentMedia(const MTPMessageMedia &media) {
"or with ttl_seconds in updateSentMedia()")); "or with ttl_seconds in updateSentMedia()"));
return false; return false;
} }
Auth().data().documentConvert(_document, data.vdocument); parent()->history()->owner().documentConvert(_document, data.vdocument);
if (const auto good = _document->goodThumbnail()) { if (const auto good = _document->goodThumbnail()) {
auto bytes = good->bytesForCache(); auto bytes = good->bytesForCache();
@ -703,7 +708,7 @@ bool MediaFile::updateSentMedia(const MTPMessageMedia &media) {
if (length > Storage::kMaxFileInMemory) { if (length > Storage::kMaxFileInMemory) {
LOG(("App Error: Bad thumbnail data for saving to cache.")); LOG(("App Error: Bad thumbnail data for saving to cache."));
} else { } else {
Auth().data().cache().putIfEmpty( parent()->history()->owner().cache().putIfEmpty(
_document->goodThumbnailCacheKey(), _document->goodThumbnailCacheKey(),
Storage::Cache::Database::TaggedValue( Storage::Cache::Database::TaggedValue(
std::move(bytes), std::move(bytes),
@ -739,7 +744,7 @@ MediaContact::MediaContact(
const QString &lastName, const QString &lastName,
const QString &phoneNumber) const QString &phoneNumber)
: Media(parent) { : Media(parent) {
Auth().data().registerContactItem(userId, parent); parent->history()->owner().registerContactItem(userId, parent);
_contact.userId = userId; _contact.userId = userId;
_contact.firstName = firstName; _contact.firstName = firstName;
@ -748,7 +753,9 @@ MediaContact::MediaContact(
} }
MediaContact::~MediaContact() { MediaContact::~MediaContact() {
Auth().data().unregisterContactItem(_contact.userId, parent()); parent()->history()->owner().unregisterContactItem(
_contact.userId,
parent());
} }
std::unique_ptr<Media> MediaContact::clone(not_null<HistoryItem*> parent) { std::unique_ptr<Media> MediaContact::clone(not_null<HistoryItem*> parent) {
@ -793,9 +800,13 @@ bool MediaContact::updateSentMedia(const MTPMessageMedia &media) {
return false; return false;
} }
if (_contact.userId != media.c_messageMediaContact().vuser_id.v) { if (_contact.userId != media.c_messageMediaContact().vuser_id.v) {
Auth().data().unregisterContactItem(_contact.userId, parent()); parent()->history()->owner().unregisterContactItem(
_contact.userId,
parent());
_contact.userId = media.c_messageMediaContact().vuser_id.v; _contact.userId = media.c_messageMediaContact().vuser_id.v;
Auth().data().registerContactItem(_contact.userId, parent()); parent()->history()->owner().registerContactItem(
_contact.userId,
parent());
} }
return true; return true;
} }
@ -823,7 +834,7 @@ MediaLocation::MediaLocation(
const QString &title, const QString &title,
const QString &description) const QString &description)
: Media(parent) : Media(parent)
, _location(Auth().data().location(coords)) , _location(parent->history()->owner().location(coords))
, _title(title) , _title(title)
, _description(description) { , _description(description) {
} }
@ -970,11 +981,11 @@ MediaWebPage::MediaWebPage(
not_null<WebPageData*> page) not_null<WebPageData*> page)
: Media(parent) : Media(parent)
, _page(page) { , _page(page) {
Auth().data().registerWebPageItem(_page, parent); parent->history()->owner().registerWebPageItem(_page, parent);
} }
MediaWebPage::~MediaWebPage() { MediaWebPage::~MediaWebPage() {
Auth().data().unregisterWebPageItem(_page, parent()); parent()->history()->owner().unregisterWebPageItem(_page, parent());
} }
std::unique_ptr<Media> MediaWebPage::clone(not_null<HistoryItem*> parent) { std::unique_ptr<Media> MediaWebPage::clone(not_null<HistoryItem*> parent) {
@ -1126,7 +1137,8 @@ bool MediaGame::updateSentMedia(const MTPMessageMedia &media) {
if (media.type() != mtpc_messageMediaGame) { if (media.type() != mtpc_messageMediaGame) {
return false; return false;
} }
Auth().data().gameConvert(_game, media.c_messageMediaGame().vgame); parent()->history()->owner().gameConvert(
_game, media.c_messageMediaGame().vgame);
return true; return true;
} }
@ -1140,7 +1152,7 @@ MediaInvoice::MediaInvoice(
not_null<HistoryItem*> parent, not_null<HistoryItem*> parent,
const MTPDmessageMediaInvoice &data) const MTPDmessageMediaInvoice &data)
: Media(parent) : Media(parent)
, _invoice(ComputeInvoiceData(data)) { , _invoice(ComputeInvoiceData(parent, data)) {
} }
MediaInvoice::MediaInvoice( MediaInvoice::MediaInvoice(
@ -1233,9 +1245,9 @@ TextWithEntities MediaPoll::clipboardText() const {
+ ranges::accumulate( + ranges::accumulate(
ranges::view::all( ranges::view::all(
_poll->answers _poll->answers
) | ranges::view::transform( ) | ranges::view::transform([](const PollAnswer &answer) {
[](const PollAnswer &answer) { return "\n- " + answer.text; } return "\n- " + answer.text;
), }),
QString()); QString());
return { text, EntitiesInText() }; return { text, EntitiesInText() };
} }

View File

@ -92,12 +92,21 @@ void PeerClickHandler::onClick(ClickContext context) const {
} }
} }
PeerData::PeerData(const PeerId &id) PeerData::PeerData(not_null<Data::Session*> owner, PeerId id)
: id(id) : id(id)
, _owner(owner)
, _userpicEmpty(createEmptyUserpic()) { , _userpicEmpty(createEmptyUserpic()) {
nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions()); nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions());
} }
Data::Session &PeerData::owner() const {
return *_owner;
}
AuthSession &PeerData::session() const {
return _owner->session();
}
void PeerData::updateNameDelayed( void PeerData::updateNameDelayed(
const QString &newName, const QString &newName,
const QString &newNameOrPhone, const QString &newNameOrPhone,
@ -173,7 +182,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 = Auth().data().photo(data); const auto photo = owner().photo(data);
photo->peer = this; photo->peer = this;
return photo->id; return photo->id;
}, [](const MTPDphotoEmpty &data) { }, [](const MTPDphotoEmpty &data) {
@ -322,7 +331,7 @@ void PeerData::setUserpicChecked(
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged); Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
if (const auto channel = asChannel()) { if (const auto channel = asChannel()) {
if (const auto feed = channel->feed()) { if (const auto feed = channel->feed()) {
Auth().data().notifyFeedUpdated( owner().notifyFeedUpdated(
feed, feed,
Data::FeedUpdateFlag::ChannelPhoto); Data::FeedUpdateFlag::ChannelPhoto);
} }
@ -417,9 +426,13 @@ const Text &BotCommand::descriptionText() const {
return _descriptionText; return _descriptionText;
} }
UserData::UserData(not_null<Data::Session*> owner, PeerId id)
: PeerData(owner, id) {
}
bool UserData::canShareThisContact() const { bool UserData::canShareThisContact() const {
return canShareThisContactFast() return canShareThisContactFast()
|| !Auth().data().findContactPhone(peerToUser(id)).isEmpty(); || !owner().findContactPhone(peerToUser(id)).isEmpty();
} }
void UserData::setContactStatus(ContactStatus status) { void UserData::setContactStatus(ContactStatus status) {
@ -621,6 +634,11 @@ bool UserData::hasCalls() const {
&& (callsStatus() != CallsStatus::Unknown); && (callsStatus() != CallsStatus::Unknown);
} }
ChatData::ChatData(not_null<Data::Session*> owner, PeerId id)
: PeerData(owner, id)
, inputChat(MTP_int(bareId())) {
}
void ChatData::setPhoto(const MTPChatPhoto &photo) { void ChatData::setPhoto(const MTPChatPhoto &photo) {
setPhoto(userpicPhotoId(), photo); setPhoto(userpicPhotoId(), photo);
} }
@ -658,8 +676,8 @@ void ChatData::setInviteLink(const QString &newInviteLink) {
} }
} }
ChannelData::ChannelData(const PeerId &id) ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
: PeerData(id) : PeerData(owner, id)
, inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) { , inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) {
Data::PeerFlagValue( Data::PeerFlagValue(
this, this,
@ -699,10 +717,10 @@ void PeerData::updateFull() {
} }
void PeerData::updateFullForced() { void PeerData::updateFullForced() {
Auth().api().requestFullPeer(this); session().api().requestFullPeer(this);
if (auto channel = asChannel()) { if (auto channel = asChannel()) {
if (!channel->amCreator() && !channel->inviter) { if (!channel->amCreator() && !channel->inviter) {
Auth().api().requestSelfParticipant(channel); session().api().requestSelfParticipant(channel);
} }
} }
} }
@ -874,7 +892,7 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
} }
} }
flags |= Notify::PeerUpdate::Flag::MembersChanged; flags |= Notify::PeerUpdate::Flag::MembersChanged;
Auth().data().removeMegagroupParticipant(this, user); owner().removeMegagroupParticipant(this, user);
} }
} }
Data::ChannelAdminChanges(this).feed(peerToUser(user->id), false); Data::ChannelAdminChanges(this).feed(peerToUser(user->id), false);
@ -907,9 +925,6 @@ void ChannelData::setRestrictionReason(const QString &text) {
void ChannelData::setAvailableMinId(MsgId availableMinId) { void ChannelData::setAvailableMinId(MsgId availableMinId) {
if (_availableMinId != availableMinId) { if (_availableMinId != availableMinId) {
_availableMinId = availableMinId; _availableMinId = availableMinId;
if (auto history = App::historyLoaded(this)) {
history->clearUpTill(availableMinId);
}
if (pinnedMessageId() <= _availableMinId) { if (pinnedMessageId() <= _availableMinId) {
clearPinnedMessage(); clearPinnedMessage();
} }
@ -1075,7 +1090,7 @@ void ChannelData::setAdminRights(const MTPChannelAdminRights &rights) {
} }
_adminRights.set(rights.c_channelAdminRights().vflags.v); _adminRights.set(rights.c_channelAdminRights().vflags.v);
if (isMegagroup()) { if (isMegagroup()) {
const auto self = Auth().user(); const auto self = session().user();
if (hasAdminRights()) { if (hasAdminRights()) {
if (!amCreator()) { if (!amCreator()) {
auto me = MegagroupInfo::Admin { rights }; auto me = MegagroupInfo::Admin { rights };
@ -1088,7 +1103,7 @@ void ChannelData::setAdminRights(const MTPChannelAdminRights &rights) {
} }
auto amAdmin = hasAdminRights() || amCreator(); auto amAdmin = hasAdminRights() || amCreator();
Data::ChannelAdminChanges(this).feed(Auth().userId(), amAdmin); Data::ChannelAdminChanges(this).feed(session().userId(), amAdmin);
} }
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged); Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
} }
@ -1101,14 +1116,14 @@ void ChannelData::setRestrictedRights(const MTPChannelBannedRights &rights) {
_restrictedUntill = rights.c_channelBannedRights().vuntil_date.v; _restrictedUntill = rights.c_channelBannedRights().vuntil_date.v;
_restrictions.set(rights.c_channelBannedRights().vflags.v); _restrictions.set(rights.c_channelBannedRights().vflags.v);
if (isMegagroup()) { if (isMegagroup()) {
const auto self = Auth().user(); const auto self = session().user();
if (hasRestrictions()) { if (hasRestrictions()) {
if (!amCreator()) { if (!amCreator()) {
auto me = MegagroupInfo::Restricted { rights }; auto me = MegagroupInfo::Restricted { rights };
mgInfo->lastRestricted.emplace(self, me); mgInfo->lastRestricted.emplace(self, me);
} }
mgInfo->lastAdmins.remove(self); mgInfo->lastAdmins.remove(self);
Data::ChannelAdminChanges(this).feed(Auth().userId(), false); Data::ChannelAdminChanges(this).feed(session().userId(), false);
} else { } else {
mgInfo->lastRestricted.remove(self); mgInfo->lastRestricted.remove(self);
} }

View File

@ -16,6 +16,7 @@ namespace Ui {
class EmptyUserpic; class EmptyUserpic;
} // namespace Ui } // namespace Ui
class AuthSession;
class PeerData; class PeerData;
class UserData; class UserData;
class ChatData; class ChatData;
@ -24,6 +25,7 @@ class ChannelData;
namespace Data { namespace Data {
class Feed; class Feed;
class Session;
int PeerColorIndex(PeerId peerId); int PeerColorIndex(PeerId peerId);
int PeerColorIndex(int32 bareId); int PeerColorIndex(int32 bareId);
@ -47,13 +49,16 @@ private:
class PeerData { class PeerData {
protected: protected:
PeerData(const PeerId &id); PeerData(not_null<Data::Session*> owner, PeerId id);
PeerData(const PeerData &other) = delete; PeerData(const PeerData &other) = delete;
PeerData &operator=(const PeerData &other) = delete; PeerData &operator=(const PeerData &other) = delete;
public: public:
virtual ~PeerData(); virtual ~PeerData();
Data::Session &owner() const;
AuthSession &session() const;
bool isUser() const { bool isUser() const {
return peerIsUser(id); return peerIsUser(id);
} }
@ -239,6 +244,8 @@ private:
static constexpr auto kUnknownPhotoId = PhotoId(0xFFFFFFFFFFFFFFFFULL); static constexpr auto kUnknownPhotoId = PhotoId(0xFFFFFFFFFFFFFFFFULL);
not_null<Data::Session*> _owner;
ImagePtr _userpic; ImagePtr _userpic;
PhotoId _userpicPhotoId = kUnknownPhotoId; PhotoId _userpicPhotoId = kUnknownPhotoId;
mutable std::unique_ptr<Ui::EmptyUserpic> _userpicEmpty; mutable std::unique_ptr<Ui::EmptyUserpic> _userpicEmpty;
@ -320,8 +327,7 @@ public:
MTPDuserFull::Flags, MTPDuserFull::Flags,
kEssentialFullFlags.value()>; kEssentialFullFlags.value()>;
UserData(const PeerId &id) : PeerData(id) { UserData(not_null<Data::Session*> owner, PeerId id);
}
void setPhoto(const MTPUserProfilePhoto &photo); void setPhoto(const MTPUserProfilePhoto &photo);
void setName( void setName(
@ -503,10 +509,8 @@ public:
MTPDchat::Flags, MTPDchat::Flags,
kEssentialFlags>; kEssentialFlags>;
ChatData(const PeerId &id) ChatData(not_null<Data::Session*> owner, PeerId id);
: PeerData(id)
, inputChat(MTP_int(bareId())) {
}
void setPhoto(const MTPChatPhoto &photo); void setPhoto(const MTPChatPhoto &photo);
void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); void setPhoto(PhotoId photoId, const MTPChatPhoto &photo);
@ -753,7 +757,7 @@ public:
MTPDchannelFull::Flags, MTPDchannelFull::Flags,
kEssentialFullFlags>; kEssentialFullFlags>;
ChannelData(const PeerId &id); ChannelData(not_null<Data::Session*> owner, PeerId id);
void setPhoto(const MTPChatPhoto &photo); void setPhoto(const MTPChatPhoto &photo);
void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); void setPhoto(PhotoId photoId, const MTPChatPhoto &photo);

View File

@ -149,8 +149,8 @@ SearchResult ParseSearchResult(
auto addType = NewMessageExisting; auto addType = NewMessageExisting;
result.messageIds.reserve(messages->size()); result.messageIds.reserve(messages->size());
for (auto &message : *messages) { for (const auto &message : *messages) {
if (auto item = App::histories().addNewMessage(message, addType)) { if (auto item = Auth().data().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)) {

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,12 @@ class Feed;
enum class FeedUpdateFlag; enum class FeedUpdateFlag;
struct FeedUpdate; struct FeedUpdate;
struct WallPaper {
int32 id = 0;
ImagePtr thumb;
ImagePtr full;
};
class Session final { class Session final {
public: public:
using ViewElement = HistoryView::Element; using ViewElement = HistoryView::Element;
@ -60,6 +66,8 @@ public:
return *_session; return *_session;
} }
void clear();
void startExport(PeerData *peer = nullptr); void startExport(PeerData *peer = nullptr);
void startExport(const MTPInputPeer &singlePeer); void startExport(const MTPInputPeer &singlePeer);
void suggestStartExport(TimeId availableAt); void suggestStartExport(TimeId availableAt);
@ -77,6 +85,39 @@ public:
Storage::Cache::Database &cache(); Storage::Cache::Database &cache();
[[nodiscard]] not_null<PeerData*> peer(PeerId id);
[[nodiscard]] not_null<UserData*> user(UserId id);
[[nodiscard]] not_null<ChatData*> chat(ChatId id);
[[nodiscard]] not_null<ChannelData*> channel(ChannelId id);
[[nodiscard]] PeerData *peerLoaded(PeerId id) const;
[[nodiscard]] UserData *userLoaded(UserId id) const;
[[nodiscard]] ChatData *chatLoaded(ChatId id) const;
[[nodiscard]] ChannelData *channelLoaded(ChannelId id) const;
not_null<UserData*> user(const MTPUser &data);
not_null<PeerData*> chat(const MTPChat &data);
// Returns last user, if there were any.
UserData *processUsers(const MTPVector<MTPUser> &data);
PeerData *processChats(const MTPVector<MTPChat> &data);
void enumerateUsers(Fn<void(not_null<UserData*>)> action) const;
void enumerateGroups(Fn<void(not_null<PeerData*>)> action) const;
void enumerateChannels(Fn<void(not_null<ChannelData*>)> action) const;
[[nodiscard]] PeerData *peerByUsername(const QString &username) const;
not_null<History*> history(PeerId peerId);
History *historyLoaded(PeerId peerId) const;
not_null<History*> history(not_null<const PeerData*> peer);
History *historyLoaded(const PeerData *peer);
void registerSendAction(
not_null<History*> history,
not_null<UserData*> user,
const MTPSendMessageAction &action,
TimeId when);
[[nodiscard]] base::Variable<bool> &contactsLoaded() { [[nodiscard]] base::Variable<bool> &contactsLoaded() {
return _contactsLoaded; return _contactsLoaded;
} }
@ -247,6 +288,34 @@ public:
void markMediaRead(not_null<const DocumentData*> document); void markMediaRead(not_null<const DocumentData*> document);
void requestPollViewRepaint(not_null<const PollData*> poll); void requestPollViewRepaint(not_null<const PollData*> poll);
HistoryItem *addNewMessage(const MTPMessage &data, NewMessageType type);
struct SendActionAnimationUpdate {
not_null<History*> history;
int width = 0;
int height = 0;
bool textUpdated = false;
};
[[nodiscard]] auto sendActionAnimationUpdated() const
-> rpl::producer<SendActionAnimationUpdate>;
void updateSendActionAnimation(SendActionAnimationUpdate &&update);
void updateSendActionAnimation();
int unreadBadge() const;
bool unreadBadgeMuted() const;
int unreadBadgeIgnoreOne(History *history) const;
bool unreadBadgeMutedIgnoreOne(History *history) const;
int unreadOnlyMutedBadge() const;
void unreadIncrement(int count, bool muted);
void unreadMuteChanged(int count, bool muted);
void unreadEntriesChanged(
int withUnreadDelta,
int mutedWithUnreadDelta);
void selfDestructIn(not_null<HistoryItem*> item, TimeMs delay);
not_null<PhotoData*> photo(PhotoId id); not_null<PhotoData*> photo(PhotoId id);
not_null<PhotoData*> photo(const MTPPhoto &data); not_null<PhotoData*> photo(const MTPPhoto &data);
not_null<PhotoData*> photo(const MTPDphoto &data); not_null<PhotoData*> photo(const MTPDphoto &data);
@ -452,11 +521,30 @@ public:
return _groups; return _groups;
} }
int wallpapersCount() const;
const WallPaper &wallpaper(int index) const;
void setWallpapers(const QVector<MTPWallPaper> &data);
void clearLocalStorage();
private: private:
void suggestStartExport(); void suggestStartExport();
void setupContactViewsViewer(); void setupContactViewsViewer();
void setupChannelLeavingViewer(); void setupChannelLeavingViewer();
void checkSelfDestructItems();
int computeUnreadBadge(
int full,
int muted,
int entriesFull,
int entriesMuted) const;
bool computeUnreadBadgeMuted(
int full,
int muted,
int entriesFull,
int entriesMuted) const;
void photoApplyFields( void photoApplyFields(
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
const MTPPhoto &data); const MTPPhoto &data);
@ -554,6 +642,8 @@ private:
const MTPMessageMedia &media, const MTPMessageMedia &media,
TimeId date); TimeId date);
void step_typings(TimeMs ms, bool timer);
not_null<AuthSession*> _session; not_null<AuthSession*> _session;
Storage::DatabasePointer _cache; Storage::DatabasePointer _cache;
@ -602,25 +692,37 @@ private:
Stickers::Order _archivedStickerSetsOrder; Stickers::Order _archivedStickerSetsOrder;
Stickers::SavedGifs _savedGifs; Stickers::SavedGifs _savedGifs;
int _unreadFull = 0;
int _unreadMuted = 0;
int _unreadEntriesFull = 0;
int _unreadEntriesMuted = 0;
base::Timer _selfDestructTimer;
std::vector<FullMsgId> _selfDestructItems;
// When typing in this history started.
base::flat_map<not_null<History*>, TimeMs> _sendActions;
BasicAnimation _a_sendActions;
std::unordered_map< std::unordered_map<
PhotoId, PhotoId,
std::unique_ptr<PhotoData>> _photos; std::unique_ptr<PhotoData>> _photos;
std::map< std::unordered_map<
not_null<const PhotoData*>, not_null<const PhotoData*>,
base::flat_set<not_null<HistoryItem*>>> _photoItems; base::flat_set<not_null<HistoryItem*>>> _photoItems;
std::unordered_map< std::unordered_map<
DocumentId, DocumentId,
std::unique_ptr<DocumentData>> _documents; std::unique_ptr<DocumentData>> _documents;
std::map< std::unordered_map<
not_null<const DocumentData*>, not_null<const DocumentData*>,
base::flat_set<not_null<HistoryItem*>>> _documentItems; base::flat_set<not_null<HistoryItem*>>> _documentItems;
std::unordered_map< std::unordered_map<
WebPageId, WebPageId,
std::unique_ptr<WebPageData>> _webpages; std::unique_ptr<WebPageData>> _webpages;
std::map< std::unordered_map<
not_null<const WebPageData*>, not_null<const WebPageData*>,
base::flat_set<not_null<HistoryItem*>>> _webpageItems; base::flat_set<not_null<HistoryItem*>>> _webpageItems;
std::map< std::unordered_map<
not_null<const WebPageData*>, not_null<const WebPageData*>,
base::flat_set<not_null<ViewElement*>>> _webpageViews; base::flat_set<not_null<ViewElement*>>> _webpageViews;
std::unordered_map< std::unordered_map<
@ -632,16 +734,16 @@ private:
std::unordered_map< std::unordered_map<
GameId, GameId,
std::unique_ptr<GameData>> _games; std::unique_ptr<GameData>> _games;
std::map< std::unordered_map<
not_null<const GameData*>, not_null<const GameData*>,
base::flat_set<not_null<ViewElement*>>> _gameViews; base::flat_set<not_null<ViewElement*>>> _gameViews;
std::map< std::unordered_map<
not_null<const PollData*>, not_null<const PollData*>,
base::flat_set<not_null<ViewElement*>>> _pollViews; base::flat_set<not_null<ViewElement*>>> _pollViews;
std::map< std::unordered_map<
UserId, UserId,
base::flat_set<not_null<HistoryItem*>>> _contactItems; base::flat_set<not_null<HistoryItem*>>> _contactItems;
std::map< std::unordered_map<
UserId, UserId,
base::flat_set<not_null<ViewElement*>>> _contactViews; base::flat_set<not_null<ViewElement*>>> _contactViews;
base::flat_map< base::flat_map<
@ -656,7 +758,7 @@ private:
base::flat_map<FeedId, std::unique_ptr<Feed>> _feeds; base::flat_map<FeedId, std::unique_ptr<Feed>> _feeds;
rpl::variable<FeedId> _defaultFeedId = FeedId(); rpl::variable<FeedId> _defaultFeedId = FeedId();
Groups _groups; Groups _groups;
std::map< std::unordered_map<
not_null<const HistoryItem*>, not_null<const HistoryItem*>,
std::vector<not_null<ViewElement*>>> _views; std::vector<not_null<ViewElement*>>> _views;
@ -671,6 +773,9 @@ private:
std::unordered_set<not_null<const PeerData*>> _mutedPeers; std::unordered_set<not_null<const PeerData*>> _mutedPeers;
base::Timer _unmuteByFinishedTimer; base::Timer _unmuteByFinishedTimer;
std::unordered_map<PeerId, std::unique_ptr<PeerData>> _peers;
std::unordered_map<PeerId, std::unique_ptr<History>> _histories;
MessageIdsList _mimeForwardIds; MessageIdsList _mimeForwardIds;
using CredentialsWithGeneration = std::pair< using CredentialsWithGeneration = std::pair<
@ -680,6 +785,10 @@ private:
rpl::event_stream<> _newAuthorizationChecks; rpl::event_stream<> _newAuthorizationChecks;
rpl::event_stream<SendActionAnimationUpdate> _sendActionAnimationUpdate;
std::vector<WallPaper> _wallpapers;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;
}; };

View File

@ -91,10 +91,12 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
subscribe(Auth().data().contactsLoaded(), [this](bool) { refresh(); }); subscribe(Auth().data().contactsLoaded(), [this](bool) { refresh(); });
Auth().data().itemRemoved( Auth().data().itemRemoved(
) | rpl::start_with_next( ) | rpl::start_with_next(
[this](auto item) { itemRemoved(item); }, [this](auto item) { itemRemoved(item); },
lifetime()); lifetime());
Auth().data().itemRepaintRequest( Auth().data().itemRepaintRequest(
) | rpl::start_with_next([=](auto item) { ) | rpl::start_with_next([=](auto item) {
const auto history = item->history(); const auto history = item->history();
@ -107,13 +109,21 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
} }
} }
}, lifetime()); }, lifetime());
subscribe(App::histories().sendActionAnimationUpdated(), [this](const Histories::SendActionAnimationUpdate &update) {
auto updateRect = Dialogs::Layout::RowPainter::sendActionAnimationRect(update.width, update.height, getFullWidth(), update.textUpdated); Auth().data().sendActionAnimationUpdated(
) | rpl::start_with_next([=](
const Data::Session::SendActionAnimationUpdate &update) {
using RowPainter = Dialogs::Layout::RowPainter;
const auto updateRect = RowPainter::sendActionAnimationRect(
update.width,
update.height,
getFullWidth(),
update.textUpdated);
updateDialogRow( updateDialogRow(
Dialogs::RowDescriptor(update.history, FullMsgId()), Dialogs::RowDescriptor(update.history, FullMsgId()),
updateRect, updateRect,
UpdateRowSection::Default | UpdateRowSection::Filtered); UpdateRowSection::Default | UpdateRowSection::Filtered);
}); }, lifetime());
subscribe(Window::Theme::Background(), [=](const Window::Theme::BackgroundUpdate &data) { subscribe(Window::Theme::Background(), [=](const Window::Theme::BackgroundUpdate &data) {
if (data.paletteChanged()) { if (data.paletteChanged()) {
@ -1915,13 +1925,13 @@ bool DialogsInner::searchReceived(
auto unknownUnreadCounts = std::vector<not_null<History*>>(); auto unknownUnreadCounts = std::vector<not_null<History*>>();
TimeId lastDateFound = 0; TimeId lastDateFound = 0;
for_const (auto message, messages) { for (const auto &message : messages) {
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 = App::peerLoaded(peerId)) {
if (lastDate) { if (lastDate) {
const auto item = App::histories().addNewMessage( const auto item = Auth().data().addNewMessage(
message, message,
NewMessageExisting); NewMessageExisting);
const auto history = item->history(); const auto history = item->history();

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_abstract_structure.h" #include "data/data_abstract_structure.h"
#include "data/data_drafts.h" #include "data/data_drafts.h"
#include "data/data_session.h"
#include "dialogs/dialogs_list.h" #include "dialogs/dialogs_list.h"
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
@ -796,7 +797,7 @@ void paintImportantSwitch(Painter &p, Mode current, int fullWidth, bool selected
if (!mutedHidden) { if (!mutedHidden) {
return; return;
} }
if (const auto unread = App::histories().unreadOnlyMutedBadge()) { if (const auto unread = Auth().data().unreadOnlyMutedBadge()) {
const auto unreadRight = fullWidth - st::dialogsPadding.x(); const auto unreadRight = fullWidth - st::dialogsPadding.x();
UnreadBadgeStyle st; UnreadBadgeStyle st;
st.muted = true; st.muted = true;

View File

@ -55,283 +55,14 @@ constexpr auto kSetMyActionForMs = 10000;
constexpr auto kNewBlockEachMessage = 50; constexpr auto kNewBlockEachMessage = 50;
constexpr auto kSkipCloudDraftsFor = TimeId(3); constexpr auto kSkipCloudDraftsFor = TimeId(3);
void checkForSwitchInlineButton(HistoryItem *item) {
if (item->out() || !item->hasSwitchInlineButton()) {
return;
}
if (const auto user = item->history()->peer->asUser()) {
if (!user->botInfo || !user->botInfo->inlineReturnPeerId) {
return;
}
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
for_const (auto &row, markup->rows) {
for_const (auto &button, row) {
if (button.type == HistoryMessageMarkupButton::Type::SwitchInline) {
Notify::switchInlineBotButtonReceived(QString::fromUtf8(button.data));
return;
}
}
}
}
}
}
} // namespace } // namespace
Histories::Histories() History::History(not_null<Data::Session*> owner, const PeerId &peerId)
: _a_typings(animation(this, &Histories::step_typings))
, _selfDestructTimer([this] { checkSelfDestructItems(); }) {
}
History *Histories::find(PeerId peerId) const {
if (const auto i = _map.find(peerId); i != _map.end()) {
return i->second.get();
}
return nullptr;
}
not_null<History*> Histories::findOrInsert(PeerId peerId) {
if (const auto result = find(peerId)) {
return result;
}
const auto [i, ok] = _map.emplace(
peerId,
std::make_unique<History>(peerId));
return i->second.get();
}
void Histories::clear() {
for (const auto &[peerId, history] : _map) {
history->unloadBlocks();
}
App::historyClearMsgs();
_map.clear();
_unreadFull = _unreadMuted = 0;
_unreadEntriesFull = _unreadEntriesMuted = 0;
Notify::unreadCounterUpdated();
App::historyClearItems();
typing.clear();
}
void Histories::registerSendAction(
not_null<History*> history,
not_null<UserData*> user,
const MTPSendMessageAction &action,
TimeId when) {
if (history->updateSendActionNeedsAnimating(user, action)) {
user->madeAction(when);
auto i = typing.find(history);
if (i == typing.cend()) {
typing.insert(history, getms());
_a_typings.start();
}
}
}
void Histories::step_typings(TimeMs ms, bool timer) {
for (auto i = typing.begin(), e = typing.end(); i != e;) {
if (i.key()->updateSendActionNeedsAnimating(ms)) {
++i;
} else {
i = typing.erase(i);
}
}
if (typing.isEmpty()) {
_a_typings.stop();
}
}
void Histories::remove(const PeerId &peer) {
const auto i = _map.find(peer);
if (i != _map.cend()) {
typing.remove(i->second.get());
_map.erase(i);
}
}
HistoryItem *Histories::addNewMessage(
const MTPMessage &msg,
NewMessageType type) {
auto peer = PeerFromMessage(msg);
if (!peer) return nullptr;
auto result = App::history(peer)->addNewMessage(msg, type);
if (result && type == NewMessageUnread) {
checkForSwitchInlineButton(result);
}
return result;
}
int Histories::unreadBadge() const {
return computeUnreadBadge(
_unreadFull,
_unreadMuted,
_unreadEntriesFull,
_unreadEntriesMuted);
}
bool Histories::unreadBadgeMuted() const {
return computeUnreadBadgeMuted(
_unreadFull,
_unreadMuted,
_unreadEntriesFull,
_unreadEntriesMuted);
}
int Histories::unreadBadgeIgnoreOne(History *history) const {
const auto removeCount = (history
&& history->inChatList(Dialogs::Mode::All))
? history->unreadCount()
: 0;
if (!removeCount) {
return unreadBadge();
}
const auto removeMuted = history->mute();
return computeUnreadBadge(
_unreadFull - removeCount,
_unreadMuted - (removeMuted ? removeCount : 0),
_unreadEntriesFull - 1,
_unreadEntriesMuted - (removeMuted ? 1 : 0));
}
bool Histories::unreadBadgeMutedIgnoreOne(History *history) const {
const auto removeCount = (history
&& history->inChatList(Dialogs::Mode::All))
? history->unreadCount()
: 0;
if (!removeCount) {
return unreadBadgeMuted();
}
const auto removeMuted = history->mute();
return computeUnreadBadgeMuted(
_unreadFull - removeCount,
_unreadMuted - (removeMuted ? removeCount : 0),
_unreadEntriesFull - 1,
_unreadEntriesMuted - (removeMuted ? 1 : 0));
}
int Histories::unreadOnlyMutedBadge() const {
return Auth().settings().countUnreadMessages()
? _unreadMuted
: _unreadEntriesMuted;
}
int Histories::computeUnreadBadge(
int full,
int muted,
int entriesFull,
int entriesMuted) const {
const auto withMuted = Auth().settings().includeMutedCounter();
return Auth().settings().countUnreadMessages()
? (full - (withMuted ? 0 : muted))
: (entriesFull - (withMuted ? 0 : entriesMuted));
}
bool Histories::computeUnreadBadgeMuted(
int full,
int muted,
int entriesFull,
int entriesMuted) const {
if (!Auth().settings().includeMutedCounter()) {
return false;
}
return Auth().settings().countUnreadMessages()
? (muted >= full)
: (entriesMuted >= entriesFull);
}
void Histories::unreadIncrement(int count, bool muted) {
if (!count) {
return;
}
_unreadFull += count;
if (muted) {
_unreadMuted += count;
}
if (Auth().settings().countUnreadMessages()) {
if (!muted || Auth().settings().includeMutedCounter()) {
Notify::unreadCounterUpdated();
}
}
}
void Histories::unreadMuteChanged(int count, bool muted) {
const auto wasAll = (_unreadMuted == _unreadFull);
if (muted) {
_unreadMuted += count;
} else {
_unreadMuted -= count;
}
if (Auth().settings().countUnreadMessages()) {
const auto nowAll = (_unreadMuted == _unreadFull);
const auto changed = !Auth().settings().includeMutedCounter()
|| (wasAll != nowAll);
if (changed) {
Notify::unreadCounterUpdated();
}
}
}
void Histories::unreadEntriesChanged(
int withUnreadDelta,
int mutedWithUnreadDelta) {
if (!withUnreadDelta && !mutedWithUnreadDelta) {
return;
}
const auto wasAll = (_unreadEntriesMuted == _unreadEntriesFull);
_unreadEntriesFull += withUnreadDelta;
_unreadEntriesMuted += mutedWithUnreadDelta;
if (!Auth().settings().countUnreadMessages()) {
const auto nowAll = (_unreadEntriesMuted == _unreadEntriesFull);
const auto withMuted = Auth().settings().includeMutedCounter();
const auto withMutedChanged = withMuted
&& (withUnreadDelta != 0 || wasAll != nowAll);
const auto withoutMutedChanged = !withMuted
&& (withUnreadDelta != mutedWithUnreadDelta);
if (withMutedChanged || withoutMutedChanged) {
Notify::unreadCounterUpdated();
}
}
}
void Histories::selfDestructIn(not_null<HistoryItem*> item, TimeMs delay) {
_selfDestructItems.push_back(item->fullId());
if (!_selfDestructTimer.isActive() || _selfDestructTimer.remainingTime() > delay) {
_selfDestructTimer.callOnce(delay);
}
}
void Histories::checkSelfDestructItems() {
auto now = getms(true);
auto nextDestructIn = TimeMs(0);
for (auto i = _selfDestructItems.begin(); i != _selfDestructItems.cend();) {
if (auto item = App::histItemById(*i)) {
if (auto destructIn = item->getSelfDestructIn(now)) {
if (nextDestructIn > 0) {
accumulate_min(nextDestructIn, destructIn);
} else {
nextDestructIn = destructIn;
}
++i;
} else {
i = _selfDestructItems.erase(i);
}
} else {
i = _selfDestructItems.erase(i);
}
}
if (nextDestructIn > 0) {
_selfDestructTimer.callOnce(nextDestructIn);
}
}
History::History(const PeerId &peerId)
: Entry(this) : Entry(this)
, peer(App::peer(peerId)) , peer(App::peer(peerId))
, cloudDraftTextCache(st::dialogsTextWidthMin) , cloudDraftTextCache(st::dialogsTextWidthMin)
, _mute(Auth().data().notifyIsMuted(peer)) , _owner(owner)
, _mute(_owner->notifyIsMuted(peer))
, _sendActionText(st::dialogsTextWidthMin) { , _sendActionText(st::dialogsTextWidthMin) {
if (const auto user = peer->asUser()) { if (const auto user = peer->asUser()) {
if (user->botInfo) { if (user->botInfo) {
@ -444,13 +175,15 @@ void History::takeLocalDraft(History *from) {
_localDraft->msgId = 0; _localDraft->msgId = 0;
} }
from->clearLocalDraft(); from->clearLocalDraft();
Auth().api().saveDraftToCloudDelayed(from); session().api().saveDraftToCloudDelayed(from);
} }
} }
void History::createLocalDraftFromCloud() { void History::createLocalDraftFromCloud() {
auto draft = cloudDraft(); auto draft = cloudDraft();
if (Data::draftIsNull(draft) || !draft->date || Auth().supportMode()) { if (Data::draftIsNull(draft)
|| !draft->date
|| session().supportMode()) {
return; return;
} }
@ -561,9 +294,9 @@ void History::draftSavedToCloud() {
} }
HistoryItemsList History::validateForwardDraft() { HistoryItemsList History::validateForwardDraft() {
auto result = Auth().data().idsToItems(_forwardDraft); auto result = _owner->idsToItems(_forwardDraft);
if (result.size() != _forwardDraft.size()) { if (result.size() != _forwardDraft.size()) {
setForwardDraft(Auth().data().itemsToIds(result)); setForwardDraft(_owner->itemsToIds(result));
} }
return result; return result;
} }
@ -740,7 +473,7 @@ bool History::updateSendActionNeedsAnimating(TimeMs ms, bool force) {
} }
auto result = (!_typing.isEmpty() || !_sendActions.isEmpty()); auto result = (!_typing.isEmpty() || !_sendActions.isEmpty());
if (changed || (result && !anim::Disabled())) { if (changed || (result && !anim::Disabled())) {
App::histories().sendActionAnimationUpdated().notify({ _owner->updateSendActionAnimation({
this, this,
_sendActionAnimation.width(), _sendActionAnimation.width(),
st::normalFont->height, st::normalFont->height,
@ -1057,7 +790,7 @@ not_null<HistoryItem*> History::addNewItem(
if (const auto sharedMediaTypes = item->sharedMediaTypes()) { if (const auto sharedMediaTypes = item->sharedMediaTypes()) {
auto from = loadedAtTop() ? 0 : minMsgId(); auto from = loadedAtTop() ? 0 : minMsgId();
auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId(); auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId();
Auth().storage().add(Storage::SharedMediaAddExisting( session().storage().add(Storage::SharedMediaAddExisting(
peer->id, peer->id,
sharedMediaTypes, sharedMediaTypes,
item->id, item->id,
@ -1102,7 +835,7 @@ not_null<HistoryItem*> History::addNewItem(
} }
if (auto megagroup = peer->asMegagroup()) { if (auto megagroup = peer->asMegagroup()) {
Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged);
Auth().data().addNewMegagroupParticipant(megagroup, user); _owner->addNewMegagroupParticipant(megagroup, user);
} }
} }
} }
@ -1162,7 +895,7 @@ not_null<HistoryItem*> History::addNewItem(
newItemAdded(item); newItemAdded(item);
} }
Auth().data().notifyHistoryChangeDelayed(this); _owner->notifyHistoryChangeDelayed(this);
return item; return item;
} }
@ -1191,7 +924,7 @@ void History::applyServiceChanges(
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);
Auth().data().addNewMegagroupParticipant(megagroup, user); _owner->addNewMegagroupParticipant(megagroup, user);
} }
if (user->botInfo) { if (user->botInfo) {
peer->asChannel()->mgInfo->bots.insert(user); peer->asChannel()->mgInfo->bots.insert(user);
@ -1213,7 +946,7 @@ void History::applyServiceChanges(
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);
Auth().data().addNewMegagroupParticipant(megagroup, user); _owner->addNewMegagroupParticipant(megagroup, user);
} }
if (user->botInfo) { if (user->botInfo) {
mgInfo->bots.insert(user); mgInfo->bots.insert(user);
@ -1249,7 +982,7 @@ void History::applyServiceChanges(
mgInfo->lastParticipants.erase(i); mgInfo->lastParticipants.erase(i);
Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged);
} }
Auth().data().removeMegagroupParticipant(megagroup, user); _owner->removeMegagroupParticipant(megagroup, user);
if (megagroup->membersCount() > 1) { if (megagroup->membersCount() > 1) {
megagroup->setMembersCount(megagroup->membersCount() - 1); megagroup->setMembersCount(megagroup->membersCount() - 1);
} else { } else {
@ -1277,7 +1010,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 = Auth().data().photo(d.vphoto.c_photo()); auto photo = _owner->photo(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();
@ -1446,7 +1179,7 @@ void History::addEdgesToSharedMedia() {
auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId(); auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId();
for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) { for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) {
const auto type = static_cast<Storage::SharedMediaType>(i); const auto type = static_cast<Storage::SharedMediaType>(i);
Auth().storage().add(Storage::SharedMediaAddSlice( session().storage().add(Storage::SharedMediaAddSlice(
peer->id, peer->id,
type, type,
{}, {},
@ -1634,7 +1367,7 @@ void History::addToSharedMedia(
for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) { for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) {
if (!medias[i].empty()) { if (!medias[i].empty()) {
const auto type = static_cast<Storage::SharedMediaType>(i); const auto type = static_cast<Storage::SharedMediaType>(i);
Auth().storage().add(Storage::SharedMediaAddSlice( session().storage().add(Storage::SharedMediaAddSlice(
peer->id, peer->id,
type, type,
std::move(medias[i]), std::move(medias[i]),
@ -1711,7 +1444,7 @@ void History::inboxRead(MsgId upTo) {
} }
_firstUnreadView = nullptr; _firstUnreadView = nullptr;
Auth().notifications().clearFromHistory(this); session().notifications().clearFromHistory(this);
} }
void History::inboxRead(not_null<const HistoryItem*> wasRead) { void History::inboxRead(not_null<const HistoryItem*> wasRead) {
@ -1812,7 +1545,7 @@ void History::setUnreadCount(int newUnreadCount) {
const auto delta = unreadMarkDelta + (unreadCountDelta const auto delta = unreadMarkDelta + (unreadCountDelta
? *unreadCountDelta ? *unreadCountDelta
: newUnreadCount); : newUnreadCount);
App::histories().unreadIncrement(delta, mute()); _owner->unreadIncrement(delta, mute());
const auto nowUnread = (*_unreadCount > 0) || _unreadMark; const auto nowUnread = (*_unreadCount > 0) || _unreadMark;
const auto entriesDelta = (wasUnread && !nowUnread) const auto entriesDelta = (wasUnread && !nowUnread)
@ -1820,7 +1553,7 @@ void History::setUnreadCount(int newUnreadCount) {
: (nowUnread && !wasUnread) : (nowUnread && !wasUnread)
? 1 ? 1
: 0; : 0;
App::histories().unreadEntriesChanged( _owner->unreadEntriesChanged(
entriesDelta, entriesDelta,
mute() ? entriesDelta : 0); mute() ? entriesDelta : 0);
} }
@ -1839,8 +1572,8 @@ void History::setUnreadMark(bool unread) {
if (!_unreadCount || !*_unreadCount) { if (!_unreadCount || !*_unreadCount) {
if (inChatList(Dialogs::Mode::All)) { if (inChatList(Dialogs::Mode::All)) {
const auto delta = _unreadMark ? 1 : -1; const auto delta = _unreadMark ? 1 : -1;
App::histories().unreadIncrement(delta, mute()); _owner->unreadIncrement(delta, mute());
App::histories().unreadEntriesChanged( _owner->unreadEntriesChanged(
delta, delta,
mute() ? delta : 0); mute() ? delta : 0);
@ -1890,17 +1623,17 @@ bool History::changeMute(bool newMute) {
feed->unreadCountChanged(unreadCountDelta, mutedCountDelta); feed->unreadCountChanged(unreadCountDelta, mutedCountDelta);
} }
} else { } else {
Auth().api().requestDialogEntry(this); session().api().requestDialogEntry(this);
Auth().api().requestDialogEntry(feed); session().api().requestDialogEntry(feed);
} }
} }
if (inChatList(Dialogs::Mode::All)) { if (inChatList(Dialogs::Mode::All)) {
if (const auto count = historiesUnreadCount()) { if (const auto count = historiesUnreadCount()) {
App::histories().unreadMuteChanged(count, _mute); _owner->unreadMuteChanged(count, _mute);
const auto entriesWithUnreadDelta = 0; const auto entriesWithUnreadDelta = 0;
const auto mutedEntriesWithUnreadDelta = _mute ? 1 : -1; const auto mutedEntriesWithUnreadDelta = _mute ? 1 : -1;
App::histories().unreadEntriesChanged( _owner->unreadEntriesChanged(
entriesWithUnreadDelta, entriesWithUnreadDelta,
mutedEntriesWithUnreadDelta); mutedEntriesWithUnreadDelta);
@ -1960,7 +1693,7 @@ std::shared_ptr<AdminLog::LocalIdManager> History::adminLogIdManager() {
TimeId History::adjustChatListTimeId() const { TimeId History::adjustChatListTimeId() const {
const auto result = chatsListTimeId(); const auto result = chatsListTimeId();
if (const auto draft = cloudDraft()) { if (const auto draft = cloudDraft()) {
if (!Data::draftIsNull(draft) && !Auth().supportMode()) { if (!Data::draftIsNull(draft) && !session().supportMode()) {
return std::max(result, draft->date); return std::max(result, draft->date);
} }
} }
@ -2279,11 +2012,11 @@ void History::getReadyFor(MsgId msgId) {
void History::setNotLoadedAtBottom() { void History::setNotLoadedAtBottom() {
_loadedAtBottom = false; _loadedAtBottom = false;
Auth().storage().invalidate( session().storage().invalidate(
Storage::SharedMediaInvalidateBottom(peer->id)); Storage::SharedMediaInvalidateBottom(peer->id));
if (const auto channel = peer->asChannel()) { if (const auto channel = peer->asChannel()) {
if (const auto feed = channel->feed()) { if (const auto feed = channel->feed()) {
Auth().storage().invalidate( session().storage().invalidate(
Storage::FeedMessagesInvalidateBottom( Storage::FeedMessagesInvalidateBottom(
feed->id())); feed->id()));
} }
@ -2293,12 +2026,14 @@ void History::setNotLoadedAtBottom() {
void History::markFullyLoaded() { void History::markFullyLoaded() {
_loadedAtTop = _loadedAtBottom = true; _loadedAtTop = _loadedAtBottom = true;
if (isEmpty()) { if (isEmpty()) {
Auth().storage().remove(Storage::SharedMediaRemoveAll(peer->id)); session().storage().remove(
Storage::SharedMediaRemoveAll(peer->id));
if (const auto channel = peer->asChannel()) { if (const auto channel = peer->asChannel()) {
if (const auto feed = channel->feed()) { if (const auto feed = channel->feed()) {
Auth().storage().remove(Storage::FeedMessagesRemoveAll( session().storage().remove(
feed->id(), Storage::FeedMessagesRemoveAll(
channel->bareId())); feed->id(),
channel->bareId()));
} }
} }
} }
@ -2339,7 +2074,7 @@ void History::updateChatListExistence() {
if (const auto channel = peer->asChannel()) { if (const auto channel = peer->asChannel()) {
if (!channel->feed()) { if (!channel->feed()) {
// After ungrouping from a feed we need to load dialog. // After ungrouping from a feed we need to load dialog.
Auth().api().requestDialogEntry(this); session().api().requestDialogEntry(this);
} }
} }
} }
@ -2405,12 +2140,12 @@ void History::applyDialog(const MTPDdialog &data) {
data.vtop_message.v); data.vtop_message.v);
if (const auto item = App::histItemById(topMessageId)) { if (const auto item = App::histItemById(topMessageId)) {
if (item->date() <= channel->date) { if (item->date() <= channel->date) {
Auth().api().requestSelfParticipant(channel); session().api().requestSelfParticipant(channel);
} }
} }
} }
} }
Auth().data().applyNotifySetting( _owner->applyNotifySetting(
MTP_notifyPeer(data.vpeer), MTP_notifyPeer(data.vpeer),
data.vnotify_settings); data.vnotify_settings);
@ -2420,7 +2155,7 @@ void History::applyDialog(const MTPDdialog &data) {
} }
bool History::clearUnreadOnClientSide() const { bool History::clearUnreadOnClientSide() const {
if (!Auth().supportMode()) { if (!session().supportMode()) {
return false; return false;
} }
if (const auto user = peer->asUser()) { if (const auto user = peer->asUser()) {
@ -2570,6 +2305,14 @@ void History::resizeToWidth(int newWidth) {
_height = y; _height = y;
} }
Data::Session &History::owner() const {
return *_owner;
}
AuthSession &History::session() const {
return _owner->session();
}
ChannelId History::channelId() const { ChannelId History::channelId() const {
return peerToChannel(peer->id); return peerToChannel(peer->id);
} }
@ -2645,7 +2388,7 @@ HistoryService *History::insertJoinedMessage(bool unread) {
} }
MTPDmessage::Flags flags = 0; MTPDmessage::Flags flags = 0;
if (inviter->id == Auth().userPeerId()) { if (inviter->id == session().userPeerId()) {
unread = false; unread = false;
//} else if (unread) { //} else if (unread) {
// flags |= MTPDmessage::Flag::f_unread; // flags |= MTPDmessage::Flag::f_unread;
@ -2811,11 +2554,11 @@ void History::clearBlocks(bool leaveItems) {
forgetScrollState(); forgetScrollState();
} }
if (leaveItems) { if (leaveItems) {
Auth().data().notifyHistoryUnloaded(this); _owner->notifyHistoryUnloaded(this);
} else { } else {
setLastMessage(nullptr); setLastMessage(nullptr);
notifies.clear(); notifies.clear();
Auth().data().notifyHistoryCleared(this); _owner->notifyHistoryCleared(this);
} }
blocks.clear(); blocks.clear();
if (leaveItems) { if (leaveItems) {
@ -2831,7 +2574,7 @@ void History::clearBlocks(bool leaveItems) {
} }
clearLastKeyboard(); clearLastKeyboard();
} }
Auth().data().notifyHistoryChangeDelayed(this); _owner->notifyHistoryChangeDelayed(this);
_loadedAtTop = false; _loadedAtTop = false;
_loadedAtBottom = !leaveItems; _loadedAtBottom = !leaveItems;
@ -2872,9 +2615,9 @@ void History::clearUpTill(MsgId availableMinId) {
} while (!isEmpty()); } while (!isEmpty());
if (!lastMessageKnown()) { if (!lastMessageKnown()) {
Auth().api().requestDialogEntry(this); session().api().requestDialogEntry(this);
} }
Auth().data().sendHistoryChangeNotifications(); _owner->sendHistoryChangeNotifications();
} }
void History::applyGroupAdminChanges( void History::applyGroupAdminChanges(
@ -2889,10 +2632,10 @@ void History::applyGroupAdminChanges(
void History::changedInChatListHook(Dialogs::Mode list, bool added) { void History::changedInChatListHook(Dialogs::Mode list, bool added) {
if (list == Dialogs::Mode::All) { if (list == Dialogs::Mode::All) {
if (const auto delta = historiesUnreadCount() * (added ? 1 : -1)) { if (const auto delta = historiesUnreadCount() * (added ? 1 : -1)) {
App::histories().unreadIncrement(delta, mute()); _owner->unreadIncrement(delta, mute());
const auto entriesDelta = added ? 1 : -1; const auto entriesDelta = added ? 1 : -1;
App::histories().unreadEntriesChanged( _owner->unreadEntriesChanged(
entriesDelta, entriesDelta,
mute() ? entriesDelta : 0); mute() ? entriesDelta : 0);
} }

View File

@ -27,6 +27,7 @@ class AuthSession;
namespace Data { namespace Data {
struct Draft; struct Draft;
class Session;
} // namespace Data } // namespace Data
namespace Dialogs { namespace Dialogs {
@ -48,92 +49,22 @@ enum NewMessageType : char {
NewMessageExisting, NewMessageExisting,
}; };
class Histories {
public:
Histories();
void registerSendAction(
not_null<History*> history,
not_null<UserData*> user,
const MTPSendMessageAction &action,
TimeId when);
void step_typings(TimeMs ms, bool timer);
History *find(PeerId peerId) const;
not_null<History*> findOrInsert(PeerId peerId);
void clear();
void remove(const PeerId &peer);
HistoryItem *addNewMessage(const MTPMessage &msg, NewMessageType type);
// When typing in this history started.
typedef QMap<History*, TimeMs> TypingHistories;
TypingHistories typing;
BasicAnimation _a_typings;
int unreadBadge() const;
bool unreadBadgeMuted() const;
int unreadBadgeIgnoreOne(History *history) const;
bool unreadBadgeMutedIgnoreOne(History *history) const;
int unreadOnlyMutedBadge() const;
void unreadIncrement(int count, bool muted);
void unreadMuteChanged(int count, bool muted);
void unreadEntriesChanged(
int withUnreadDelta,
int mutedWithUnreadDelta);
struct SendActionAnimationUpdate {
History *history;
int width;
int height;
bool textUpdated;
};
base::Observable<SendActionAnimationUpdate> &sendActionAnimationUpdated() {
return _sendActionAnimationUpdated;
}
void selfDestructIn(not_null<HistoryItem*> item, TimeMs delay);
private:
void checkSelfDestructItems();
int computeUnreadBadge(
int full,
int muted,
int entriesFull,
int entriesMuted) const;
bool computeUnreadBadgeMuted(
int full,
int muted,
int entriesFull,
int entriesMuted) const;
std::unordered_map<PeerId, std::unique_ptr<History>> _map;
int _unreadFull = 0;
int _unreadMuted = 0;
int _unreadEntriesFull = 0;
int _unreadEntriesMuted = 0;
base::Observable<SendActionAnimationUpdate> _sendActionAnimationUpdated;
base::Timer _selfDestructTimer;
std::vector<FullMsgId> _selfDestructItems;
};
enum class UnreadMentionType { enum class UnreadMentionType {
New, // when new message is added to history New, // when new message is added to history
Existing, // when some messages slice was received Existing, // when some messages slice was received
}; };
class History : public Dialogs::Entry { class History final : public Dialogs::Entry {
public: public:
using Element = HistoryView::Element; using Element = HistoryView::Element;
History(const PeerId &peerId); History(not_null<Data::Session*> owner, const PeerId &peerId);
History(const History &) = delete; History(const History &) = delete;
History &operator=(const History &) = delete; History &operator=(const History &) = delete;
Data::Session &owner() const;
AuthSession &session() const;
ChannelId channelId() const; ChannelId channelId() const;
bool isChannel() const; bool isChannel() const;
bool isMegagroup() const; bool isMegagroup() const;
@ -501,6 +432,7 @@ private:
void viewReplaced(not_null<const Element*> was, Element *now); void viewReplaced(not_null<const Element*> was, Element *now);
not_null<Data::Session*> _owner;
Flags _flags = 0; Flags _flags = 0;
bool _mute = false; bool _mute = false;
int _width = 0; int _width = 0;

View File

@ -172,12 +172,12 @@ TimeId HistoryItem::date() const {
} }
void HistoryItem::finishEdition(int oldKeyboardTop) { void HistoryItem::finishEdition(int oldKeyboardTop) {
Auth().data().requestItemViewRefresh(this); _history->owner().requestItemViewRefresh(this);
invalidateChatsListEntry(); invalidateChatsListEntry();
if (const auto group = Auth().data().groups().find(this)) { if (const auto group = _history->owner().groups().find(this)) {
const auto leader = group->items.back(); const auto leader = group->items.back();
if (leader != this) { if (leader != this) {
Auth().data().requestItemViewRefresh(leader); _history->owner().requestItemViewRefresh(leader);
leader->invalidateChatsListEntry(); leader->invalidateChatsListEntry();
} }
} }
@ -195,7 +195,7 @@ void HistoryItem::setGroupId(MessageGroupId groupId) {
Expects(!_groupId); Expects(!_groupId);
_groupId = groupId; _groupId = groupId;
Auth().data().groups().registerMessage(this); _history->owner().groups().registerMessage(this);
} }
HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() { HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() {
@ -305,7 +305,7 @@ void HistoryItem::addLogEntryOriginal(
Expects(isLogEntry()); Expects(isLogEntry());
AddComponents(HistoryMessageLogEntryOriginal::Bit()); AddComponents(HistoryMessageLogEntryOriginal::Bit());
Get<HistoryMessageLogEntryOriginal>()->page = Auth().data().webpage( Get<HistoryMessageLogEntryOriginal>()->page = _history->owner().webpage(
localId, localId,
label, label,
content); content);
@ -330,7 +330,6 @@ UserData *HistoryItem::getMessageBot() const {
}; };
void HistoryItem::destroy() { void HistoryItem::destroy() {
const auto history = this->history();
if (isLogEntry()) { if (isLogEntry()) {
Assert(!mainView()); Assert(!mainView());
} else { } else {
@ -338,13 +337,13 @@ void HistoryItem::destroy() {
eraseFromUnreadMentions(); eraseFromUnreadMentions();
if (IsServerMsgId(id)) { if (IsServerMsgId(id)) {
if (const auto types = sharedMediaTypes()) { if (const auto types = sharedMediaTypes()) {
Auth().storage().remove(Storage::SharedMediaRemoveOne( _history->session().storage().remove(Storage::SharedMediaRemoveOne(
history->peer->id, _history->peer->id,
types, types,
id)); id));
} }
} else { } else {
Auth().api().cancelLocalItem(this); _history->session().api().cancelLocalItem(this);
} }
_history->itemRemoved(this); _history->itemRemoved(this);
} }
@ -353,14 +352,14 @@ void HistoryItem::destroy() {
void HistoryItem::refreshMainView() { void HistoryItem::refreshMainView() {
if (const auto view = mainView()) { if (const auto view = mainView()) {
Auth().data().notifyHistoryChangeDelayed(_history); _history->owner().notifyHistoryChangeDelayed(_history);
view->refreshInBlock(); view->refreshInBlock();
} }
} }
void HistoryItem::removeMainView() { void HistoryItem::removeMainView() {
if (const auto view = mainView()) { if (const auto view = mainView()) {
Auth().data().notifyHistoryChangeDelayed(_history); _history->owner().notifyHistoryChangeDelayed(_history);
view->removeFromBlock(); view->removeFromBlock();
} }
} }
@ -378,14 +377,14 @@ void HistoryItem::indexAsNewItem() {
addToUnreadMentions(UnreadMentionType::New); addToUnreadMentions(UnreadMentionType::New);
CrashReports::ClearAnnotation("addToUnreadMentions"); CrashReports::ClearAnnotation("addToUnreadMentions");
if (const auto types = sharedMediaTypes()) { if (const auto types = sharedMediaTypes()) {
Auth().storage().add(Storage::SharedMediaAddNew( _history->session().storage().add(Storage::SharedMediaAddNew(
history()->peer->id, history()->peer->id,
types, types,
id)); id));
} }
if (const auto channel = history()->peer->asChannel()) { if (const auto channel = history()->peer->asChannel()) {
if (const auto feed = channel->feed()) { if (const auto feed = channel->feed()) {
Auth().storage().add(Storage::FeedMessagesAddNew( _history->session().storage().add(Storage::FeedMessagesAddNew(
feed->id(), feed->id(),
position())); position()));
} }
@ -409,8 +408,8 @@ void HistoryItem::setRealId(MsgId newId) {
} }
} }
Auth().data().notifyItemIdChange({ this, oldId }); _history->owner().notifyItemIdChange({ this, oldId });
Auth().data().requestItemRepaint(this); _history->owner().requestItemRepaint(this);
} }
bool HistoryItem::isPinned() const { bool HistoryItem::isPinned() const {
@ -749,10 +748,10 @@ void HistoryItem::drawInDialog(
} }
HistoryItem::~HistoryItem() { HistoryItem::~HistoryItem() {
Auth().data().notifyItemRemoved(this); _history->owner().notifyItemRemoved(this);
App::historyUnregItem(this); App::historyUnregItem(this);
if (id < 0 && !App::quitting()) { if (id < 0 && !App::quitting()) {
Auth().uploader().cancel(fullId()); _history->session().uploader().cancel(fullId());
} }
} }

View File

@ -11,12 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/media/history_media_document.h" #include "history/media/history_media_document.h"
#include "media/media_audio.h" #include "media/media_audio.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
#include "auth_session.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
@ -165,7 +165,7 @@ bool HistoryMessageReply::updateData(
replyToMsgId = 0; replyToMsgId = 0;
} }
if (force) { if (force) {
Auth().data().requestItemResize(holder); holder->history()->owner().requestItemResize(holder);
} }
return (replyToMsg || !replyToMsgId); return (replyToMsg || !replyToMsgId);
} }
@ -228,7 +228,7 @@ void HistoryMessageReply::itemRemoved(
HistoryItem *removed) { HistoryItem *removed) {
if (replyToMsg == removed) { if (replyToMsg == removed) {
clearData(holder); clearData(holder);
Auth().data().requestItemResize(holder); holder->history()->owner().requestItemResize(holder);
} }
} }

View File

@ -90,10 +90,11 @@ void FastShareMessage(not_null<HistoryItem*> item) {
MessageIdsList msgIds; MessageIdsList msgIds;
base::flat_set<mtpRequestId> requests; base::flat_set<mtpRequestId> requests;
}; };
const auto history = item->history();
const auto data = std::make_shared<ShareData>( const auto data = std::make_shared<ShareData>(
item->history()->peer, history->peer,
Auth().data().itemOrItsGroup(item)); history->owner().itemOrItsGroup(item));
const auto isGroup = (Auth().data().groups().find(item) != nullptr); const auto isGroup = (history->owner().groups().find(item) != nullptr);
const auto isGame = item->getMessageBot() const auto isGame = item->getMessageBot()
&& item->media() && item->media()
&& (item->media()->game() != nullptr); && (item->media()->game() != nullptr);
@ -127,7 +128,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
if (!data->requests.empty()) { if (!data->requests.empty()) {
return; // Share clicked already. return; // Share clicked already.
} }
auto items = Auth().data().idsToItems(data->msgIds); auto items = history->owner().idsToItems(data->msgIds);
if (items.empty() || result.empty()) { if (items.empty() || result.empty()) {
return; return;
} }
@ -153,8 +154,8 @@ void FastShareMessage(not_null<HistoryItem*> item) {
return; return;
} }
auto doneCallback = [data](const MTPUpdates &updates, mtpRequestId requestId) { auto doneCallback = [=](const MTPUpdates &updates, mtpRequestId requestId) {
Auth().api().applyUpdates(updates); history->session().api().applyUpdates(updates);
data->requests.remove(requestId); data->requests.remove(requestId);
if (data->requests.empty()) { if (data->requests.empty()) {
Ui::Toast::Show(lang(lng_share_done)); Ui::Toast::Show(lang(lng_share_done));
@ -189,7 +190,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
auto message = ApiWrap::MessageToSend(history); auto message = ApiWrap::MessageToSend(history);
message.textWithTags = comment; message.textWithTags = comment;
message.clearDraft = false; message.clearDraft = false;
Auth().api().sendMessage(std::move(message)); history->session().api().sendMessage(std::move(message));
} }
auto request = MTPmessages_ForwardMessages( auto request = MTPmessages_ForwardMessages(
MTP_flags(sendFlags), MTP_flags(sendFlags),
@ -577,7 +578,7 @@ void HistoryMessage::applyGroupAdminChanges(
} else { } else {
_flags &= ~MTPDmessage_ClientFlag::f_has_admin_badge; _flags &= ~MTPDmessage_ClientFlag::f_has_admin_badge;
} }
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
} }
} }
@ -653,7 +654,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
reply->replyToMsgId = config.replyTo; reply->replyToMsgId = config.replyTo;
if (!reply->updateData(this)) { if (!reply->updateData(this)) {
Auth().api().requestMessageData( history()->session().api().requestMessageData(
history()->peer->asChannel(), history()->peer->asChannel(),
reply->replyToMsgId, reply->replyToMsgId,
HistoryDependentItemCallback(fullId())); HistoryDependentItemCallback(fullId()));
@ -719,12 +720,12 @@ void HistoryMessage::refreshMedia(const MTPMessageMedia *media) {
} }
void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) { void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) {
const auto wasGrouped = Auth().data().groups().isGrouped(this); const auto wasGrouped = history()->owner().groups().isGrouped(this);
refreshMedia(media); refreshMedia(media);
if (wasGrouped) { if (wasGrouped) {
Auth().data().groups().refreshMessage(this); history()->owner().groups().refreshMessage(this);
} else { } else {
Auth().data().requestItemViewRefresh(this); history()->owner().requestItemViewRefresh(this);
} }
} }
@ -789,7 +790,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,
Auth().data().photo(photo)); item->history()->owner().photo(photo));
}, [](const MTPDphotoEmpty &) -> Result { }, [](const MTPDphotoEmpty &) -> Result {
return nullptr; return nullptr;
}); });
@ -809,7 +810,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,
Auth().data().document(document)); item->history()->owner().document(document));
}, [](const MTPDdocumentEmpty &) -> Result { }, [](const MTPDdocumentEmpty &) -> Result {
return nullptr; return nullptr;
}); });
@ -819,11 +820,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,
Auth().data().webpage(webpage)); item->history()->owner().webpage(webpage));
}, [&](const MTPDwebPage &webpage) -> Result { }, [&](const MTPDwebPage &webpage) -> Result {
return std::make_unique<Data::MediaWebPage>( return std::make_unique<Data::MediaWebPage>(
item, item,
Auth().data().webpage(webpage)); item->history()->owner().webpage(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 +834,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,
Auth().data().game(game)); item->history()->owner().game(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,
Auth().data().poll(media)); item->history()->owner().poll(media));
}, [](const MTPDmessageMediaEmpty &) -> Result { }, [](const MTPDmessageMediaEmpty &) -> Result {
return nullptr; return nullptr;
}, [](const MTPDmessageMediaUnsupported &) -> Result { }, [](const MTPDmessageMediaUnsupported &) -> Result {
@ -917,7 +918,7 @@ void HistoryMessage::updateSentMedia(const MTPMessageMedia *media) {
refreshSentMedia(media); refreshSentMedia(media);
} }
} }
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
} }
void HistoryMessage::addToUnreadMentions(UnreadMentionType type) { void HistoryMessage::addToUnreadMentions(UnreadMentionType type) {
@ -995,7 +996,7 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
if (Has<HistoryMessageReplyMarkup>()) { if (Has<HistoryMessageReplyMarkup>()) {
RemoveComponents(HistoryMessageReplyMarkup::Bit()); RemoveComponents(HistoryMessageReplyMarkup::Bit());
} }
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
Notify::replyMarkupUpdated(this); Notify::replyMarkupUpdated(this);
} }
return; return;
@ -1014,7 +1015,7 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
changed = true; changed = true;
} }
if (changed) { if (changed) {
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
Notify::replyMarkupUpdated(this); Notify::replyMarkupUpdated(this);
} }
} else { } else {
@ -1025,7 +1026,7 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
AddComponents(HistoryMessageReplyMarkup::Bit()); AddComponents(HistoryMessageReplyMarkup::Bit());
} }
Get<HistoryMessageReplyMarkup>()->create(*markup); Get<HistoryMessageReplyMarkup>()->create(*markup);
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
Notify::replyMarkupUpdated(this); Notify::replyMarkupUpdated(this);
} }
} }
@ -1065,17 +1066,17 @@ void HistoryMessage::setViewsCount(int32 count) {
? 0 ? 0
: st::msgDateFont->width(views->_viewsText); : st::msgDateFont->width(views->_viewsText);
if (was == views->_viewsWidth) { if (was == views->_viewsWidth) {
Auth().data().requestItemRepaint(this); history()->owner().requestItemRepaint(this);
} else { } else {
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
} }
} }
void HistoryMessage::setRealId(MsgId newId) { void HistoryMessage::setRealId(MsgId newId) {
HistoryItem::setRealId(newId); HistoryItem::setRealId(newId);
Auth().data().groups().refreshMessage(this); history()->owner().groups().refreshMessage(this);
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
if (reply->replyToLink()) { if (reply->replyToLink()) {
reply->setReplyToLinkFrom(this); reply->setReplyToLinkFrom(this);

View File

@ -246,7 +246,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
if (auto channel = history()->peer->asMegagroup()) { if (auto channel = history()->peer->asMegagroup()) {
auto &users = action.c_messageActionChatAddUser().vusers; auto &users = action.c_messageActionChatAddUser().vusers;
for_const (auto &item, users.v) { for_const (auto &item, users.v) {
if (item.v == Auth().userId()) { if (item.v == history()->session().userId()) {
channel->mgInfo->joinedMessageFound = true; channel->mgInfo->joinedMessageFound = true;
break; break;
} }
@ -266,7 +266,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
_media = std::make_unique<Data::MediaPhoto>( _media = std::make_unique<Data::MediaPhoto>(
this, this,
history()->peer, history()->peer,
Auth().data().photo(photo.c_photo())); history()->owner().photo(photo.c_photo()));
} }
} break; } break;
@ -321,7 +321,7 @@ bool HistoryService::updateDependent(bool force) {
updateDependentText(); updateDependentText();
} }
if (force && gotDependencyItem) { if (force && gotDependencyItem) {
Auth().notifications().checkDelayed(); history()->session().notifications().checkDelayed();
} }
return (dependent->msg || !dependent->msgId); return (dependent->msg || !dependent->msgId);
} }
@ -539,10 +539,10 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
} }
void HistoryService::markMediaAsReadHook() { void HistoryService::markMediaAsReadHook() {
if (auto selfdestruct = Get<HistoryServiceSelfDestruct>()) { if (const auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
if (!selfdestruct->destructAt) { if (!selfdestruct->destructAt) {
selfdestruct->destructAt = getms(true) + selfdestruct->timeToLive; selfdestruct->destructAt = getms(true) + selfdestruct->timeToLive;
App::histories().selfDestructIn(this, selfdestruct->timeToLive); history()->owner().selfDestructIn(this, selfdestruct->timeToLive);
} }
} }
} }
@ -626,7 +626,7 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
if (auto dependent = GetDependentData()) { if (auto dependent = GetDependentData()) {
dependent->msgId = message.vreply_to_msg_id.v; dependent->msgId = message.vreply_to_msg_id.v;
if (!updateDependent()) { if (!updateDependent()) {
Auth().api().requestMessageData( history()->session().api().requestMessageData(
history()->peer->asChannel(), history()->peer->asChannel(),
dependent->msgId, dependent->msgId,
HistoryDependentItemCallback(fullId())); HistoryDependentItemCallback(fullId()));
@ -656,7 +656,7 @@ void HistoryService::removeMedia() {
_media.reset(); _media.reset();
_textWidth = -1; _textWidth = -1;
_textHeight = 0; _textHeight = 0;
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
} }
Storage::SharedMediaTypesMask HistoryService::sharedMediaTypes() const { Storage::SharedMediaTypesMask HistoryService::sharedMediaTypes() const {
@ -679,7 +679,7 @@ void HistoryService::updateDependentText() {
} }
setServiceText(text); setServiceText(text);
Auth().data().requestItemResize(this); history()->owner().requestItemResize(this);
if (history()->textCachedFor == this) { if (history()->textCachedFor == this) {
history()->textCachedFor = nullptr; history()->textCachedFor = nullptr;
} }
@ -712,7 +712,7 @@ HistoryService::~HistoryService() {
HistoryService::PreparedText GenerateJoinedText( HistoryService::PreparedText GenerateJoinedText(
not_null<History*> history, not_null<History*> history,
not_null<UserData*> inviter) { not_null<UserData*> inviter) {
if (inviter->id != Auth().userPeerId()) { if (inviter->id != history->session().userPeerId()) {
auto result = HistoryService::PreparedText{}; auto result = HistoryService::PreparedText{};
result.links.push_back(inviter->createOpenLink()); result.links.push_back(inviter->createOpenLink());
result.text = (history->isMegagroup() result.text = (history->isMegagroup()
@ -720,7 +720,7 @@ HistoryService::PreparedText GenerateJoinedText(
: lng_action_add_you)(lt_from, textcmdLink(1, inviter->name)); : lng_action_add_you)(lt_from, textcmdLink(1, inviter->name));
return result; return result;
} else if (history->isMegagroup()) { } else if (history->isMegagroup()) {
auto self = App::user(Auth().userPeerId()); auto self = history->session().user();
auto result = HistoryService::PreparedText{}; auto result = HistoryService::PreparedText{};
result.links.push_back(self->createOpenLink()); result.links.push_back(self->createOpenLink());
result.text = lng_action_user_joined( result.text = lng_action_user_joined(

View File

@ -25,6 +25,10 @@ Storage::SharedMediaTypesMask HistoryMedia::sharedMediaTypes() const {
return {}; return {};
} }
not_null<History*> HistoryMedia::history() const {
return _parent->history();
}
bool HistoryMedia::isDisplayed() const { bool HistoryMedia::isDisplayed() const {
return true; return true;
} }

View File

@ -47,6 +47,8 @@ public:
HistoryMedia(not_null<Element*> parent) : _parent(parent) { HistoryMedia(not_null<Element*> parent) : _parent(parent) {
} }
not_null<History*> history() const;
virtual TextWithEntities selectedText(TextSelection selection) const { virtual TextWithEntities selectedText(TextSelection selection) const {
return TextWithEntities(); return TextWithEntities();
} }

View File

@ -10,10 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "auth_session.h"
#include "boxes/add_contact_box.h" #include "boxes/add_contact_box.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "window/window_controller.h" #include "window/window_controller.h"
@ -67,7 +67,7 @@ HistoryContact::HistoryContact(
, _fname(first) , _fname(first)
, _lname(last) , _lname(last)
, _phone(App::formatPhone(phone)) { , _phone(App::formatPhone(phone)) {
Auth().data().registerContactView(userId, parent); history()->owner().registerContactView(userId, parent);
_name.setText( _name.setText(
st::semiboldTextStyle, st::semiboldTextStyle,
@ -77,14 +77,14 @@ HistoryContact::HistoryContact(
} }
HistoryContact::~HistoryContact() { HistoryContact::~HistoryContact() {
Auth().data().unregisterContactView(_userId, _parent); history()->owner().unregisterContactView(_userId, _parent);
} }
void HistoryContact::updateSharedContactUserId(UserId userId) { void HistoryContact::updateSharedContactUserId(UserId userId) {
if (_userId != userId) { if (_userId != userId) {
Auth().data().unregisterContactView(_userId, _parent); history()->owner().unregisterContactView(_userId, _parent);
_userId = userId; _userId = userId;
Auth().data().registerContactView(_userId, _parent); history()->owner().registerContactView(_userId, _parent);
} }
} }

View File

@ -9,11 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "media/media_audio.h" #include "media/media_audio.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/media/history_media_common.h"
@ -547,7 +547,7 @@ void HistoryDocument::updatePressed(QPoint point) {
nameright = st::msgFilePadding.left(); nameright = st::msgFilePadding.left();
} }
voice->setSeekingCurrent(snap((point.x() - nameleft) / float64(width() - nameleft - nameright), 0., 1.)); voice->setSeekingCurrent(snap((point.x() - nameleft) / float64(width() - nameleft - nameright), 0., 1.));
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} }
} }
@ -695,7 +695,7 @@ void HistoryDocument::step_voiceProgress(float64 ms, bool timer) {
voice->_playback->a_progress.update(qMin(dt, 1.), anim::linear); voice->_playback->a_progress.update(qMin(dt, 1.), anim::linear);
} }
if (timer) { if (timer) {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} }
} }
@ -753,7 +753,7 @@ void HistoryDocument::parentTextUpdated() {
} else { } else {
RemoveComponents(HistoryDocumentCaptioned::Bit()); RemoveComponents(HistoryDocumentCaptioned::Bit());
} }
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
TextWithEntities HistoryDocument::getCaption() const { TextWithEntities HistoryDocument::getCaption() const {

View File

@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "styles/style_history.h" #include "styles/style_history.h"
@ -27,13 +27,13 @@ void HistoryFileMedia::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool
} }
void HistoryFileMedia::thumbAnimationCallback() { void HistoryFileMedia::thumbAnimationCallback() {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
void HistoryFileMedia::clickHandlerPressedChanged( void HistoryFileMedia::clickHandlerPressedChanged(
const ClickHandlerPtr &handler, const ClickHandlerPtr &handler,
bool pressed) { bool pressed) {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
void HistoryFileMedia::setLinks( void HistoryFileMedia::setLinks(
@ -76,7 +76,7 @@ void HistoryFileMedia::step_radial(TimeMs ms, bool timer) {
}; };
if (timer) { if (timer) {
if (!anim::Disabled() || updateRadial()) { if (!anim::Disabled() || updateRadial()) {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} else { } else {
updateRadial(); updateRadial();

View File

@ -9,8 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/media/history_media_common.h"
@ -40,7 +40,7 @@ HistoryGame::HistoryGame(
consumed, consumed,
Ui::ItemTextOptions(parent->data())); Ui::ItemTextOptions(parent->data()));
} }
Auth().data().registerGameView(_data, _parent); history()->owner().registerGameView(_data, _parent);
} }
QSize HistoryGame::countOptimalSize() { QSize HistoryGame::countOptimalSize() {
@ -428,10 +428,10 @@ void HistoryGame::parentTextUpdated() {
} else { } else {
_description = Text(st::msgMinWidth - st::webPageLeft); _description = Text(st::msgMinWidth - st::webPageLeft);
} }
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
} }
HistoryGame::~HistoryGame() { HistoryGame::~HistoryGame() {
Auth().data().unregisterGameView(_data, _parent); history()->owner().unregisterGameView(_data, _parent);
} }

View File

@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "auth_session.h"
#include "media/media_audio.h" #include "media/media_audio.h"
#include "media/media_clip_reader.h" #include "media/media_clip_reader.h"
#include "media/player/media_player_round_controller.h" #include "media/player/media_player_round_controller.h"
@ -18,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "window/window_controller.h" #include "window/window_controller.h"
@ -779,7 +779,7 @@ void HistoryGif::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Text(); : Text();
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const {
@ -836,7 +836,7 @@ void HistoryGif::clipCallback(Media::Clip::Notification notification) {
auto stopped = false; auto stopped = false;
if (reader->autoPausedGif()) { if (reader->autoPausedGif()) {
auto amVisible = false; auto amVisible = false;
Auth().data().queryItemVisibility().notify( history()->owner().queryItemVisibility().notify(
{ _parent->data(), &amVisible }, { _parent->data(), &amVisible },
true); true);
if (!amVisible) { // Stop animation if it is not visible. if (!amVisible) { // Stop animation if it is not visible.
@ -845,13 +845,13 @@ void HistoryGif::clipCallback(Media::Clip::Notification notification) {
} }
} }
if (!stopped) { if (!stopped) {
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
} break; } break;
case NotificationRepaint: { case NotificationRepaint: {
if (!reader->currentDisplayed()) { if (!reader->currentDisplayed()) {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} break; } break;
} }
@ -868,7 +868,7 @@ void HistoryGif::playAnimation(bool autoplay) {
stopAnimation(); stopAnimation();
} else if (_data->loaded(DocumentData::FilePathResolveChecked)) { } else if (_data->loaded(DocumentData::FilePathResolveChecked)) {
if (!cAutoPlayGif()) { if (!cAutoPlayGif()) {
Auth().data().stopAutoplayAnimations(); history()->owner().stopAutoplayAnimations();
} }
setClipReader(Media::Clip::MakeReader( setClipReader(Media::Clip::MakeReader(
_data, _data,
@ -884,18 +884,18 @@ void HistoryGif::playAnimation(bool autoplay) {
void HistoryGif::stopAnimation() { void HistoryGif::stopAnimation() {
if (_gif) { if (_gif) {
clearClipReader(); clearClipReader();
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
_data->unload(); _data->unload();
} }
} }
void HistoryGif::setClipReader(Media::Clip::ReaderPointer gif) { void HistoryGif::setClipReader(Media::Clip::ReaderPointer gif) {
if (_gif) { if (_gif) {
Auth().data().unregisterAutoplayAnimation(_gif.get()); history()->owner().unregisterAutoplayAnimation(_gif.get());
} }
_gif = std::move(gif); _gif = std::move(gif);
if (_gif) { if (_gif) {
Auth().data().registerAutoplayAnimation(_gif.get(), _parent); history()->owner().registerAutoplayAnimation(_gif.get(), _parent);
} }
} }

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
@ -17,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/grouped_layout.h" #include "ui/grouped_layout.h"
#include "ui/text_options.h" #include "ui/text_options.h"
#include "auth_session.h"
#include "layout.h" #include "layout.h"
#include "styles/style_history.h" #include "styles/style_history.h"
@ -408,7 +408,7 @@ void HistoryGroupedMedia::updateNeedBubbleState() {
} }
void HistoryGroupedMedia::parentTextUpdated() { void HistoryGroupedMedia::parentTextUpdated() {
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
bool HistoryGroupedMedia::needsBubble() const { bool HistoryGroupedMedia::needsBubble() const {

View File

@ -8,9 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/media/history_media_photo.h" #include "history/media/history_media_photo.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/media/history_media_common.h"
@ -526,5 +526,5 @@ void HistoryPhoto::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Text(); : Text();
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }

View File

@ -193,7 +193,7 @@ HistoryPoll::HistoryPoll(
: HistoryMedia(parent) : HistoryMedia(parent)
, _poll(poll) , _poll(poll)
, _question(st::msgMinWidth / 2) { , _question(st::msgMinWidth / 2) {
Auth().data().registerPollView(_poll, _parent); history()->owner().registerPollView(_poll, _parent);
} }
QSize HistoryPoll::countOptimalSize() { QSize HistoryPoll::countOptimalSize() {
@ -371,7 +371,7 @@ ClickHandlerPtr HistoryPoll::createAnswerClickHandler(
const auto option = answer.option; const auto option = answer.option;
const auto itemId = _parent->data()->fullId(); const auto itemId = _parent->data()->fullId();
return std::make_shared<LambdaClickHandler>([=] { return std::make_shared<LambdaClickHandler>([=] {
Auth().api().sendPollVotes(itemId, { option }); history()->session().api().sendPollVotes(itemId, { option });
}); });
} }
@ -563,7 +563,7 @@ void HistoryPoll::resetAnswersAnimation() const {
void HistoryPoll::step_radial(TimeMs ms, bool timer) { void HistoryPoll::step_radial(TimeMs ms, bool timer) {
if (timer && !anim::Disabled()) { if (timer && !anim::Disabled()) {
Auth().data().requestViewRepaint(_parent); history()->owner().requestViewRepaint(_parent);
} }
} }
@ -806,7 +806,7 @@ void HistoryPoll::startAnswersAnimation() const {
data.opacity.start(can ? 0. : 1.); data.opacity.start(can ? 0. : 1.);
} }
_answersAnimation->progress.start( _answersAnimation->progress.start(
[=] { Auth().data().requestViewRepaint(_parent); }, [=] { history()->owner().requestViewRepaint(_parent); },
0., 0.,
1., 1.,
st::historyPollDuration); st::historyPollDuration);
@ -883,7 +883,7 @@ void HistoryPoll::toggleRipple(Answer &answer, bool pressed) {
? st::historyPollRippleOut ? st::historyPollRippleOut
: st::historyPollRippleIn), : st::historyPollRippleIn),
std::move(mask), std::move(mask),
[=] { Auth().data().requestViewRepaint(_parent); }); [=] { history()->owner().requestViewRepaint(_parent); });
} }
const auto top = countAnswerTop(answer, innerWidth); const auto top = countAnswerTop(answer, innerWidth);
answer.ripple->add(_lastLinkPoint - QPoint(0, top)); answer.ripple->add(_lastLinkPoint - QPoint(0, top));
@ -895,5 +895,5 @@ void HistoryPoll::toggleRipple(Answer &answer, bool pressed) {
} }
HistoryPoll::~HistoryPoll() { HistoryPoll::~HistoryPoll() {
Auth().data().unregisterPollView(_poll, _parent); history()->owner().unregisterPollView(_poll, _parent);
} }

View File

@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/media/history_media_common.h" #include "history/media/history_media_common.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "ui/image/image.h" #include "ui/image/image.h"
@ -501,7 +501,7 @@ void HistoryVideo::parentTextUpdated() {
_caption = (_parent->media() == this) _caption = (_parent->media() == this)
? createCaption(_parent->data()) ? createCaption(_parent->data())
: Text(); : Text();
Auth().data().requestViewResize(_parent); history()->owner().requestViewResize(_parent);
} }
void HistoryVideo::updateStatusText() const { void HistoryVideo::updateStatusText() const {

View File

@ -8,10 +8,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/media/history_media_web_page.h" #include "history/media/history_media_web_page.h"
#include "layout.h" #include "layout.h"
#include "auth_session.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/media/history_media_common.h" #include "history/media/history_media_common.h"
@ -76,7 +76,7 @@ HistoryWebPage::HistoryWebPage(
, _data(data) , _data(data)
, _title(st::msgMinWidth - st::webPageLeft) , _title(st::msgMinWidth - st::webPageLeft)
, _description(st::msgMinWidth - st::webPageLeft) { , _description(st::msgMinWidth - st::webPageLeft) {
Auth().data().registerWebPageView(_data, _parent); history()->owner().registerWebPageView(_data, _parent);
} }
QSize HistoryWebPage::countOptimalSize() { QSize HistoryWebPage::countOptimalSize() {
@ -694,5 +694,5 @@ int HistoryWebPage::bottomInfoPadding() const {
} }
HistoryWebPage::~HistoryWebPage() { HistoryWebPage::~HistoryWebPage() {
Auth().data().unregisterWebPageView(_data, _parent); history()->owner().unregisterWebPageView(_data, _parent);
} }

View File

@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_groups.h" #include "data/data_groups.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "auth_session.h"
#include "layout.h" #include "layout.h"
#include "styles/style_history.h" #include "styles/style_history.h"
@ -139,10 +138,10 @@ Element::Element(
, _data(data) , _data(data)
, _dateTime(ItemDateTime(data)) , _dateTime(ItemDateTime(data))
, _context(delegate->elementContext()) { , _context(delegate->elementContext()) {
Auth().data().registerItemView(this); history()->owner().registerItemView(this);
refreshMedia(); refreshMedia();
if (_context == Context::History) { if (_context == Context::History) {
_data->_history->setHasPendingResizedItems(); history()->setHasPendingResizedItems();
} }
} }
@ -154,6 +153,10 @@ not_null<HistoryItem*> Element::data() const {
return _data; return _data;
} }
not_null<History*> Element::history() const {
return _data->history();
}
QDateTime Element::dateTime() const { QDateTime Element::dateTime() const {
return _dateTime; return _dateTime;
} }
@ -260,7 +263,7 @@ void Element::refreshMedia() {
const auto item = data(); const auto item = data();
const auto media = item->media(); const auto media = item->media();
if (media && media->canBeGrouped()) { if (media && media->canBeGrouped()) {
if (const auto group = Auth().data().groups().find(item)) { if (const auto group = history()->owner().groups().find(item)) {
if (group->items.back() != item) { if (group->items.back() != item) {
_media = nullptr; _media = nullptr;
_flags |= Flag::HiddenByGroup; _flags |= Flag::HiddenByGroup;
@ -269,7 +272,7 @@ void Element::refreshMedia() {
this, this,
group->items); group->items);
if (!pendingResize()) { if (!pendingResize()) {
Auth().data().requestViewResize(this); history()->owner().requestViewResize(this);
} }
} }
return; return;
@ -324,7 +327,7 @@ void Element::destroyUnreadBar() {
return; return;
} }
RemoveComponents(UnreadBar::Bit()); RemoveComponents(UnreadBar::Bit());
Auth().data().requestViewResize(this); history()->owner().requestViewResize(this);
if (data()->mainView() == this) { if (data()->mainView() == this) {
recountAttachToPreviousInBlocks(); recountAttachToPreviousInBlocks();
} }
@ -341,9 +344,9 @@ void Element::setUnreadBarCount(int count) {
if (data()->mainView() == this) { if (data()->mainView() == this) {
recountAttachToPreviousInBlocks(); recountAttachToPreviousInBlocks();
} }
Auth().data().requestViewResize(this); history()->owner().requestViewResize(this);
} else { } else {
Auth().data().requestViewRepaint(this); history()->owner().requestViewRepaint(this);
} }
} }
@ -608,7 +611,7 @@ void Element::clickHandlerActiveChanged(
} }
} }
App::hoveredLinkItem(active ? this : nullptr); App::hoveredLinkItem(active ? this : nullptr);
Auth().data().requestViewRepaint(this); history()->owner().requestViewRepaint(this);
if (const auto media = this->media()) { if (const auto media = this->media()) {
media->clickHandlerActiveChanged(handler, active); media->clickHandlerActiveChanged(handler, active);
} }
@ -623,7 +626,7 @@ void Element::clickHandlerPressedChanged(
} }
} }
App::pressedLinkItem(pressed ? this : nullptr); App::pressedLinkItem(pressed ? this : nullptr);
Auth().data().requestViewRepaint(this); history()->owner().requestViewRepaint(this);
if (const auto media = this->media()) { if (const auto media = this->media()) {
media->clickHandlerPressedChanged(handler, pressed); media->clickHandlerPressedChanged(handler, pressed);
} }
@ -634,9 +637,9 @@ Element::~Element() {
_data->clearMainView(); _data->clearMainView();
} }
if (_context == Context::History) { if (_context == Context::History) {
Auth().data().notifyViewRemoved(this); history()->owner().notifyViewRemoved(this);
} }
Auth().data().unregisterItemView(this); history()->owner().unregisterItemView(this);
} }
} // namespace HistoryView } // namespace HistoryView

View File

@ -121,6 +121,7 @@ public:
not_null<ElementDelegate*> delegate() const; not_null<ElementDelegate*> delegate() const;
not_null<HistoryItem*> data() const; not_null<HistoryItem*> data() const;
not_null<History*> history() const;
HistoryMedia *media() const; HistoryMedia *media() const;
Context context() const; Context context() const;
void refreshDataId(); void refreshDataId();

View File

@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h" #include "mainwidget.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "auth_session.h"
#include "layout.h" #include "layout.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
#include "styles/style_history.h" #include "styles/style_history.h"
@ -57,7 +56,7 @@ const style::TextStyle &KeyboardStyle::textStyle() const {
} }
void KeyboardStyle::repaint(not_null<const HistoryItem*> item) const { void KeyboardStyle::repaint(not_null<const HistoryItem*> item) const {
Auth().data().requestItemRepaint(item); item->history()->owner().requestItemRepaint(item);
} }
int KeyboardStyle::buttonRadius() const { int KeyboardStyle::buttonRadius() const {

View File

@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "calls/calls_instance.h" #include "calls/calls_instance.h"
#include "data/data_peer_values.h" #include "data/data_peer_values.h"
#include "data/data_feed.h" #include "data/data_feed.h"
#include "data/data_session.h"
#include "support/support_helper.h" #include "support/support_helper.h"
#include "observer_peer.h" #include "observer_peer.h"
#include "apiwrap.h" #include "apiwrap.h"
@ -96,13 +97,14 @@ TopBarWidget::TopBarWidget(
if (Adaptive::OneColumn()) { if (Adaptive::OneColumn()) {
createUnreadBadge(); createUnreadBadge();
} }
subscribe( Auth().data().sendActionAnimationUpdated(
App::histories().sendActionAnimationUpdated(), ) | rpl::start_with_next([=](
[this](const Histories::SendActionAnimationUpdate &update) { const Data::Session::SendActionAnimationUpdate &update) {
if (update.history == _activeChat.history()) { if (update.history == _activeChat.history()) {
this->update(); this->update();
} }
}); }, lifetime());
using UpdateFlag = Notify::PeerUpdate::Flag; using UpdateFlag = Notify::PeerUpdate::Flag;
auto flags = UpdateFlag::UserHasCalls auto flags = UpdateFlag::UserHasCalls
| UpdateFlag::UserOnlineChanged | UpdateFlag::UserOnlineChanged
@ -696,8 +698,8 @@ void TopBarWidget::updateUnreadBadge() {
if (!_unreadBadge) return; if (!_unreadBadge) return;
const auto history = _activeChat.history(); const auto history = _activeChat.history();
const auto active = !App::histories().unreadBadgeMutedIgnoreOne(history); const auto active = !Auth().data().unreadBadgeMutedIgnoreOne(history);
const auto counter = App::histories().unreadBadgeIgnoreOne(history); const auto counter = Auth().data().unreadBadgeIgnoreOne(history);
const auto text = [&] { const auto text = [&] {
if (!counter) { if (!counter) {
return QString(); return QString();

View File

@ -100,7 +100,7 @@ Controller::Controller(
, _widget(widget) , _widget(widget)
, _key(memento->key()) , _key(memento->key())
, _migrated(memento->migratedPeerId() , _migrated(memento->migratedPeerId()
? App::peer(memento->migratedPeerId()) ? App::peer(memento->migratedPeerId()).get()
: nullptr) : nullptr)
, _section(memento->section()) { , _section(memento->section()) {
updateSearchControllers(memento); updateSearchControllers(memento);

View File

@ -1420,8 +1420,8 @@ void MainWidget::updateScrollColors() {
_history->updateScrollColors(); _history->updateScrollColors();
} }
void MainWidget::setChatBackground(const App::WallPaper &wp) { void MainWidget::setChatBackground(const Data::WallPaper &background) {
_background = std::make_unique<App::WallPaper>(wp); _background = std::make_unique<Data::WallPaper>(background);
_background->full->loadEvenCancelled(Data::FileOrigin()); _background->full->loadEvenCancelled(Data::FileOrigin());
checkChatBackground(); checkChatBackground();
} }
@ -1450,7 +1450,7 @@ void MainWidget::checkChatBackground() {
Window::Theme::Background()->setImage(_background->id, _background->full->pix(Data::FileOrigin()).toImage()); Window::Theme::Background()->setImage(_background->id, _background->full->pix(Data::FileOrigin()).toImage());
} }
_background = nullptr; _background = nullptr;
QTimer::singleShot(0, this, SLOT(update())); crl::on_main(this, [=] { update(); });
} }
} }
} }
@ -1730,9 +1730,9 @@ void MainWidget::ui_showPeerHistory(
animationParams); animationParams);
} else { } else {
_history->show(); _history->show();
if (App::wnd()) { crl::on_main(App::wnd(), [] {
QTimer::singleShot(0, App::wnd(), SLOT(setInnerFocus())); App::wnd()->setInnerFocus();
} });
} }
} }
} }
@ -2073,9 +2073,9 @@ void MainWidget::showBackFromStack(
if (selectingPeer()) return; if (selectingPeer()) return;
if (_stack.empty()) { if (_stack.empty()) {
_controller->clearSectionStack(params); _controller->clearSectionStack(params);
if (App::wnd()) { crl::on_main(App::wnd(), [] {
QTimer::singleShot(0, App::wnd(), SLOT(setInnerFocus())); App::wnd()->setInnerFocus();
} });
return; return;
} }
auto item = std::move(_stack.back()); auto item = std::move(_stack.back());
@ -3256,8 +3256,7 @@ void MainWidget::openPeerByName(
FullMsgId clickFromMessageId) { FullMsgId clickFromMessageId) {
Messenger::Instance().hideMediaView(); Messenger::Instance().hideMediaView();
PeerData *peer = App::peerByName(username); if (const auto peer = Auth().data().peerByUsername(username)) {
if (peer) {
if (msgId == ShowAtGameShareMsgId) { if (msgId == ShowAtGameShareMsgId) {
if (peer->isUser() && peer->asUser()->botInfo && !startToken.isEmpty()) { if (peer->isUser() && peer->asUser()->botInfo && !startToken.isEmpty()) {
peer->asUser()->botInfo->shareGameShortName = startToken; peer->asUser()->botInfo->shareGameShortName = startToken;
@ -3716,8 +3715,11 @@ bool fwdInfoDataLoaded(const MTPMessageFwdHeader &header) {
if (!App::channelLoaded(peerFromChannel(info.vchannel_id))) { if (!App::channelLoaded(peerFromChannel(info.vchannel_id))) {
return false; return false;
} }
if (info.has_from_id() && !App::user(peerFromUser(info.vfrom_id), PeerData::MinimalLoaded)) { if (info.has_from_id()) {
return false; const auto from = App::user(peerFromUser(info.vfrom_id));
if (from->loadedStatus == PeerData::NotLoaded) {
return false;
}
} }
} else { } else {
if (info.has_from_id() && !App::userLoaded(peerFromUser(info.vfrom_id))) { if (info.has_from_id() && !App::userLoaded(peerFromUser(info.vfrom_id))) {
@ -4188,7 +4190,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
const auto user = App::userLoaded(d.vuser_id.v); const auto user = App::userLoaded(d.vuser_id.v);
if (history && user) { if (history && user) {
const auto when = requestingDifference() ? 0 : unixtime(); const auto when = requestingDifference() ? 0 : unixtime();
App::histories().registerSendAction(history, user, d.vaction, when); Auth().data().registerSendAction(history, user, d.vaction, when);
} }
} break; } break;
@ -4207,7 +4209,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
: App::userLoaded(d.vuser_id.v); : App::userLoaded(d.vuser_id.v);
if (history && user) { if (history && user) {
const auto when = requestingDifference() ? 0 : unixtime(); const auto when = requestingDifference() ? 0 : unixtime();
App::histories().registerSendAction(history, user, d.vaction, when); Auth().data().registerSendAction(history, user, d.vaction, when);
} }
} break; } break;
@ -4505,8 +4507,11 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateChannelAvailableMessages: { case mtpc_updateChannelAvailableMessages: {
auto &d = update.c_updateChannelAvailableMessages(); auto &d = update.c_updateChannelAvailableMessages();
if (auto channel = App::channelLoaded(d.vchannel_id.v)) { if (const auto channel = App::channelLoaded(d.vchannel_id.v)) {
channel->setAvailableMinId(d.vavailable_min_id.v); channel->setAvailableMinId(d.vavailable_min_id.v);
if (const auto history = App::historyLoaded(channel)) {
history->clearUpTill(d.vavailable_min_id.v);
}
} }
} break; } break;

View File

@ -24,6 +24,10 @@ namespace Notify {
struct PeerUpdate; struct PeerUpdate;
} // namespace Notify } // namespace Notify
namespace Data {
struct WallPaper;
} // namespace Data
namespace Dialogs { namespace Dialogs {
struct RowDescriptor; struct RowDescriptor;
class Row; class Row;
@ -222,7 +226,7 @@ public:
QPixmap cachedBackground(const QRect &forRect, int &x, int &y); QPixmap cachedBackground(const QRect &forRect, int &x, int &y);
void updateScrollColors(); void updateScrollColors();
void setChatBackground(const App::WallPaper &wp); void setChatBackground(const Data::WallPaper &background);
bool chatBackgroundLoading(); bool chatBackgroundLoading();
float64 chatBackgroundProgress() const; float64 chatBackgroundProgress() const;
void checkChatBackground(); void checkChatBackground();
@ -547,7 +551,7 @@ private:
ViewsIncrementByRequest _viewsIncrementByRequest; ViewsIncrementByRequest _viewsIncrementByRequest;
SingleTimer _viewsIncrementTimer; SingleTimer _viewsIncrementTimer;
std::unique_ptr<App::WallPaper> _background; std::unique_ptr<Data::WallPaper> _background;
bool _firstColumnResizing = false; bool _firstColumnResizing = false;
int _firstColumnResizingShift = 0; int _firstColumnResizingShift = 0;

View File

@ -142,13 +142,9 @@ void MainWindow::firstShow() {
void MainWindow::clearWidgetsHook() { void MainWindow::clearWidgetsHook() {
Expects(_passcodeLock == nullptr || !Global::LocalPasscode()); Expects(_passcodeLock == nullptr || !Global::LocalPasscode());
auto wasMain = (_main != nullptr);
_main.destroy(); _main.destroy();
_passcodeLock.destroy(); _passcodeLock.destroy();
_intro.destroy(); _intro.destroy();
if (wasMain) {
App::clearHistories();
}
} }
QPixmap MainWindow::grabInner() { QPixmap MainWindow::grabInner() {

View File

@ -735,19 +735,20 @@ void Messenger::authSessionCreate(const MTPUser &user) {
void Messenger::authSessionDestroy() { void Messenger::authSessionDestroy() {
unlockTerms(); unlockTerms();
_authSession.reset(); _authSession = nullptr;
_private->storedAuthSession.reset(); _private->storedAuthSession.reset();
_private->authSessionUserId = 0; _private->authSessionUserId = 0;
_private->authSessionUserSerialized = {}; _private->authSessionUserSerialized = {};
authSessionChanged().notify(true); authSessionChanged().notify(true);
Notify::unreadCounterUpdated();
} }
int Messenger::unreadBadge() const { int Messenger::unreadBadge() const {
return _authSession ? App::histories().unreadBadge() : 0; return _authSession ? _authSession->data().unreadBadge() : 0;
} }
bool Messenger::unreadBadgeMuted() const { bool Messenger::unreadBadgeMuted() const {
return _authSession ? App::histories().unreadBadgeMuted() : false; return _authSession ? _authSession->data().unreadBadgeMuted() : false;
} }
void Messenger::setInternalLinkDomain(const QString &domain) const { void Messenger::setInternalLinkDomain(const QString &domain) const {
@ -902,7 +903,6 @@ Messenger::~Messenger() {
_mediaView.reset(); _mediaView.reset();
// Some MTP requests can be cancelled from data clearing. // Some MTP requests can be cancelled from data clearing.
App::clearHistories();
authSessionDestroy(); authSessionDestroy();
// The langpack manager should be destroyed before MTProto instance, // The langpack manager should be destroyed before MTProto instance,
@ -1000,16 +1000,14 @@ void Messenger::loggedOut() {
Media::Player::mixer()->stopAndClear(); Media::Player::mixer()->stopAndClear();
Global::SetVoiceMsgPlaybackDoubled(false); Global::SetVoiceMsgPlaybackDoubled(false);
Media::Player::mixer()->setVoicePlaybackDoubled(false); Media::Player::mixer()->setVoicePlaybackDoubled(false);
if (const auto w = getActiveWindow()) { if (const auto window = getActiveWindow()) {
w->tempDirDelete(Local::ClearManagerAll); window->tempDirDelete(Local::ClearManagerAll);
w->setupIntro(); window->setupIntro();
} }
App::histories().clear();
if (const auto session = authSession()) { if (const auto session = authSession()) {
session->data().cache().close(); session->data().clearLocalStorage();
session->data().cache().clear(); authSessionDestroy();
} }
authSessionDestroy();
if (_mediaView) { if (_mediaView) {
hideMediaView(); hideMediaView();
_mediaView->clearData(); _mediaView->clearData();

View File

@ -11,18 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Support { namespace Support {
bool ValidateAccount(const MTPUser &self) {
//return true; AssertIsDebug();
return self.match([](const MTPDuser &data) {
DEBUG_LOG(("ValidateAccount: %1 %2"
).arg(Logs::b(data.has_phone())
).arg(data.has_phone() ? qs(data.vphone) : QString()));
return data.has_phone() && qs(data.vphone).startsWith(qstr("424"));
}, [](const MTPDuserEmpty &data) {
return false;
});
}
bool HandleSwitch(Qt::KeyboardModifiers modifiers) { bool HandleSwitch(Qt::KeyboardModifiers modifiers) {
return !(modifiers & Qt::ShiftModifier) return !(modifiers & Qt::ShiftModifier)
|| (!(modifiers & Qt::ControlModifier) || (!(modifiers & Qt::ControlModifier)

View File

@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Support { namespace Support {
bool ValidateAccount(const MTPUser &self);
enum class SwitchSettings { enum class SwitchSettings {
None, None,
Next, Next,

View File

@ -282,6 +282,12 @@ Helper::Helper(not_null<AuthSession*> session)
}).send(); }).send();
} }
std::unique_ptr<Helper> Helper::Create(not_null<AuthSession*> session) {
//return std::make_unique<Helper>(session); AssertIsDebug();
const auto valid = session->user()->phone().startsWith(qstr("424"));
return valid ? std::make_unique<Helper>(session) : nullptr;
}
void Helper::registerWindow(not_null<Window::Controller*> controller) { void Helper::registerWindow(not_null<Window::Controller*> controller) {
controller->activeChatValue( controller->activeChatValue(
) | rpl::map([](Dialogs::Key key) { ) | rpl::map([](Dialogs::Key key) {

View File

@ -39,6 +39,8 @@ class Helper : private MTP::Sender {
public: public:
explicit Helper(not_null<AuthSession*> session); explicit Helper(not_null<AuthSession*> session);
static std::unique_ptr<Helper> Create(not_null<AuthSession*> session);
void registerWindow(not_null<Window::Controller*> controller); void registerWindow(not_null<Window::Controller*> controller);
void cloudDraftChanged(not_null<History*> history); void cloudDraftChanged(not_null<History*> history);

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "data/data_session.h"
#include "mediaview.h" #include "mediaview.h"
#include "auth_session.h" #include "auth_session.h"
#include "apiwrap.h" #include "apiwrap.h"
@ -428,7 +429,7 @@ void MainWindow::updateUnreadCounter() {
if (!Global::started() || App::quitting()) return; if (!Global::started() || App::quitting()) return;
const auto counter = AuthSession::Exists() const auto counter = AuthSession::Exists()
? App::histories().unreadBadge() ? Auth().data().unreadBadge()
: 0; : 0;
_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"); _titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram");