mirror of https://github.com/procxx/kepka.git
Move _authSession to Main::Account.
This commit is contained in:
parent
94c4ea6174
commit
263bbf1788
|
@ -786,8 +786,7 @@ void Application::authSessionCreate(const MTPUser &user) {
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_authSession = std::make_unique<AuthSession>(&activeAccount(), user);
|
activeAccount().createSession(user);
|
||||||
authSessionChanged().notify(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::authSessionDestroy() {
|
void Application::authSessionDestroy() {
|
||||||
|
@ -798,12 +797,7 @@ void Application::authSessionDestroy() {
|
||||||
unlockTerms();
|
unlockTerms();
|
||||||
_mtproto->clearGlobalHandlers();
|
_mtproto->clearGlobalHandlers();
|
||||||
|
|
||||||
// Must be called before Auth().data() is destroyed,
|
activeAccount().destroySession();
|
||||||
// because streaming media holds pointers to it.
|
|
||||||
Media::Player::instance()->handleLogout();
|
|
||||||
|
|
||||||
_authSession = nullptr;
|
|
||||||
authSessionChanged().notify(true);
|
|
||||||
|
|
||||||
Notify::unreadCounterUpdated();
|
Notify::unreadCounterUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mtproto/auth_key.h"
|
#include "mtproto/auth_key.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
|
|
||||||
class AuthSession;
|
|
||||||
class AuthSessionSettings;
|
class AuthSessionSettings;
|
||||||
class MainWidget;
|
class MainWidget;
|
||||||
class FileUploader;
|
class FileUploader;
|
||||||
|
@ -158,13 +157,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthSession component.
|
// AuthSession component.
|
||||||
AuthSession *authSession() {
|
|
||||||
return _authSession.get();
|
|
||||||
}
|
|
||||||
void authSessionCreate(const MTPUser &user);
|
void authSessionCreate(const MTPUser &user);
|
||||||
base::Observable<void> &authSessionChanged() {
|
|
||||||
return _authSessionChanged;
|
|
||||||
}
|
|
||||||
int unreadBadge() const;
|
int unreadBadge() const;
|
||||||
bool unreadBadgeMuted() const;
|
bool unreadBadgeMuted() const;
|
||||||
void logOut();
|
void logOut();
|
||||||
|
@ -289,8 +282,6 @@ private:
|
||||||
std::unique_ptr<MTP::Instance> _mtproto;
|
std::unique_ptr<MTP::Instance> _mtproto;
|
||||||
std::unique_ptr<MTP::Instance> _mtprotoForKeysDestroy;
|
std::unique_ptr<MTP::Instance> _mtprotoForKeysDestroy;
|
||||||
rpl::event_stream<> _configUpdates;
|
rpl::event_stream<> _configUpdates;
|
||||||
std::unique_ptr<AuthSession> _authSession;
|
|
||||||
base::Observable<void> _authSessionChanged;
|
|
||||||
base::Observable<void> _passcodedChanged;
|
base::Observable<void> _passcodedChanged;
|
||||||
QPointer<BoxContent> _badProxyDisableBox;
|
QPointer<BoxContent> _badProxyDisableBox;
|
||||||
|
|
||||||
|
|
|
@ -18,32 +18,35 @@ Account::Account(const QString &dataName) {
|
||||||
Account::~Account() {
|
Account::~Account() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Account::createSession(const MTPUser &user) {
|
||||||
|
Expects(_session == nullptr);
|
||||||
|
Expects(_sessionValue.current() == nullptr);
|
||||||
|
|
||||||
|
_session = std::make_unique<AuthSession>(this, user);
|
||||||
|
_sessionValue = _session.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Account::destroySession() {
|
||||||
|
_sessionValue = nullptr;
|
||||||
|
_session = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool Account::sessionExists() const {
|
bool Account::sessionExists() const {
|
||||||
return Core::App().authSession() != nullptr;
|
return (_sessionValue.current() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthSession &Account::session() {
|
AuthSession &Account::session() {
|
||||||
Expects(sessionExists());
|
Expects(sessionExists());
|
||||||
|
|
||||||
return *Core::App().authSession();
|
return *_sessionValue.current();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<AuthSession*> Account::sessionValue() const {
|
rpl::producer<AuthSession*> Account::sessionValue() const {
|
||||||
return rpl::single(
|
return _sessionValue.value();
|
||||||
rpl::empty_value()
|
|
||||||
) | rpl::then(
|
|
||||||
base::ObservableViewer(Core::App().authSessionChanged())
|
|
||||||
) | rpl::map([] {
|
|
||||||
return Core::App().authSession();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<AuthSession*> Account::sessionChanges() const {
|
rpl::producer<AuthSession*> Account::sessionChanges() const {
|
||||||
return base::ObservableViewer(
|
return _sessionValue.changes();
|
||||||
Core::App().authSessionChanged()
|
|
||||||
) | rpl::map([] {
|
|
||||||
return Core::App().authSession();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MTP::Instance *Account::mtp() {
|
MTP::Instance *Account::mtp() {
|
||||||
|
|
|
@ -19,6 +19,9 @@ public:
|
||||||
Account(const Account &other) = delete;
|
Account(const Account &other) = delete;
|
||||||
Account &operator=(const Account &other) = delete;
|
Account &operator=(const Account &other) = delete;
|
||||||
|
|
||||||
|
void createSession(const MTPUser &user);
|
||||||
|
void destroySession();
|
||||||
|
|
||||||
[[nodiscard]] bool sessionExists() const;
|
[[nodiscard]] bool sessionExists() const;
|
||||||
[[nodiscard]] AuthSession &session();
|
[[nodiscard]] AuthSession &session();
|
||||||
[[nodiscard]] rpl::producer<AuthSession*> sessionValue() const;
|
[[nodiscard]] rpl::producer<AuthSession*> sessionValue() const;
|
||||||
|
@ -27,6 +30,8 @@ public:
|
||||||
[[nodiscard]] MTP::Instance *mtp();
|
[[nodiscard]] MTP::Instance *mtp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<AuthSession> _session;
|
||||||
|
rpl::variable<AuthSession*> _sessionValue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
#include "intro/introwidget.h"
|
#include "intro/introwidget.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionValue.
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
#include "boxes/add_contact_box.h"
|
#include "boxes/add_contact_box.h"
|
||||||
|
@ -80,12 +81,13 @@ MainWindow::MainWindow() {
|
||||||
|
|
||||||
setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
|
setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||||
|
|
||||||
subscribe(Core::App().authSessionChanged(), [this] {
|
Core::App().activeAccount().sessionValue(
|
||||||
|
) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
updateGlobalMenu();
|
updateGlobalMenu();
|
||||||
if (!AuthSession::Exists()) {
|
if (!session) {
|
||||||
_mediaPreview.destroy();
|
_mediaPreview.destroy();
|
||||||
}
|
}
|
||||||
});
|
}, lifetime());
|
||||||
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
||||||
themeUpdated(data);
|
themeUpdated(data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "core/shortcuts.h"
|
#include "core/shortcuts.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionValue.
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
|
|
||||||
|
@ -93,9 +94,10 @@ Instance::Instance()
|
||||||
});
|
});
|
||||||
|
|
||||||
// While we have one Media::Player::Instance for all authsessions we have to do this.
|
// While we have one Media::Player::Instance for all authsessions we have to do this.
|
||||||
const auto handleAuthSessionChange = [=] {
|
Core::App().activeAccount().sessionValue(
|
||||||
if (AuthSession::Exists()) {
|
) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
subscribe(Auth().calls().currentCallChanged(), [=](Calls::Call *call) {
|
if (session) {
|
||||||
|
subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) {
|
||||||
if (call) {
|
if (call) {
|
||||||
pauseOnCall(AudioMsgId::Type::Voice);
|
pauseOnCall(AudioMsgId::Type::Voice);
|
||||||
pauseOnCall(AudioMsgId::Type::Song);
|
pauseOnCall(AudioMsgId::Type::Song);
|
||||||
|
@ -104,12 +106,15 @@ Instance::Instance()
|
||||||
resumeOnCall(AudioMsgId::Type::Song);
|
resumeOnCall(AudioMsgId::Type::Song);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
const auto reset = [&](AudioMsgId::Type type) {
|
||||||
|
const auto data = getData(type);
|
||||||
|
*data = Data(type, data->overview);
|
||||||
|
};
|
||||||
|
reset(AudioMsgId::Type::Voice);
|
||||||
|
reset(AudioMsgId::Type::Song);
|
||||||
}
|
}
|
||||||
};
|
}, _lifetime);
|
||||||
subscribe(
|
|
||||||
Core::App().authSessionChanged(),
|
|
||||||
handleAuthSessionChange);
|
|
||||||
handleAuthSessionChange();
|
|
||||||
|
|
||||||
setupShortcuts();
|
setupShortcuts();
|
||||||
}
|
}
|
||||||
|
@ -636,15 +641,6 @@ void Instance::emitUpdate(AudioMsgId::Type type, CheckCallback check) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::handleLogout() {
|
|
||||||
const auto reset = [&](AudioMsgId::Type type) {
|
|
||||||
const auto data = getData(type);
|
|
||||||
*data = Data(type, data->overview);
|
|
||||||
};
|
|
||||||
reset(AudioMsgId::Type::Voice);
|
|
||||||
reset(AudioMsgId::Type::Song);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instance::setupShortcuts() {
|
void Instance::setupShortcuts() {
|
||||||
Shortcuts::Requests(
|
Shortcuts::Requests(
|
||||||
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
||||||
|
|
|
@ -156,8 +156,6 @@ public:
|
||||||
|
|
||||||
void documentLoadProgress(DocumentData *document);
|
void documentLoadProgress(DocumentData *document);
|
||||||
|
|
||||||
void handleLogout();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using SharedMediaType = Storage::SharedMediaType;
|
using SharedMediaType = Storage::SharedMediaType;
|
||||||
using SliceKey = SparseIdsMergedSlice::Key;
|
using SliceKey = SparseIdsMergedSlice::Key;
|
||||||
|
|
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "window/themes/window_theme_preview.h"
|
#include "window/themes/window_theme_preview.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionValue.
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
@ -242,14 +243,15 @@ OverlayWidget::OverlayWidget()
|
||||||
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));
|
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));
|
||||||
|
|
||||||
// While we have one mediaview for all authsessions we have to do this.
|
// While we have one mediaview for all authsessions we have to do this.
|
||||||
auto handleAuthSessionChange = [this] {
|
Core::App().activeAccount().sessionValue(
|
||||||
if (AuthSession::Exists()) {
|
) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
subscribe(Auth().downloaderTaskFinished(), [this] {
|
if (session) {
|
||||||
|
subscribe(session->downloaderTaskFinished(), [=] {
|
||||||
if (!isHidden()) {
|
if (!isHidden()) {
|
||||||
updateControls();
|
updateControls();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
subscribe(Auth().calls().currentCallChanged(), [this](Calls::Call *call) {
|
subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) {
|
||||||
if (!_streamed) {
|
if (!_streamed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -259,12 +261,12 @@ OverlayWidget::OverlayWidget()
|
||||||
playbackResumeOnCall();
|
playbackResumeOnCall();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
subscribe(Auth().documentUpdated, [this](DocumentData *document) {
|
subscribe(session->documentUpdated, [=](DocumentData *document) {
|
||||||
if (!isHidden()) {
|
if (!isHidden()) {
|
||||||
documentUpdated(document);
|
documentUpdated(document);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
subscribe(Auth().messageIdChanging, [this](std::pair<not_null<HistoryItem*>, MsgId> update) {
|
subscribe(session->messageIdChanging, [=](std::pair<not_null<HistoryItem*>, MsgId> update) {
|
||||||
changingMsgId(update.first, update.second);
|
changingMsgId(update.first, update.second);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -272,11 +274,7 @@ OverlayWidget::OverlayWidget()
|
||||||
_userPhotos = nullptr;
|
_userPhotos = nullptr;
|
||||||
_collage = nullptr;
|
_collage = nullptr;
|
||||||
}
|
}
|
||||||
};
|
}, lifetime());
|
||||||
subscribe(Core::App().authSessionChanged(), [handleAuthSessionChange] {
|
|
||||||
handleAuthSessionChange();
|
|
||||||
});
|
|
||||||
handleAuthSessionChange();
|
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
setWindowFlags(Qt::FramelessWindowHint | Qt::MaximizeUsingFullscreenGeometryHint);
|
setWindowFlags(Qt::FramelessWindowHint | Qt::MaximizeUsingFullscreenGeometryHint);
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "auth_session.h"
|
#include "auth_session.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionChanges.
|
||||||
|
|
||||||
namespace MTP {
|
namespace MTP {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -89,11 +90,12 @@ WeakInstance::WeakInstance(QPointer<MTP::Instance> instance)
|
||||||
_instance = nullptr;
|
_instance = nullptr;
|
||||||
die();
|
die();
|
||||||
});
|
});
|
||||||
subscribe(Core::App().authSessionChanged(), [=] {
|
Core::App().activeAccount().sessionChanges(
|
||||||
if (!AuthSession::Exists()) {
|
) | rpl::filter([](AuthSession *session) {
|
||||||
die();
|
return !session;
|
||||||
}
|
}) | rpl::start_with_next([=] {
|
||||||
});
|
die();
|
||||||
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WeakInstance::valid() const {
|
bool WeakInstance::valid() const {
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
|
|
||||||
QPointer<Instance> _instance;
|
QPointer<Instance> _instance;
|
||||||
std::map<mtpRequestId, Fn<void(const RPCError &)>> _requests;
|
std::map<mtpRequestId, Fn<void(const RPCError &)>> _requests;
|
||||||
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_widget.h"
|
#include "history/history_widget.h"
|
||||||
#include "history/history_inner_widget.h"
|
#include "history/history_inner_widget.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionChanges.
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "window/notifications_manager_default.h"
|
#include "window/notifications_manager_default.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
|
@ -405,8 +406,9 @@ void MainWindow::initTouchBar() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(Core::App().authSessionChanged(), [this] {
|
Core::App().activeAccount().sessionValue(
|
||||||
if (AuthSession::Exists()) {
|
) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
|
if (session) {
|
||||||
// We need only common pinned dialogs.
|
// We need only common pinned dialogs.
|
||||||
if (!_private->_touchBar) {
|
if (!_private->_touchBar) {
|
||||||
if (auto view = reinterpret_cast<NSView*>(winId())) {
|
if (auto view = reinterpret_cast<NSView*>(winId())) {
|
||||||
|
@ -422,7 +424,7 @@ void MainWindow::initTouchBar() {
|
||||||
}
|
}
|
||||||
_private->_touchBar = nil;
|
_private->_touchBar = nil;
|
||||||
}
|
}
|
||||||
});
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeWithoutDestroy() {
|
void MainWindow::closeWithoutDestroy() {
|
||||||
|
|
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_lock_widgets.h"
|
#include "window/window_lock_widgets.h"
|
||||||
#include "window/window_outdated_bar.h"
|
#include "window/window_outdated_bar.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
|
#include "main/main_account.h" // Account::authSessionValue.
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
|
@ -125,11 +126,14 @@ MainWindow::MainWindow()
|
||||||
subscribe(Global::RefWorkMode(), [=](DBIWorkMode mode) {
|
subscribe(Global::RefWorkMode(), [=](DBIWorkMode mode) {
|
||||||
workmodeUpdated(mode);
|
workmodeUpdated(mode);
|
||||||
});
|
});
|
||||||
subscribe(Core::App().authSessionChanged(), [=] {
|
|
||||||
checkAuthSession();
|
Core::App().activeAccount().sessionValue(
|
||||||
|
) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
|
_controller = session
|
||||||
|
? std::make_unique<Window::Controller>(session, this)
|
||||||
|
: nullptr;
|
||||||
updateWindowIcon();
|
updateWindowIcon();
|
||||||
});
|
}, lifetime());
|
||||||
checkAuthSession();
|
|
||||||
|
|
||||||
Core::App().termsLockValue(
|
Core::App().termsLockValue(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
@ -639,14 +643,6 @@ void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkAuthSession() {
|
|
||||||
if (AuthSession::Exists()) {
|
|
||||||
_controller = std::make_unique<Window::Controller>(&Auth(), this);
|
|
||||||
} else {
|
|
||||||
_controller = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::setInactivePress(bool inactive) {
|
void MainWindow::setInactivePress(bool inactive) {
|
||||||
_wasInactivePress = inactive;
|
_wasInactivePress = inactive;
|
||||||
if (_wasInactivePress) {
|
if (_wasInactivePress) {
|
||||||
|
|
|
@ -148,7 +148,6 @@ protected:
|
||||||
QSystemTrayIcon::ActivationReason reason) = 0;
|
QSystemTrayIcon::ActivationReason reason) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkAuthSession();
|
|
||||||
void updatePalette();
|
void updatePalette();
|
||||||
void updateUnreadCounter();
|
void updateUnreadCounter();
|
||||||
void initSize();
|
void initSize();
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/parse_helper.h"
|
#include "base/parse_helper.h"
|
||||||
#include "base/zlib_help.h"
|
#include "base/zlib_help.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "main/main_account.h" // Account::sessionValue.
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "boxes/background_box.h"
|
#include "boxes/background_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
@ -391,23 +392,20 @@ void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatBackground::start() {
|
void ChatBackground::start() {
|
||||||
if (Data::details::IsUninitializedWallPaper(_paper)) {
|
if (!Data::details::IsUninitializedWallPaper(_paper)) {
|
||||||
if (!Local::readBackground()) {
|
return;
|
||||||
set(Data::ThemeWallPaper());
|
}
|
||||||
}
|
if (!Local::readBackground()) {
|
||||||
refreshSession();
|
set(Data::ThemeWallPaper());
|
||||||
subscribe(Core::App().authSessionChanged(), [=] {
|
|
||||||
refreshSession();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ChatBackground::refreshSession() {
|
Core::App().activeAccount().sessionValue(
|
||||||
const auto session = AuthSession::Exists() ? &Auth() : nullptr;
|
) | rpl::filter([=](AuthSession *session) {
|
||||||
if (_session != session) {
|
return session != _session;
|
||||||
|
}) | rpl::start_with_next([=](AuthSession *session) {
|
||||||
_session = session;
|
_session = session;
|
||||||
checkUploadWallPaper();
|
checkUploadWallPaper();
|
||||||
}
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatBackground::checkUploadWallPaper() {
|
void ChatBackground::checkUploadWallPaper() {
|
||||||
|
|
|
@ -154,7 +154,6 @@ private:
|
||||||
void keepApplied(const QString &path, bool write);
|
void keepApplied(const QString &path, bool write);
|
||||||
[[nodiscard]] bool isNonDefaultThemeOrBackground();
|
[[nodiscard]] bool isNonDefaultThemeOrBackground();
|
||||||
[[nodiscard]] bool isNonDefaultBackground();
|
[[nodiscard]] bool isNonDefaultBackground();
|
||||||
void refreshSession();
|
|
||||||
void checkUploadWallPaper();
|
void checkUploadWallPaper();
|
||||||
[[nodiscard]] bool testingPalette() const;
|
[[nodiscard]] bool testingPalette() const;
|
||||||
|
|
||||||
|
@ -191,6 +190,8 @@ private:
|
||||||
mtpRequestId _wallPaperRequestId = 0;
|
mtpRequestId _wallPaperRequestId = 0;
|
||||||
rpl::lifetime _wallPaperUploadLifetime;
|
rpl::lifetime _wallPaperUploadLifetime;
|
||||||
|
|
||||||
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatBackground *Background();
|
ChatBackground *Background();
|
||||||
|
|
Loading…
Reference in New Issue