diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 25f8d5fe7c..9c3295adc5 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -73,6 +73,7 @@ QByteArray AuthSessionData::serialize() const { } stream << qint32(_variables.thirdSectionInfoEnabled ? 1 : 0); stream << qint32(_variables.smallDialogsList ? 1 : 0); + stream << qint32(snap(qRound(_variables.dialogsWidthRatio.current() * 1000000), 0, 1000000)); } return result; } @@ -94,6 +95,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { base::flat_set groupStickersSectionHidden; qint32 thirdSectionInfoEnabled = 0; qint32 smallDialogsList = 0; + float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current(); stream >> selectorTab; stream >> lastSeenWarningSeen; if (!stream.atEnd()) { @@ -131,6 +133,11 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { stream >> thirdSectionInfoEnabled; stream >> smallDialogsList; } + if (!stream.atEnd()) { + qint32 value = 0; + stream >> value; + dialogsWidthRatio = snap(value / 1000000., 0., 1.); + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()")); return; @@ -162,7 +169,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { _variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden); _variables.thirdSectionInfoEnabled = thirdSectionInfoEnabled; _variables.smallDialogsList = smallDialogsList; - + _variables.dialogsWidthRatio = dialogsWidthRatio; if (_variables.thirdSectionInfoEnabled) { _variables.tabbedSelectorSectionEnabled = false; } diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index 5e0bc6240f..76043ac368 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include +#include #include "base/timer.h" namespace Storage { @@ -144,8 +145,8 @@ public: }); } - void copyFrom(const AuthSessionData &other) { - _variables = other._variables; + void moveFrom(AuthSessionData &&other) { + _variables = std::move(other._variables); } QByteArray serialize() const; void constructFromSerialized(const QByteArray &serialized); @@ -219,6 +220,16 @@ public: RectPart floatPlayerCorner() const { return _variables.floatPlayerCorner; } + void setDialogsWidthRatio(float64 ratio) { + _variables.dialogsWidthRatio = ratio; + } + float64 dialogsWidthRatio() const { + return _variables.dialogsWidthRatio.current(); + } + rpl::producer dialogsWidthRatioChanges() const { + return _variables.dialogsWidthRatio.changes(); + } + void setGroupStickersSectionHidden(PeerId peerId) { _variables.groupStickersSectionHidden.insert(peerId); } @@ -233,16 +244,19 @@ private: struct Variables { Variables(); + static constexpr auto kDefaultDialogsWidthRatio = 5. / 14; + bool lastSeenWarningSeen = false; - ChatHelpers::SelectorTab selectorTab; - bool tabbedSelectorSectionEnabled = false; + ChatHelpers::SelectorTab selectorTab; // per-window + bool tabbedSelectorSectionEnabled = false; // per-window int tabbedSelectorSectionTooltipShown = 0; QMap soundOverrides; - Window::Column floatPlayerColumn; - RectPart floatPlayerCorner; + Window::Column floatPlayerColumn; // per-window + RectPart floatPlayerCorner; // per-window base::flat_set groupStickersSectionHidden; - bool thirdSectionInfoEnabled = true; - bool smallDialogsList = false; + bool thirdSectionInfoEnabled = true; // per-window + bool smallDialogsList = false; // per-window + rpl::variable dialogsWidthRatio = kDefaultDialogsWidthRatio; // per-window }; base::Variable _contactsLoaded = { false }; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 9dd53c639b..ac6890429a 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -166,10 +166,6 @@ void joinGroupByHash(const QString &hash) { if (MainWidget *m = main()) m->joinGroupByHash(hash); } -void stickersBox(const QString &name) { - if (MainWidget *m = main()) m->stickersBox(MTP_inputStickerSetShortName(MTP_string(name))); -} - void removeDialog(History *history) { if (MainWidget *m = main()) { m->removeDialog(history); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 839c516701..98ddf121dc 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -136,7 +136,6 @@ void activateBotCommand(const HistoryItem *msg, int row, int col); void searchByHashtag(const QString &tag, PeerData *inPeer); void openPeerByName(const QString &username, MsgId msgId = ShowAtUnreadMsgId, const QString &startToken = QString()); void joinGroupByHash(const QString &hash); -void stickersBox(const QString &name); void removeDialog(History *history); void showSettings(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 668e9fc234..0b08276c49 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -262,9 +262,10 @@ MainWidget::MainWidget( subscribe(_controller->dialogsListDisplayForced(), [this](bool) { updateDialogsWidthAnimated(); }); - subscribe(_controller->dialogsWidthRatio(), [this](float64) { - updateControlsGeometry(); - }); + Auth().data().dialogsWidthRatioChanges() + | rpl::start_with_next( + [this] { updateControlsGeometry(); }, + lifetime()); subscribe(_controller->floatPlayerAreaUpdated(), [this] { checkFloatPlayerVisibility(); }); @@ -3516,7 +3517,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) { void MainWidget::updateControlsGeometry() { updateWindowAdaptiveLayout(); - if (_controller->dialogsWidthRatio().value() > 0) { + if (Auth().data().dialogsWidthRatio() > 0) { _a_dialogsWidth.finish(); } if (!_a_dialogsWidth.animating()) { @@ -3616,12 +3617,12 @@ void MainWidget::updateControlsGeometry() { } void MainWidget::updateDialogsWidthAnimated() { - if (_controller->dialogsWidthRatio().value() > 0) { + if (Auth().data().dialogsWidthRatio() > 0) { return; } auto dialogsWidth = _dialogsWidth; updateWindowAdaptiveLayout(); - if (!_controller->dialogsWidthRatio().value() + if (!Auth().data().dialogsWidthRatio() && (_dialogsWidth != dialogsWidth || _a_dialogsWidth.animating())) { _dialogs->startWidthAnimation(); @@ -3722,16 +3723,15 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) { } else if (e->type() == QEvent::MouseButtonRelease) { _resizingSide = false; if (!Adaptive::OneColumn() - && _controller->dialogsWidthRatio().value() > 0) { - _controller->dialogsWidthRatio().set( - float64(_dialogsWidth) / width(), - true); + && Auth().data().dialogsWidthRatio() > 0) { + Auth().data().setDialogsWidthRatio( + float64(_dialogsWidth) / width()); } Local::writeUserSettings(); } else if (e->type() == QEvent::MouseMove && _resizingSide) { auto newWidth = mouseLeft() - _resizingSideShift; auto newRatio = (newWidth < st::dialogsWidthMin / 2) ? 0. : float64(newWidth) / width(); - _controller->dialogsWidthRatio().set(newRatio, true); + Auth().data().setDialogsWidthRatio(newRatio); } } else if (e->type() == QEvent::FocusIn) { if (auto widget = qobject_cast(o)) { @@ -3771,7 +3771,7 @@ void MainWidget::handleAdaptiveLayoutUpdate() { void MainWidget::updateWindowAdaptiveLayout() { auto layout = _controller->computeColumnLayout(); - auto dialogsWidthRatio = _controller->dialogsWidthRatio().value(); + auto dialogsWidthRatio = Auth().data().dialogsWidthRatio(); // Check if we are in a single-column layout in a wide enough window // for the normal layout. If so, switch to the normal layout. @@ -3814,7 +3814,7 @@ void MainWidget::updateWindowAdaptiveLayout() { //} } - _controller->dialogsWidthRatio().set(dialogsWidthRatio, true); + Auth().data().setDialogsWidthRatio(dialogsWidthRatio); auto useSmallColumnWidth = !Adaptive::OneColumn() && !dialogsWidthRatio diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index ca9235facf..60f337cb9e 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -68,7 +68,7 @@ Messenger *Messenger::InstancePointer() { struct Messenger::Private { UserId authSessionUserId = 0; - std::unique_ptr storedAuthSession; + std::unique_ptr storedAuthSession; MTP::Instance::Config mtpConfig; MTP::AuthKeysList mtpKeysToDestroy; base::Timer quitTimer; @@ -337,14 +337,14 @@ void Messenger::setAuthSessionUserId(UserId userId) { _private->authSessionUserId = userId; } -void Messenger::setAuthSessionFromStorage(std::unique_ptr data) { +void Messenger::setAuthSessionFromStorage(std::unique_ptr data) { Expects(!authSession()); _private->storedAuthSession = std::move(data); } AuthSessionData *Messenger::getAuthSessionData() { if (_private->authSessionUserId) { - return _private->storedAuthSession ? &_private->storedAuthSession->data : nullptr; + return _private->storedAuthSession ? _private->storedAuthSession.get() : nullptr; } else if (_authSession) { return &_authSession->data(); } @@ -414,11 +414,8 @@ void Messenger::startMtp() { } if (_private->storedAuthSession) { if (_authSession) { - _authSession->data().copyFrom(_private->storedAuthSession->data); - if (auto window = App::wnd()) { - Assert(window->controller() != nullptr); - window->controller()->dialogsWidthRatio().set(_private->storedAuthSession->dialogsWidthRatio); - } + _authSession->data().moveFrom( + std::move(*_private->storedAuthSession)); } _private->storedAuthSession.reset(); } diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h index b0af99ae17..d357ebeced 100644 --- a/Telegram/SourceFiles/messenger.h +++ b/Telegram/SourceFiles/messenger.h @@ -43,10 +43,6 @@ class FileUploader; class Translator; class MediaView; -namespace Local { -struct StoredAuthSession; -} // namespace Local - namespace Media { namespace Audio { class Instance; @@ -112,7 +108,7 @@ public: void setMtpMainDcId(MTP::DcId mainDcId); void setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData); void setAuthSessionUserId(UserId userId); - void setAuthSessionFromStorage(std::unique_ptr data); + void setAuthSessionFromStorage(std::unique_ptr data); AuthSessionData *getAuthSessionData(); // Serialization. diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index d25629fd8a..51b545849c 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -571,7 +571,7 @@ enum { dbiNotificationsCount = 0x45, dbiNotificationsCorner = 0x46, dbiThemeKey = 0x47, - dbiDialogsWidthRatio = 0x48, + dbiDialogsWidthRatioOld = 0x48, dbiUseExternalVideoPlayer = 0x49, dbiDcOptions = 0x4a, dbiMtpAuthorization = 0x4b, @@ -646,10 +646,10 @@ enum class WriteMapWhen { Soon, }; -std::unique_ptr StoredAuthSessionCache; -StoredAuthSession &GetStoredAuthSessionCache() { +std::unique_ptr StoredAuthSessionCache; +AuthSessionData &GetStoredAuthSessionCache() { if (!StoredAuthSessionCache) { - StoredAuthSessionCache = std::make_unique(); + StoredAuthSessionCache = std::make_unique(); } return *StoredAuthSessionCache; } @@ -1102,12 +1102,12 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting Global::SetNotificationsCorner(static_cast((v >= 0 && v < 4) ? v : 2)); } break; - case dbiDialogsWidthRatio: { + case dbiDialogsWidthRatioOld: { qint32 v; stream >> v; if (!_checkStreamStatus(stream)) return false; - GetStoredAuthSessionCache().dialogsWidthRatio = v / 1000000.; + GetStoredAuthSessionCache().setDialogsWidthRatio(v / 1000000.); } break; case dbiLastSeenWarningSeenOld: { @@ -1115,7 +1115,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting stream >> v; if (!_checkStreamStatus(stream)) return false; - GetStoredAuthSessionCache().data.setLastSeenWarningSeen(v == 1); + GetStoredAuthSessionCache().setLastSeenWarningSeen(v == 1); } break; case dbiAuthSessionData: { @@ -1123,7 +1123,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting stream >> v; if (!_checkStreamStatus(stream)) return false; - GetStoredAuthSessionCache().data.constructFromSerialized(v); + GetStoredAuthSessionCache().constructFromSerialized(v); } break; case dbiWorkMode: { @@ -1766,18 +1766,8 @@ void _writeUserSettings() { recentEmojiPreloadData.push_back(qMakePair(item.first->id(), item.second)); } } - auto userDataInstance = StoredAuthSessionCache ? &StoredAuthSessionCache->data : Messenger::Instance().getAuthSessionData(); + auto userDataInstance = StoredAuthSessionCache ? StoredAuthSessionCache.get() : Messenger::Instance().getAuthSessionData(); auto userData = userDataInstance ? userDataInstance->serialize() : QByteArray(); - auto dialogsWidthRatio = [] { - if (StoredAuthSessionCache) { - return StoredAuthSessionCache->dialogsWidthRatio; - } else if (auto window = App::wnd()) { - if (auto controller = window->controller()) { - return controller->dialogsWidthRatio().value(); - } - } - return Window::Controller::kDefaultDialogsWidthRatio; - }; uint32 size = 21 * (sizeof(quint32) + sizeof(qint32)); size += sizeof(quint32) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark()); @@ -1822,7 +1812,6 @@ void _writeUserSettings() { data.stream << quint32(dbiDialogsMode) << qint32(Global::DialogsModeEnabled() ? 1 : 0) << static_cast(Global::DialogsMode()); data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0); - data.stream << quint32(dbiDialogsWidthRatio) << qint32(snap(qRound(dialogsWidthRatio() * 1000000), 0, 1000000)); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); if (!userData.isEmpty()) { data.stream << quint32(dbiAuthSessionData) << userData; diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 5bbe576999..eab7271f15 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -32,11 +32,6 @@ struct Cached; namespace Local { -struct StoredAuthSession { - AuthSessionData data; - float64 dialogsWidthRatio; -}; - void start(); void finish(); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 0508446494..c705c296e9 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -108,13 +108,13 @@ Controller::ColumnLayout Controller::computeColumnLayout() const { dialogsWidth = chatWidth = bodyWidth; } else if (useNormalLayout()) { layout = Adaptive::WindowLayout::Normal; - dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value()); + dialogsWidth = qRound(bodyWidth * Auth().data().dialogsWidthRatio()); accumulate_max(dialogsWidth, st::columnMinimalWidthLeft); accumulate_min(dialogsWidth, bodyWidth - st::columnMinimalWidthMain); chatWidth = bodyWidth - dialogsWidth; } else { layout = Adaptive::WindowLayout::ThreeColumn; - dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value()); + dialogsWidth = qRound(bodyWidth * Auth().data().dialogsWidthRatio()); accumulate_max(dialogsWidth, st::columnMinimalWidthLeft); thirdWidth = st::columnMinimalWidthThird; accumulate_min( @@ -161,9 +161,8 @@ void Controller::resizeForThirdSection() { minimalThreeColumnWidth() - layout.bodyWidth, st::columnMinimalWidthThird); auto newBodyWidth = layout.bodyWidth + extendBy; - dialogsWidthRatio().set( - (dialogsWidthRatio().value() * layout.bodyWidth) / newBodyWidth, - true); + auto currentRatio = Auth().data().dialogsWidthRatio(); + Auth().data().setDialogsWidthRatio((currentRatio * layout.bodyWidth) / newBodyWidth); window()->tryToExtendWidthBy(extendBy); Auth().data().setTabbedSelectorSectionEnabled( @@ -181,9 +180,8 @@ void Controller::closeThirdSection() { auto newBodyWidth = noResize ? layout.bodyWidth : (layout.bodyWidth - layout.thirdWidth); - dialogsWidthRatio().set( - (dialogsWidthRatio().value() * layout.bodyWidth) / newBodyWidth, - true); + auto currentRatio = Auth().data().dialogsWidthRatio(); + Auth().data().setDialogsWidthRatio((currentRatio * layout.bodyWidth) / newBodyWidth); newWindowSize = QSize( window()->width() + (newBodyWidth - layout.bodyWidth), window()->height()); diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 72e9001e79..9889f9db88 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -76,8 +76,6 @@ class SectionMemento; class Controller { public: - static constexpr auto kDefaultDialogsWidthRatio = 5. / 14; - Controller(not_null window) : _window(window) { } @@ -170,12 +168,6 @@ public: not_null peer, QDate requestedDate); - base::Variable &dialogsWidthRatio() { - return _dialogsWidthRatio; - } - const base::Variable &dialogsWidthRatio() const { - return _dialogsWidthRatio; - } base::Variable &dialogsListFocused() { return _dialogsListFocused; } @@ -199,7 +191,6 @@ private: base::Observable _gifPauseLevelChanged; base::Observable _floatPlayerAreaUpdated; - base::Variable _dialogsWidthRatio = { kDefaultDialogsWidthRatio }; base::Variable _dialogsListFocused = { false }; base::Variable _dialogsListDisplayForced = { false };