2017-02-23 09:32:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-23 09:32:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-23 09:32:28 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
#include <rpl/event_stream.h>
|
2017-10-22 17:06:57 +00:00
|
|
|
#include <rpl/filter.h>
|
2017-11-05 13:57:51 +00:00
|
|
|
#include <rpl/variable.h>
|
2017-04-09 18:06:06 +00:00
|
|
|
#include "base/timer.h"
|
|
|
|
|
2017-12-25 11:13:27 +00:00
|
|
|
class ApiWrap;
|
|
|
|
enum class SendFilesWay;
|
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
namespace Data {
|
2018-01-04 10:22:53 +00:00
|
|
|
class Session;
|
2018-01-04 09:40:58 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
namespace Storage {
|
|
|
|
class Downloader;
|
2017-08-04 14:54:32 +00:00
|
|
|
class Uploader;
|
2017-09-04 11:40:02 +00:00
|
|
|
class Facade;
|
2017-03-04 19:36:59 +00:00
|
|
|
} // namespace Storage
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
|
|
|
class System;
|
|
|
|
} // namespace Notifications
|
2017-05-24 10:04:29 +00:00
|
|
|
enum class Column;
|
2017-03-04 19:36:59 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2017-04-19 09:44:07 +00:00
|
|
|
namespace Calls {
|
|
|
|
class Instance;
|
|
|
|
} // namespace Calls
|
|
|
|
|
2017-05-24 10:10:04 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
enum class SelectorTab;
|
|
|
|
} // namespace ChatHelpers
|
2017-04-06 19:02:40 +00:00
|
|
|
|
2017-12-29 18:17:07 +00:00
|
|
|
namespace Core {
|
|
|
|
class Changelogs;
|
|
|
|
} // namespace Core
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
class AuthSessionSettings final {
|
2017-03-28 12:30:38 +00:00
|
|
|
public:
|
2018-01-04 10:22:53 +00:00
|
|
|
void moveFrom(AuthSessionSettings &&other) {
|
2017-11-05 13:57:51 +00:00
|
|
|
_variables = std::move(other._variables);
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
|
|
|
QByteArray serialize() const;
|
|
|
|
void constructFromSerialized(const QByteArray &serialized);
|
|
|
|
|
|
|
|
void setLastSeenWarningSeen(bool lastSeenWarningSeen) {
|
|
|
|
_variables.lastSeenWarningSeen = lastSeenWarningSeen;
|
|
|
|
}
|
2018-01-04 10:22:53 +00:00
|
|
|
bool lastSeenWarningSeen() const {
|
|
|
|
return _variables.lastSeenWarningSeen;
|
|
|
|
}
|
2017-12-25 11:13:27 +00:00
|
|
|
void setSendFilesWay(SendFilesWay way) {
|
|
|
|
_variables.sendFilesWay = way;
|
|
|
|
}
|
|
|
|
SendFilesWay sendFilesWay() const {
|
|
|
|
return _variables.sendFilesWay;
|
|
|
|
}
|
2017-05-24 10:10:04 +00:00
|
|
|
ChatHelpers::SelectorTab selectorTab() const {
|
|
|
|
return _variables.selectorTab;
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
2017-05-24 10:10:04 +00:00
|
|
|
void setSelectorTab(ChatHelpers::SelectorTab tab) {
|
|
|
|
_variables.selectorTab = tab;
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
bool tabbedSelectorSectionEnabled() const {
|
|
|
|
return _variables.tabbedSelectorSectionEnabled;
|
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
void setTabbedSelectorSectionEnabled(bool enabled);
|
|
|
|
bool thirdSectionInfoEnabled() const {
|
|
|
|
return _variables.thirdSectionInfoEnabled;
|
|
|
|
}
|
|
|
|
void setThirdSectionInfoEnabled(bool enabled);
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<bool> thirdSectionInfoEnabledValue() const;
|
2017-11-16 16:43:52 +00:00
|
|
|
int thirdSectionExtendedBy() const {
|
|
|
|
return _variables.thirdSectionExtendedBy;
|
|
|
|
}
|
|
|
|
void setThirdSectionExtendedBy(int savedValue) {
|
|
|
|
_variables.thirdSectionExtendedBy = savedValue;
|
|
|
|
}
|
2017-09-19 19:44:34 +00:00
|
|
|
bool tabbedReplacedWithInfo() const {
|
|
|
|
return _tabbedReplacedWithInfo;
|
|
|
|
}
|
|
|
|
void setTabbedReplacedWithInfo(bool enabled);
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<bool> tabbedReplacedWithInfoValue() const;
|
2017-09-19 18:59:10 +00:00
|
|
|
void setSmallDialogsList(bool enabled) {
|
|
|
|
_variables.smallDialogsList = enabled;
|
|
|
|
}
|
|
|
|
bool smallDialogsList() const {
|
|
|
|
return _variables.smallDialogsList;
|
|
|
|
}
|
2017-04-15 18:48:54 +00:00
|
|
|
void setLastTimeVideoPlayedAt(TimeMs time) {
|
|
|
|
_lastTimeVideoPlayedAt = time;
|
|
|
|
}
|
|
|
|
TimeMs lastTimeVideoPlayedAt() const {
|
|
|
|
return _lastTimeVideoPlayedAt;
|
|
|
|
}
|
2017-05-08 09:08:24 +00:00
|
|
|
void setSoundOverride(const QString &key, const QString &path) {
|
|
|
|
_variables.soundOverrides.insert(key, path);
|
|
|
|
}
|
|
|
|
void clearSoundOverrides() {
|
|
|
|
_variables.soundOverrides.clear();
|
|
|
|
}
|
|
|
|
QString getSoundPath(const QString &key) const;
|
2017-05-17 09:40:03 +00:00
|
|
|
void setTabbedSelectorSectionTooltipShown(int shown) {
|
|
|
|
_variables.tabbedSelectorSectionTooltipShown = shown;
|
|
|
|
}
|
|
|
|
int tabbedSelectorSectionTooltipShown() const {
|
|
|
|
return _variables.tabbedSelectorSectionTooltipShown;
|
|
|
|
}
|
2017-05-24 10:04:29 +00:00
|
|
|
void setFloatPlayerColumn(Window::Column column) {
|
|
|
|
_variables.floatPlayerColumn = column;
|
|
|
|
}
|
|
|
|
Window::Column floatPlayerColumn() const {
|
|
|
|
return _variables.floatPlayerColumn;
|
|
|
|
}
|
2017-05-24 12:07:58 +00:00
|
|
|
void setFloatPlayerCorner(RectPart corner) {
|
2017-05-24 10:04:29 +00:00
|
|
|
_variables.floatPlayerCorner = corner;
|
|
|
|
}
|
2017-05-24 12:07:58 +00:00
|
|
|
RectPart floatPlayerCorner() const {
|
2017-05-24 10:04:29 +00:00
|
|
|
return _variables.floatPlayerCorner;
|
|
|
|
}
|
2017-11-21 09:20:56 +00:00
|
|
|
void setDialogsWidthRatio(float64 ratio);
|
|
|
|
float64 dialogsWidthRatio() const;
|
|
|
|
rpl::producer<float64> dialogsWidthRatioChanges() const;
|
|
|
|
void setThirdColumnWidth(int width);
|
|
|
|
int thirdColumnWidth() const;
|
|
|
|
rpl::producer<int> thirdColumnWidthChanges() const;
|
2017-11-05 13:57:51 +00:00
|
|
|
|
2017-08-05 14:04:18 +00:00
|
|
|
void setGroupStickersSectionHidden(PeerId peerId) {
|
|
|
|
_variables.groupStickersSectionHidden.insert(peerId);
|
|
|
|
}
|
|
|
|
bool isGroupStickersSectionHidden(PeerId peerId) const {
|
|
|
|
return _variables.groupStickersSectionHidden.contains(peerId);
|
|
|
|
}
|
|
|
|
void removeGroupStickersSectionHidden(PeerId peerId) {
|
|
|
|
_variables.groupStickersSectionHidden.remove(peerId);
|
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
|
2017-03-28 12:30:38 +00:00
|
|
|
private:
|
|
|
|
struct Variables {
|
2017-05-24 10:04:29 +00:00
|
|
|
Variables();
|
|
|
|
|
2017-11-05 13:57:51 +00:00
|
|
|
static constexpr auto kDefaultDialogsWidthRatio = 5. / 14;
|
2017-11-12 16:50:58 +00:00
|
|
|
static constexpr auto kDefaultThirdColumnWidth = 0;
|
2017-11-05 13:57:51 +00:00
|
|
|
|
2017-03-28 12:30:38 +00:00
|
|
|
bool lastSeenWarningSeen = false;
|
2017-12-25 11:13:27 +00:00
|
|
|
SendFilesWay sendFilesWay;
|
2017-11-05 13:57:51 +00:00
|
|
|
ChatHelpers::SelectorTab selectorTab; // per-window
|
|
|
|
bool tabbedSelectorSectionEnabled = false; // per-window
|
2017-05-17 09:40:03 +00:00
|
|
|
int tabbedSelectorSectionTooltipShown = 0;
|
2017-05-08 09:08:24 +00:00
|
|
|
QMap<QString, QString> soundOverrides;
|
2017-11-05 13:57:51 +00:00
|
|
|
Window::Column floatPlayerColumn; // per-window
|
|
|
|
RectPart floatPlayerCorner; // per-window
|
2017-09-16 16:53:41 +00:00
|
|
|
base::flat_set<PeerId> groupStickersSectionHidden;
|
2017-11-05 13:57:51 +00:00
|
|
|
bool thirdSectionInfoEnabled = true; // per-window
|
|
|
|
bool smallDialogsList = false; // per-window
|
2017-11-16 16:43:52 +00:00
|
|
|
int thirdSectionExtendedBy = -1; // per-window
|
2017-11-12 16:50:58 +00:00
|
|
|
rpl::variable<float64> dialogsWidthRatio
|
|
|
|
= kDefaultDialogsWidthRatio; // per-window
|
|
|
|
rpl::variable<int> thirdColumnWidth
|
|
|
|
= kDefaultThirdColumnWidth; // per-window
|
2017-03-28 12:30:38 +00:00
|
|
|
};
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
rpl::event_stream<bool> _thirdSectionInfoEnabledValue;
|
2017-09-19 19:44:34 +00:00
|
|
|
bool _tabbedReplacedWithInfo = false;
|
|
|
|
rpl::event_stream<bool> _tabbedReplacedWithInfoValue;
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-03-28 12:30:38 +00:00
|
|
|
Variables _variables;
|
2017-04-15 18:48:54 +00:00
|
|
|
TimeMs _lastTimeVideoPlayedAt = 0;
|
2017-03-28 12:30:38 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
// One per Messenger.
|
|
|
|
class AuthSession;
|
|
|
|
AuthSession &Auth();
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
class AuthSession final
|
|
|
|
: public base::has_weak_ptr
|
|
|
|
, private base::Subscriber {
|
2017-02-23 09:32:28 +00:00
|
|
|
public:
|
|
|
|
AuthSession(UserId userId);
|
|
|
|
|
|
|
|
AuthSession(const AuthSession &other) = delete;
|
|
|
|
AuthSession &operator=(const AuthSession &other) = delete;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
static bool Exists();
|
|
|
|
|
2017-02-23 09:32:28 +00:00
|
|
|
UserId userId() const {
|
|
|
|
return _userId;
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
PeerId userPeerId() const {
|
|
|
|
return peerFromUser(userId());
|
|
|
|
}
|
|
|
|
UserData *user() const;
|
2017-03-04 19:36:59 +00:00
|
|
|
bool validateSelf(const MTPUser &user);
|
|
|
|
|
2017-03-15 16:24:06 +00:00
|
|
|
Storage::Downloader &downloader() {
|
|
|
|
return *_downloader;
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Storage::Uploader &uploader() {
|
|
|
|
return *_uploader;
|
|
|
|
}
|
2017-09-04 11:40:02 +00:00
|
|
|
Storage::Facade &storage() {
|
|
|
|
return *_storage;
|
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
base::Observable<void> &downloaderTaskFinished();
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2017-03-15 16:24:06 +00:00
|
|
|
Window::Notifications::System ¬ifications() {
|
|
|
|
return *_notifications;
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
Data::Session &data() {
|
|
|
|
return *_data;
|
|
|
|
}
|
|
|
|
AuthSessionSettings &settings() {
|
|
|
|
return _settings;
|
2017-03-14 14:16:03 +00:00
|
|
|
}
|
2018-01-04 10:22:53 +00:00
|
|
|
void saveSettingsDelayed(TimeMs delay = kDefaultSaveDelay);
|
2017-03-14 14:16:03 +00:00
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
ApiWrap &api() {
|
|
|
|
return *_api;
|
|
|
|
}
|
|
|
|
|
2017-04-19 09:44:07 +00:00
|
|
|
Calls::Instance &calls() {
|
|
|
|
return *_calls;
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:48:54 +00:00
|
|
|
void checkAutoLock();
|
|
|
|
void checkAutoLockIn(TimeMs time);
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
base::Observable<DocumentData*> documentUpdated;
|
2017-08-18 19:14:31 +00:00
|
|
|
base::Observable<std::pair<not_null<HistoryItem*>, MsgId>> messageIdChanging;
|
2017-08-08 09:31:48 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
~AuthSession();
|
2017-02-23 09:32:28 +00:00
|
|
|
|
|
|
|
private:
|
2017-09-30 18:26:45 +00:00
|
|
|
static constexpr auto kDefaultSaveDelay = TimeMs(1000);
|
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
const UserId _userId = 0;
|
2018-01-04 10:22:53 +00:00
|
|
|
AuthSessionSettings _settings;
|
2017-04-09 18:06:06 +00:00
|
|
|
base::Timer _saveDataTimer;
|
2017-02-23 09:32:28 +00:00
|
|
|
|
2017-04-15 18:48:54 +00:00
|
|
|
TimeMs _shouldLockAt = 0;
|
|
|
|
base::Timer _autoLockTimer;
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
const std::unique_ptr<Data::Session> _data;
|
2017-04-06 19:02:40 +00:00
|
|
|
const std::unique_ptr<ApiWrap> _api;
|
2017-04-19 09:44:07 +00:00
|
|
|
const std::unique_ptr<Calls::Instance> _calls;
|
2017-03-04 19:36:59 +00:00
|
|
|
const std::unique_ptr<Storage::Downloader> _downloader;
|
2017-08-04 14:54:32 +00:00
|
|
|
const std::unique_ptr<Storage::Uploader> _uploader;
|
2017-09-04 11:40:02 +00:00
|
|
|
const std::unique_ptr<Storage::Facade> _storage;
|
2017-03-04 19:36:59 +00:00
|
|
|
const std::unique_ptr<Window::Notifications::System> _notifications;
|
2017-12-29 18:17:07 +00:00
|
|
|
const std::unique_ptr<Core::Changelogs> _changelogs;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-02-23 09:32:28 +00:00
|
|
|
};
|