2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-05 08:55:59 +00:00

Remove some calls to Auth().

This commit is contained in:
John Preston
2019-07-24 13:13:51 +02:00
parent 9cf4cf6dca
commit 06982fdf04
39 changed files with 573 additions and 444 deletions

View File

@@ -105,8 +105,8 @@ private:
};
History *FindWastedPin(Data::Folder *folder) {
const auto &order = Auth().data().pinnedChatsOrder(folder);
History *FindWastedPin(not_null<Data::Session*> data, Data::Folder *folder) {
const auto &order = data->pinnedChatsOrder(folder);
for (const auto &pinned : order) {
if (const auto history = pinned.history()) {
if (history->peer->isChat()
@@ -126,17 +126,19 @@ void AddChatMembers(not_null<ChatData*> chat) {
bool PinnedLimitReached(Dialogs::Key key) {
Expects(key.entry()->folderKnown());
const auto folder = key.entry()->folder();
const auto pinnedCount = Auth().data().pinnedChatsCount(folder);
const auto pinnedMax = Auth().data().pinnedChatsLimit(folder);
const auto entry = key.entry();
const auto owner = &entry->owner();
const auto folder = entry->folder();
const auto pinnedCount = owner->pinnedChatsCount(folder);
const auto pinnedMax = owner->pinnedChatsLimit(folder);
if (pinnedCount < pinnedMax) {
return false;
}
// Some old chat, that was converted, maybe is still pinned.
if (const auto wasted = FindWastedPin(folder)) {
Auth().data().setChatPinned(wasted, false);
Auth().data().setChatPinned(key, true);
Auth().api().savePinnedOrder(folder);
if (const auto wasted = FindWastedPin(owner, folder)) {
owner->setChatPinned(wasted, false);
owner->setChatPinned(key, true);
entry->session().api().savePinnedOrder(folder);
} else {
auto errorText = tr::lng_error_pinned_max(
tr::now,
@@ -151,12 +153,13 @@ void TogglePinnedDialog(Dialogs::Key key) {
if (!key.entry()->folderKnown()) {
return;
}
const auto owner = &key.entry()->owner();
const auto isPinned = !key.entry()->isPinnedDialog();
if (isPinned && PinnedLimitReached(key)) {
return;
}
Auth().data().setChatPinned(key, isPinned);
owner->setChatPinned(key, isPinned);
const auto flags = isPinned
? MTPmessages_ToggleDialogPin::Flag::f_pinned
: MTPmessages_ToggleDialogPin::Flag(0);
@@ -165,7 +168,7 @@ void TogglePinnedDialog(Dialogs::Key key) {
MTP_flags(flags),
MTP_inputDialogPeer(key.history()->peer->input)
)).done([=](const MTPBool &result) {
Auth().data().notifyPinnedDialogsOrderUpdated();
owner->notifyPinnedDialogsOrderUpdated();
}).send();
} else if (const auto folder = key.folder()) {
folder->session().api().request(MTPmessages_ToggleDialogPin(
@@ -199,8 +202,8 @@ bool Filler::showInfo() {
} else if (!Adaptive::ThreeColumn()) {
return true;
} else if (
!Auth().settings().thirdSectionInfoEnabled() &&
!Auth().settings().tabbedReplacedWithInfo()) {
!_peer->session().settings().thirdSectionInfoEnabled() &&
!_peer->session().settings().tabbedReplacedWithInfo()) {
return true;
}
return false;
@@ -290,9 +293,11 @@ void Filler::addToggleUnreadMark() {
const auto markAsRead = isUnread(peer);
const auto handle = [&](not_null<History*> history) {
if (markAsRead) {
Auth().api().readServerHistory(history);
peer->session().api().readServerHistory(history);
} else {
Auth().api().changeDialogUnreadMark(history, !markAsRead);
peer->session().api().changeDialogUnreadMark(
history,
!markAsRead);
}
};
const auto history = peer->owner().history(peer);
@@ -361,16 +366,16 @@ void Filler::addBlockUser(not_null<UserData*> user) {
}, *lifetime);
if (user->blockStatus() == UserData::BlockStatus::Unknown) {
Auth().api().requestFullPeer(user);
user->session().api().requestFullPeer(user);
}
}
void Filler::addUserActions(not_null<UserData*> user) {
const auto window = &_controller->window()->controller();
if (_source != PeerMenuSource::ChatsList) {
if (Auth().supportMode()) {
if (user->session().supportMode()) {
_addAction("Edit support info", [=] {
Auth().supportHelper().editInfo(user);
user->session().supportHelper().editInfo(user);
});
}
if (!user->isContact() && !user->isSelf() && !user->isBot()) {
@@ -409,7 +414,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
tr::lng_profile_clear_history(tr::now),
ClearHistoryHandler(user));
if (!user->isInaccessible()
&& user != Auth().user()
&& user != user->session().user()
&& _source != PeerMenuSource::ChatsList) {
addBlockUser(user);
}
@@ -503,7 +508,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
: tr::lng_profile_join_channel(tr::now);
_addAction(
text,
[channel] { Auth().api().joinChannel(channel); });
[=] { channel->session().api().joinChannel(channel); });
}
if (_source != PeerMenuSource::ChatsList) {
const auto needReport = !channel->amCreator()
@@ -622,7 +627,7 @@ void FolderFiller::addTogglesForArchive() {
} // namespace
void PeerMenuExportChat(not_null<PeerData*> peer) {
Auth().data().startExport(peer);
peer->owner().startExport(peer);
}
void PeerMenuDeleteContact(not_null<UserData*> user) {
@@ -654,7 +659,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
return;
} else if (peer->isSelf()) {
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
Auth().api().shareContact(user, options);
user->session().api().shareContact(user, options);
Ui::Toast::Show(tr::lng_share_done(tr::now));
if (auto strong = *weak) {
strong->closeBox();
@@ -671,7 +676,7 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
const auto history = peer->owner().history(peer);
Ui::showPeerHistory(history, ShowAtTheEndMsgId);
auto options = ApiWrap::SendOptions(history);
Auth().api().shareContact(user, options);
user->session().api().shareContact(user, options);
}), LayerOption::KeepOther);
};
*weak = Ui::show(Box<PeerListBox>(
@@ -698,8 +703,8 @@ void PeerMenuCreatePoll(not_null<PeerData*> peer) {
if (const auto localDraft = options.history->localDraft()) {
options.clearDraft = localDraft->textWithTags.text.isEmpty();
}
Auth().api().createPoll(result, options, crl::guard(box, [=] {
const auto api = &peer->session().api();
api->createPoll(result, options, crl::guard(box, [=] {
box->closeBox();
}), crl::guard(box, [=](const RPCError &error) {
*lock = false;
@@ -802,11 +807,12 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
weak
](not_null<PeerData*> peer) mutable {
if (peer->isSelf()) {
auto items = Auth().data().idsToItems(ids);
auto items = peer->owner().idsToItems(ids);
if (!items.empty()) {
const auto api = &peer->session().api();
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
options.generateLocal = false;
Auth().api().forwardMessages(std::move(items), options, [] {
api->forwardMessages(std::move(items), options, [] {
Ui::Toast::Show(tr::lng_share_done(tr::now));
});
}
@@ -839,8 +845,10 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
LayerOption::KeepOther);
return;
}
auto callback = [=](const MTPchannels_ChannelParticipants &result) {
Auth().api().parseChannelParticipants(channel, result, [&](
const auto api = &channel->session().api();
api->requestChannelMembersForAdd(channel, [=](
const MTPchannels_ChannelParticipants &result) {
api->parseChannelParticipants(channel, result, [&](
int availableCount,
const QVector<MTPChannelParticipant> &list) {
auto already = (
@@ -849,8 +857,8 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
return p.match([](const auto &data) {
return data.vuser_id().v;
});
}) | ranges::view::transform([](UserId userId) {
return Auth().data().userLoaded(userId);
}) | ranges::view::transform([&](UserId userId) {
return channel->owner().userLoaded(userId);
}) | ranges::view::filter([](UserData *user) {
return (user != nullptr);
}) | ranges::to_vector;
@@ -859,24 +867,23 @@ void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
channel,
{ already.begin(), already.end() });
});
};
Auth().api().requestChannelMembersForAdd(channel, callback);
});
}
void PeerMenuAddMuteAction(
not_null<PeerData*> peer,
const PeerMenuCallback &addAction) {
Auth().data().requestNotifySettings(peer);
peer->owner().requestNotifySettings(peer);
const auto muteText = [](bool isMuted) {
return isMuted
? tr::lng_enable_notifications_from_tray(tr::now)
: tr::lng_disable_notifications_from_tray(tr::now);
};
const auto muteAction = addAction(QString("-"), [=] {
if (!Auth().data().notifyIsMuted(peer)) {
if (!peer->owner().notifyIsMuted(peer)) {
Ui::show(Box<MuteSettingsBox>(peer));
} else {
Auth().data().updateNotifySettings(peer, 0);
peer->owner().updateNotifySettings(peer, 0);
}
});
@@ -892,7 +899,7 @@ void PeerMenuAddMuteAction(
// Ui::show(Box<ConfirmBox>(
// tr::lng_feed_sure_ungroup_all(tr::now),
// tr::lng_feed_ungroup_sure(tr::now),
// [=] { Ui::hideLayer(); Auth().api().ungroupAllFromFeed(feed); }));
// [=] { Ui::hideLayer(); feed->session().api().ungroupAllFromFeed(feed); }));
//}
//
void ToggleHistoryArchived(not_null<History*> history, bool archived) {