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

Remove Session::Exists() global access point.

This commit is contained in:
John Preston
2020-06-10 17:24:41 +04:00
parent 5f8d22f1f2
commit 598fb67cdf
19 changed files with 119 additions and 133 deletions

View File

@@ -120,9 +120,7 @@ Application::Application(not_null<Launcher*> launcher)
_mediaView->clearData();
}
if (session && !UpdaterDisabled()) {
if (const auto mtp = activeAccount().mtp()) {
UpdateChecker().setMtproto(mtp, session->userId());
}
UpdateChecker().setMtproto(session);
}
}, _lifetime);
@@ -580,6 +578,16 @@ bool Application::unreadBadgeMuted() const {
: false;
}
bool Application::offerLangPackSwitch() const {
// #TODO multi we offer only if we were upgraded from an old authed app.
return activeAccount().sessionExists();
}
bool Application::canApplyLangPackWithoutRestart() const {
// #TODO multi we can't if at least one account is authorized.
return !activeAccount().sessionExists();
}
void Application::setInternalLinkDomain(const QString &domain) const {
// This domain should start with 'http[s]://' and end with '/'.
// Like 'https://telegram.me/' or 'https://t.me/'.

View File

@@ -85,23 +85,23 @@ public:
Application &operator=(const Application &other) = delete;
~Application();
not_null<Launcher*> launcher() const {
[[nodiscard]] not_null<Launcher*> launcher() const {
return _launcher;
}
void run();
Ui::Animations::Manager &animationManager() const {
[[nodiscard]] Ui::Animations::Manager &animationManager() const {
return *_animationsManager;
}
// Windows interface.
Window::Controller *activeWindow() const;
[[nodiscard]] Window::Controller *activeWindow() const;
bool closeActiveWindow();
bool minimizeActiveWindow();
QWidget *getFileDialogParent();
[[nodiscard]] QWidget *getFileDialogParent();
void notifyFileDialogShown(bool shown);
QWidget *getModalParent();
[[nodiscard]] QWidget *getModalParent();
// Media view interface.
void checkMediaViewActivation();
@@ -113,13 +113,13 @@ public:
void showTheme(
not_null<DocumentData*> document,
const Data::CloudTheme &cloud);
PeerData *ui_getPeerForMouseAction();
[[nodiscard]] PeerData *ui_getPeerForMouseAction();
QPoint getPointForCallPanelCenter() const;
QImage logo() const {
[[nodiscard]] QPoint getPointForCallPanelCenter() const;
[[nodiscard]] QImage logo() const {
return _logo;
}
QImage logoNoMargin() const {
[[nodiscard]] QImage logoNoMargin() const {
return _logoNoMargin;
}
@@ -129,7 +129,7 @@ public:
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
// Dc options and proxy.
not_null<MTP::DcOptions*> dcOptions() {
[[nodiscard]] not_null<MTP::DcOptions*> dcOptions() {
return _dcOptions.get();
}
struct ProxyChange {
@@ -155,28 +155,30 @@ public:
// Main::Session component.
[[nodiscard]] int unreadBadge() const;
bool unreadBadgeMuted() const;
[[nodiscard]] bool unreadBadgeMuted() const;
// Media component.
Media::Audio::Instance &audio() {
[[nodiscard]] Media::Audio::Instance &audio() {
return *_audio;
}
// Langpack and emoji keywords.
Lang::Instance &langpack() {
[[nodiscard]] Lang::Instance &langpack() {
return *_langpack;
}
Lang::CloudManager *langCloudManager() {
[[nodiscard]] Lang::CloudManager *langCloudManager() {
return _langCloudManager.get();
}
ChatHelpers::EmojiKeywords &emojiKeywords() {
[[nodiscard]] bool offerLangPackSwitch() const;
[[nodiscard]] bool canApplyLangPackWithoutRestart() const;
[[nodiscard]] ChatHelpers::EmojiKeywords &emojiKeywords() {
return *_emojiKeywords;
}
// Internal links.
void setInternalLinkDomain(const QString &domain) const;
QString createInternalLink(const QString &query) const;
QString createInternalLinkFull(const QString &query) const;
[[nodiscard]] QString createInternalLink(const QString &query) const;
[[nodiscard]] QString createInternalLinkFull(const QString &query) const;
void checkStartUrl();
bool openLocalUrl(const QString &url, QVariant context);
bool openInternalUrl(const QString &url, QVariant context);

View File

@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/click_handler_types.h"
#include "mainwindow.h"
#include "main/main_account.h"
#include "main/main_session.h"
#include "info/info_memento.h"
#include "info/settings/info_settings_widget.h"
#include "window/window_session_controller.h"
@@ -172,7 +173,7 @@ private:
class MtpChecker : public Checker {
public:
MtpChecker(QPointer<MTP::Instance> instance, int32 userId, bool testing);
MtpChecker(base::weak_ptr<Main::Session> session, bool testing);
void start() override;
@@ -879,16 +880,14 @@ void HttpLoaderActor::partFailed(QNetworkReply::NetworkError e) {
}
MtpChecker::MtpChecker(
QPointer<MTP::Instance> instance,
int32 userId,
base::weak_ptr<Main::Session> session,
bool testing)
: Checker(testing)
, _mtp(instance)
, _mtpUserId(userId) {
, _mtp(session) {
}
void MtpChecker::start() {
if (!_mtp.valid() || !_mtpUserId) {
if (!_mtp.valid()) {
LOG(("Update Info: MTP is unavailable."));
crl::on_main(this, [=] { fail(); });
return;
@@ -896,7 +895,7 @@ void MtpChecker::start() {
const auto updaterVersion = Platform::AutoUpdateVersion();
const auto feed = "tdhbcfeed"
+ (updaterVersion > 1 ? QString::number(updaterVersion) : QString());
MTP::ResolveChannel(&_mtp, _mtpUserId, feed, [=](
MTP::ResolveChannel(&_mtp, feed, [=](
const MTPInputChannel &channel) {
_mtp.send(
MTPmessages_GetHistory(
@@ -931,12 +930,7 @@ void MtpChecker::gotMessage(const MTPmessages_Messages &result) {
fail();
}
};
MTP::StartDedicatedLoader(
&_mtp,
_mtpUserId,
*location,
UpdatesFolder(),
ready);
MTP::StartDedicatedLoader(&_mtp, *location, UpdatesFolder(), ready);
}
auto MtpChecker::parseMessage(const MTPmessages_Messages &result) const
@@ -1044,7 +1038,7 @@ public:
int already() const;
int size() const;
void setMtproto(const QPointer<MTP::Instance> &mtproto, int32 userId);
void setMtproto(base::weak_ptr<Main::Session> session);
~Updater();
@@ -1089,8 +1083,7 @@ private:
Implementation _mtpImplementation;
std::shared_ptr<Loader> _activeLoader;
bool _usingMtprotoLoader = (cAlphaVersion() != 0);
QPointer<MTP::Instance> _mtproto;
int32 _mtprotoUserId = 0;
base::weak_ptr<Main::Session> _session;
rpl::lifetime _lifetime;
@@ -1238,7 +1231,7 @@ void Updater::start(bool forceWait) {
std::make_unique<HttpChecker>(_testing));
startImplementation(
&_mtpImplementation,
std::make_unique<MtpChecker>(_mtproto, _mtprotoUserId, _testing));
std::make_unique<MtpChecker>(_session, _testing));
_checking.fire({});
} else {
@@ -1301,11 +1294,8 @@ void Updater::test() {
start(false);
}
void Updater::setMtproto(
const QPointer<MTP::Instance> &mtproto,
int32 userId) {
_mtproto = mtproto;
_mtprotoUserId = userId;
void Updater::setMtproto(base::weak_ptr<Main::Session> session) {
_session = session;
}
void Updater::handleTimeout() {
@@ -1405,9 +1395,7 @@ UpdateChecker::UpdateChecker()
if (IsAppLaunched()) {
const auto &account = Core::App().activeAccount();
if (account.sessionExists()) {
if (const auto mtproto = account.mtp()) {
_updater->setMtproto(mtproto, account.session().userId());
}
_updater->setMtproto(&account.session());
}
}
}
@@ -1441,10 +1429,8 @@ void UpdateChecker::test() {
_updater->test();
}
void UpdateChecker::setMtproto(
const QPointer<MTP::Instance> &mtproto,
int32 userId) {
_updater->setMtproto(mtproto, userId);
void UpdateChecker::setMtproto(base::weak_ptr<Main::Session> session) {
_updater->setMtproto(session);
}
void UpdateChecker::stop() {

View File

@@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/dedicated_file_loader.h"
namespace MTP {
class Instance;
} // namespace MTP
namespace Main {
class Session;
} // namespace Main
namespace Core {
@@ -41,7 +41,7 @@ public:
void stop();
void test();
void setMtproto(const QPointer<MTP::Instance> &mtproto, int32 userId);
void setMtproto(base::weak_ptr<Main::Session> session);
State state() const;
int already() const;