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"
|
2018-11-30 12:49:30 +00:00
|
|
|
#include "data/data_auto_download.h"
|
2017-04-09 18:06:06 +00:00
|
|
|
|
2017-12-25 11:13:27 +00:00
|
|
|
class ApiWrap;
|
|
|
|
enum class SendFilesWay;
|
|
|
|
|
2018-09-29 12:18:26 +00:00
|
|
|
namespace Ui {
|
|
|
|
enum class InputSubmitSettings;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Support {
|
|
|
|
enum class SwitchSettings;
|
2018-11-15 15:36:04 +00:00
|
|
|
class Helper;
|
2018-10-02 20:39:54 +00:00
|
|
|
class Templates;
|
2018-09-29 12:18:26 +00:00
|
|
|
} // namespace Support
|
|
|
|
|
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;
|
|
|
|
}
|
2018-09-29 12:18:26 +00:00
|
|
|
void setSendSubmitWay(Ui::InputSubmitSettings value) {
|
|
|
|
_variables.sendSubmitWay = value;
|
|
|
|
}
|
|
|
|
Ui::InputSubmitSettings sendSubmitWay() const {
|
|
|
|
return _variables.sendSubmitWay;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSupportSwitch(Support::SwitchSettings value) {
|
|
|
|
_variables.supportSwitch = value;
|
|
|
|
}
|
|
|
|
Support::SwitchSettings supportSwitch() const {
|
|
|
|
return _variables.supportSwitch;
|
|
|
|
}
|
|
|
|
void setSupportFixChatsOrder(bool fix) {
|
|
|
|
_variables.supportFixChatsOrder = fix;
|
|
|
|
}
|
|
|
|
bool supportFixChatsOrder() const {
|
|
|
|
return _variables.supportFixChatsOrder;
|
|
|
|
}
|
2018-10-11 11:17:51 +00:00
|
|
|
void setSupportTemplatesAutocomplete(bool enabled) {
|
|
|
|
_variables.supportTemplatesAutocomplete = enabled;
|
|
|
|
}
|
|
|
|
bool supportTemplatesAutocomplete() const {
|
|
|
|
return _variables.supportTemplatesAutocomplete;
|
|
|
|
}
|
2018-11-09 13:54:34 +00:00
|
|
|
void setSupportChatsTimeSlice(int slice);
|
|
|
|
int supportChatsTimeSlice() const;
|
|
|
|
rpl::producer<int> supportChatsTimeSliceValue() const;
|
2018-12-30 08:40:25 +00:00
|
|
|
void setSupportAllSearchResults(bool all);
|
|
|
|
bool supportAllSearchResults() const;
|
|
|
|
rpl::producer<bool> supportAllSearchResultsValue() const;
|
2018-09-29 12:18:26 +00:00
|
|
|
|
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-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
|
|
|
|
2018-11-30 12:49:30 +00:00
|
|
|
Data::AutoDownload::Full &autoDownload() {
|
|
|
|
return _variables.autoDownload;
|
|
|
|
}
|
|
|
|
const Data::AutoDownload::Full &autoDownload() const {
|
|
|
|
return _variables.autoDownload;
|
|
|
|
}
|
|
|
|
|
2018-11-04 16:51:59 +00:00
|
|
|
bool hadLegacyCallsPeerToPeerNobody() const {
|
|
|
|
return _variables.hadLegacyCallsPeerToPeerNobody;
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:32:06 +00:00
|
|
|
bool includeMutedCounter() const {
|
|
|
|
return _variables.includeMutedCounter;
|
|
|
|
}
|
|
|
|
void setIncludeMutedCounter(bool value) {
|
|
|
|
_variables.includeMutedCounter = value;
|
|
|
|
}
|
|
|
|
bool countUnreadMessages() const {
|
|
|
|
return _variables.countUnreadMessages;
|
|
|
|
}
|
|
|
|
void setCountUnreadMessages(bool value) {
|
|
|
|
_variables.countUnreadMessages = value;
|
|
|
|
}
|
2018-12-05 08:07:17 +00:00
|
|
|
bool exeLaunchWarning() const {
|
|
|
|
return _variables.exeLaunchWarning;
|
|
|
|
}
|
|
|
|
void setExeLaunchWarning(bool warning) {
|
|
|
|
_variables.exeLaunchWarning = warning;
|
|
|
|
}
|
2018-12-04 10:32:06 +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
|
2018-09-29 12:18:26 +00:00
|
|
|
Ui::InputSubmitSettings sendSubmitWay;
|
2018-11-04 16:51:59 +00:00
|
|
|
bool hadLegacyCallsPeerToPeerNobody = false;
|
2018-12-04 10:32:06 +00:00
|
|
|
bool includeMutedCounter = true;
|
|
|
|
bool countUnreadMessages = true;
|
2018-12-05 08:07:17 +00:00
|
|
|
bool exeLaunchWarning = true;
|
2018-11-30 12:49:30 +00:00
|
|
|
Data::AutoDownload::Full autoDownload;
|
2018-09-29 12:18:26 +00:00
|
|
|
|
2018-11-09 13:54:34 +00:00
|
|
|
static constexpr auto kDefaultSupportChatsLimitSlice
|
2018-11-21 06:43:07 +00:00
|
|
|
= 7 * 24 * 60 * 60;
|
2018-11-09 13:54:34 +00:00
|
|
|
|
2018-09-29 12:18:26 +00:00
|
|
|
Support::SwitchSettings supportSwitch;
|
|
|
|
bool supportFixChatsOrder = true;
|
2018-10-11 11:17:51 +00:00
|
|
|
bool supportTemplatesAutocomplete = true;
|
2018-11-09 13:54:34 +00:00
|
|
|
rpl::variable<int> supportChatsTimeSlice
|
|
|
|
= kDefaultSupportChatsLimitSlice;
|
2018-12-30 08:40:25 +00:00
|
|
|
rpl::variable<bool> supportAllSearchResults = false;
|
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-08-04 14:54:32 +00:00
|
|
|
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:
|
2018-09-11 12:50:40 +00:00
|
|
|
AuthSession(const MTPUser &user);
|
2017-02-23 09:32:28 +00:00
|
|
|
|
|
|
|
AuthSession(const AuthSession &other) = delete;
|
|
|
|
AuthSession &operator=(const AuthSession &other) = delete;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
static bool Exists();
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
UserId userId() const;
|
|
|
|
PeerId userPeerId() const;
|
2018-09-11 12:50:40 +00:00
|
|
|
not_null<UserData*> user() const {
|
|
|
|
return _user;
|
2017-08-04 14:54:32 +00:00
|
|
|
}
|
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-11-04 16:51:59 +00:00
|
|
|
void moveSettingsFrom(AuthSessionSettings &&other);
|
2019-02-19 06:57:53 +00:00
|
|
|
void saveSettingsDelayed(crl::time 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();
|
2019-02-19 06:57:53 +00:00
|
|
|
void checkAutoLockIn(crl::time time);
|
2019-03-04 18:40:21 +00:00
|
|
|
void localPasscodeChanged();
|
2017-04-15 18:48:54 +00:00
|
|
|
|
2018-09-06 11:13:54 +00:00
|
|
|
rpl::lifetime &lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-09-28 11:56:21 +00:00
|
|
|
bool supportMode() const;
|
2018-11-15 15:36:04 +00:00
|
|
|
Support::Helper &supportHelper() const;
|
|
|
|
Support::Templates &supportTemplates() const;
|
2018-09-28 11:56:21 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
~AuthSession();
|
2017-02-23 09:32:28 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-19 06:57:53 +00:00
|
|
|
static constexpr auto kDefaultSaveDelay = crl::time(1000);
|
2017-09-30 18:26:45 +00:00
|
|
|
|
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
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _shouldLockAt = 0;
|
2017-04-15 18:48:54 +00:00
|
|
|
base::Timer _autoLockTimer;
|
|
|
|
|
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;
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
// _data depends on _downloader / _uploader / _notifications.
|
2018-01-27 09:21:57 +00:00
|
|
|
const std::unique_ptr<Data::Session> _data;
|
2019-01-03 12:36:01 +00:00
|
|
|
const not_null<UserData*> _user;
|
2018-01-27 09:21:57 +00:00
|
|
|
|
2018-02-18 13:26:28 +00:00
|
|
|
// _changelogs depends on _data, subscribes on chats loading event.
|
|
|
|
const std::unique_ptr<Core::Changelogs> _changelogs;
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
const std::unique_ptr<Support::Helper> _supportHelper;
|
2018-10-02 20:39:54 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-02-23 09:32:28 +00:00
|
|
|
};
|