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
|
|
|
*/
|
|
|
|
#include "auth_session.h"
|
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
#include "apiwrap.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "messenger.h"
|
2017-12-29 18:17:07 +00:00
|
|
|
#include "core/changelogs.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "storage/file_download.h"
|
2017-08-04 14:54:32 +00:00
|
|
|
#include "storage/file_upload.h"
|
2017-04-09 18:06:06 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-09-04 11:40:02 +00:00
|
|
|
#include "storage/storage_facade.h"
|
2017-05-08 09:08:24 +00:00
|
|
|
#include "storage/serialize_common.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2017-12-29 18:17:07 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2017-04-15 18:48:54 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2017-04-19 09:44:07 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2017-05-24 10:04:29 +00:00
|
|
|
#include "window/section_widget.h"
|
2017-05-24 10:10:04 +00:00
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2017-12-25 11:13:27 +00:00
|
|
|
#include "boxes/send_files_box.h"
|
2017-04-15 18:48:54 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000);
|
|
|
|
|
|
|
|
} // namespace
|
2017-02-23 09:32:28 +00:00
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
AuthSessionSettings::Variables::Variables()
|
2017-12-25 11:13:27 +00:00
|
|
|
: sendFilesWay(SendFilesWay::Album)
|
|
|
|
, selectorTab(ChatHelpers::SelectorTab::Emoji)
|
2017-05-24 10:10:04 +00:00
|
|
|
, floatPlayerColumn(Window::Column::Second)
|
2017-05-24 12:07:58 +00:00
|
|
|
, floatPlayerCorner(RectPart::TopRight) {
|
2017-05-24 10:04:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
QByteArray AuthSessionSettings::serialize() const {
|
2017-09-19 18:59:10 +00:00
|
|
|
auto size = sizeof(qint32) * 10;
|
2017-05-08 09:08:24 +00:00
|
|
|
for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) {
|
|
|
|
size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value());
|
|
|
|
}
|
2017-08-05 14:04:18 +00:00
|
|
|
size += _variables.groupStickersSectionHidden.size() * sizeof(quint64);
|
2017-03-28 12:30:38 +00:00
|
|
|
|
|
|
|
auto result = QByteArray();
|
|
|
|
result.reserve(size);
|
|
|
|
{
|
2017-08-08 18:25:10 +00:00
|
|
|
QDataStream stream(&result, QIODevice::WriteOnly);
|
2017-03-28 12:30:38 +00:00
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
2017-05-24 10:10:04 +00:00
|
|
|
stream << static_cast<qint32>(_variables.selectorTab);
|
2017-03-28 12:30:38 +00:00
|
|
|
stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0);
|
2017-04-09 18:06:06 +00:00
|
|
|
stream << qint32(_variables.tabbedSelectorSectionEnabled ? 1 : 0);
|
2017-05-08 09:08:24 +00:00
|
|
|
stream << qint32(_variables.soundOverrides.size());
|
|
|
|
for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) {
|
|
|
|
stream << i.key() << i.value();
|
|
|
|
}
|
2017-05-17 09:40:03 +00:00
|
|
|
stream << qint32(_variables.tabbedSelectorSectionTooltipShown);
|
2017-05-24 10:04:29 +00:00
|
|
|
stream << qint32(_variables.floatPlayerColumn);
|
|
|
|
stream << qint32(_variables.floatPlayerCorner);
|
2017-08-05 14:04:18 +00:00
|
|
|
stream << qint32(_variables.groupStickersSectionHidden.size());
|
|
|
|
for (auto peerId : _variables.groupStickersSectionHidden) {
|
|
|
|
stream << quint64(peerId);
|
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
stream << qint32(_variables.thirdSectionInfoEnabled ? 1 : 0);
|
2017-09-19 18:59:10 +00:00
|
|
|
stream << qint32(_variables.smallDialogsList ? 1 : 0);
|
2017-11-12 16:50:58 +00:00
|
|
|
stream << qint32(snap(
|
|
|
|
qRound(_variables.dialogsWidthRatio.current() * 1000000),
|
|
|
|
0,
|
|
|
|
1000000));
|
|
|
|
stream << qint32(_variables.thirdColumnWidth.current());
|
2017-11-16 16:43:52 +00:00
|
|
|
stream << qint32(_variables.thirdSectionExtendedBy);
|
2017-12-25 11:13:27 +00:00
|
|
|
stream << qint32(_variables.sendFilesWay);
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) {
|
2017-03-28 12:30:38 +00:00
|
|
|
if (serialized.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-08 18:25:10 +00:00
|
|
|
QDataStream stream(serialized);
|
2017-03-28 12:30:38 +00:00
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
2017-05-24 10:10:04 +00:00
|
|
|
qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
|
2017-03-28 12:30:38 +00:00
|
|
|
qint32 lastSeenWarningSeen = 0;
|
2017-04-09 18:06:06 +00:00
|
|
|
qint32 tabbedSelectorSectionEnabled = 1;
|
2017-05-17 09:40:03 +00:00
|
|
|
qint32 tabbedSelectorSectionTooltipShown = 0;
|
2017-05-24 10:04:29 +00:00
|
|
|
qint32 floatPlayerColumn = static_cast<qint32>(Window::Column::Second);
|
2017-05-24 12:07:58 +00:00
|
|
|
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
|
2017-05-08 09:08:24 +00:00
|
|
|
QMap<QString, QString> soundOverrides;
|
2017-09-16 16:53:41 +00:00
|
|
|
base::flat_set<PeerId> groupStickersSectionHidden;
|
|
|
|
qint32 thirdSectionInfoEnabled = 0;
|
2017-09-19 18:59:10 +00:00
|
|
|
qint32 smallDialogsList = 0;
|
2017-11-05 13:57:51 +00:00
|
|
|
float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current();
|
2017-11-12 16:50:58 +00:00
|
|
|
int thirdColumnWidth = _variables.thirdColumnWidth.current();
|
2017-11-16 16:43:52 +00:00
|
|
|
int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy;
|
2017-12-25 11:13:27 +00:00
|
|
|
qint32 sendFilesWay = static_cast<qint32>(_variables.sendFilesWay);
|
2017-05-24 10:10:04 +00:00
|
|
|
stream >> selectorTab;
|
2017-03-28 12:30:38 +00:00
|
|
|
stream >> lastSeenWarningSeen;
|
2017-04-09 18:06:06 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> tabbedSelectorSectionEnabled;
|
|
|
|
}
|
2017-05-08 09:08:24 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
QString key, value;
|
|
|
|
stream >> key >> value;
|
|
|
|
soundOverrides[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 09:40:03 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> tabbedSelectorSectionTooltipShown;
|
|
|
|
}
|
2017-05-24 10:04:29 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> floatPlayerColumn >> floatPlayerCorner;
|
|
|
|
}
|
2017-08-05 14:04:18 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
quint64 peerId;
|
|
|
|
stream >> peerId;
|
|
|
|
groupStickersSectionHidden.insert(peerId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> thirdSectionInfoEnabled;
|
2017-09-19 18:59:10 +00:00
|
|
|
stream >> smallDialogsList;
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
2017-11-05 13:57:51 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
qint32 value = 0;
|
|
|
|
stream >> value;
|
|
|
|
dialogsWidthRatio = snap(value / 1000000., 0., 1.);
|
2017-11-12 16:50:58 +00:00
|
|
|
|
|
|
|
stream >> value;
|
|
|
|
thirdColumnWidth = value;
|
2017-11-16 16:43:52 +00:00
|
|
|
|
|
|
|
stream >> value;
|
|
|
|
thirdSectionExtendedBy = value;
|
2017-11-05 13:57:51 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
2018-01-04 10:22:53 +00:00
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for AuthSessionSettings::constructFromSerialized()"));
|
2017-03-28 12:30:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-24 10:10:04 +00:00
|
|
|
auto uncheckedTab = static_cast<ChatHelpers::SelectorTab>(selectorTab);
|
2017-03-28 12:30:38 +00:00
|
|
|
switch (uncheckedTab) {
|
2017-05-24 10:10:04 +00:00
|
|
|
case ChatHelpers::SelectorTab::Emoji:
|
|
|
|
case ChatHelpers::SelectorTab::Stickers:
|
|
|
|
case ChatHelpers::SelectorTab::Gifs: _variables.selectorTab = uncheckedTab; break;
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
|
|
|
_variables.lastSeenWarningSeen = (lastSeenWarningSeen == 1);
|
2017-04-09 18:06:06 +00:00
|
|
|
_variables.tabbedSelectorSectionEnabled = (tabbedSelectorSectionEnabled == 1);
|
2017-05-08 09:08:24 +00:00
|
|
|
_variables.soundOverrides = std::move(soundOverrides);
|
2017-05-17 09:40:03 +00:00
|
|
|
_variables.tabbedSelectorSectionTooltipShown = tabbedSelectorSectionTooltipShown;
|
2017-05-24 10:04:29 +00:00
|
|
|
auto uncheckedColumn = static_cast<Window::Column>(floatPlayerColumn);
|
|
|
|
switch (uncheckedColumn) {
|
|
|
|
case Window::Column::First:
|
|
|
|
case Window::Column::Second:
|
|
|
|
case Window::Column::Third: _variables.floatPlayerColumn = uncheckedColumn; break;
|
|
|
|
}
|
2017-05-24 12:07:58 +00:00
|
|
|
auto uncheckedCorner = static_cast<RectPart>(floatPlayerCorner);
|
2017-05-24 10:04:29 +00:00
|
|
|
switch (uncheckedCorner) {
|
2017-05-24 12:07:58 +00:00
|
|
|
case RectPart::TopLeft:
|
|
|
|
case RectPart::TopRight:
|
|
|
|
case RectPart::BottomLeft:
|
|
|
|
case RectPart::BottomRight: _variables.floatPlayerCorner = uncheckedCorner; break;
|
2017-05-24 10:04:29 +00:00
|
|
|
}
|
2017-08-05 14:04:18 +00:00
|
|
|
_variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden);
|
2017-09-16 16:53:41 +00:00
|
|
|
_variables.thirdSectionInfoEnabled = thirdSectionInfoEnabled;
|
2017-09-19 18:59:10 +00:00
|
|
|
_variables.smallDialogsList = smallDialogsList;
|
2017-11-05 13:57:51 +00:00
|
|
|
_variables.dialogsWidthRatio = dialogsWidthRatio;
|
2017-11-12 16:50:58 +00:00
|
|
|
_variables.thirdColumnWidth = thirdColumnWidth;
|
2017-11-16 16:43:52 +00:00
|
|
|
_variables.thirdSectionExtendedBy = thirdSectionExtendedBy;
|
2017-09-20 19:44:22 +00:00
|
|
|
if (_variables.thirdSectionInfoEnabled) {
|
|
|
|
_variables.tabbedSelectorSectionEnabled = false;
|
|
|
|
}
|
2017-12-25 11:13:27 +00:00
|
|
|
auto uncheckedSendFilesWay = static_cast<SendFilesWay>(sendFilesWay);
|
|
|
|
switch (uncheckedSendFilesWay) {
|
|
|
|
case SendFilesWay::Album:
|
|
|
|
case SendFilesWay::Photos:
|
|
|
|
case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay;
|
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) {
|
2017-09-16 16:53:41 +00:00
|
|
|
_variables.tabbedSelectorSectionEnabled = enabled;
|
|
|
|
if (enabled) {
|
|
|
|
setThirdSectionInfoEnabled(false);
|
|
|
|
}
|
2017-09-19 19:44:34 +00:00
|
|
|
setTabbedReplacedWithInfo(false);
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
rpl::producer<bool> AuthSessionSettings::tabbedReplacedWithInfoValue() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _tabbedReplacedWithInfoValue.events_starting_with(
|
|
|
|
tabbedReplacedWithInfo());
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::setThirdSectionInfoEnabled(bool enabled) {
|
2017-09-16 16:53:41 +00:00
|
|
|
if (_variables.thirdSectionInfoEnabled != enabled) {
|
|
|
|
_variables.thirdSectionInfoEnabled = enabled;
|
|
|
|
if (enabled) {
|
|
|
|
setTabbedSelectorSectionEnabled(false);
|
|
|
|
}
|
2017-09-19 19:44:34 +00:00
|
|
|
setTabbedReplacedWithInfo(false);
|
2017-09-16 16:53:41 +00:00
|
|
|
_thirdSectionInfoEnabledValue.fire_copy(enabled);
|
|
|
|
}
|
2017-05-08 09:08:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
rpl::producer<bool> AuthSessionSettings::thirdSectionInfoEnabledValue() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _thirdSectionInfoEnabledValue.events_starting_with(
|
|
|
|
thirdSectionInfoEnabled());
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::setTabbedReplacedWithInfo(bool enabled) {
|
2017-09-19 19:44:34 +00:00
|
|
|
if (_tabbedReplacedWithInfo != enabled) {
|
|
|
|
_tabbedReplacedWithInfo = enabled;
|
|
|
|
_tabbedReplacedWithInfoValue.fire_copy(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
QString AuthSessionSettings::getSoundPath(const QString &key) const {
|
2017-05-08 09:08:24 +00:00
|
|
|
auto it = _variables.soundOverrides.constFind(key);
|
|
|
|
if (it != _variables.soundOverrides.end()) {
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
return qsl(":/sounds/") + key + qsl(".mp3");
|
2017-03-28 12:30:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::setDialogsWidthRatio(float64 ratio) {
|
2017-11-21 09:20:56 +00:00
|
|
|
_variables.dialogsWidthRatio = ratio;
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
float64 AuthSessionSettings::dialogsWidthRatio() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _variables.dialogsWidthRatio.current();
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
rpl::producer<float64> AuthSessionSettings::dialogsWidthRatioChanges() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _variables.dialogsWidthRatio.changes();
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSessionSettings::setThirdColumnWidth(int width) {
|
2017-11-21 09:20:56 +00:00
|
|
|
_variables.thirdColumnWidth = width;
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
int AuthSessionSettings::thirdColumnWidth() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _variables.thirdColumnWidth.current();
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
rpl::producer<int> AuthSessionSettings::thirdColumnWidthChanges() const {
|
2017-11-21 09:20:56 +00:00
|
|
|
return _variables.thirdColumnWidth.changes();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
AuthSession &Auth() {
|
|
|
|
auto result = Messenger::Instance().authSession();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(result != nullptr);
|
2017-08-04 14:54:32 +00:00
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
AuthSession::AuthSession(UserId userId)
|
|
|
|
: _userId(userId)
|
2017-04-15 21:45:25 +00:00
|
|
|
, _autoLockTimer([this] { checkAutoLock(); })
|
2017-06-05 13:33:45 +00:00
|
|
|
, _api(std::make_unique<ApiWrap>(this))
|
2017-04-19 09:44:07 +00:00
|
|
|
, _calls(std::make_unique<Calls::Instance>())
|
2017-03-04 19:36:59 +00:00
|
|
|
, _downloader(std::make_unique<Storage::Downloader>())
|
2017-08-04 14:54:32 +00:00
|
|
|
, _uploader(std::make_unique<Storage::Uploader>())
|
2017-09-04 11:40:02 +00:00
|
|
|
, _storage(std::make_unique<Storage::Facade>())
|
2017-12-29 18:17:07 +00:00
|
|
|
, _notifications(std::make_unique<Window::Notifications::System>(this))
|
2018-02-18 13:26:28 +00:00
|
|
|
, _data(std::make_unique<Data::Session>(this))
|
|
|
|
, _changelogs(Core::Changelogs::Create(this)) {
|
2017-03-28 12:30:38 +00:00
|
|
|
Expects(_userId != 0);
|
2017-12-29 18:17:07 +00:00
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
_saveDataTimer.setCallback([=] {
|
2017-04-09 18:06:06 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
});
|
2018-04-07 08:47:08 +00:00
|
|
|
subscribe(Messenger::Instance().passcodedChanged(), [=] {
|
2017-04-15 18:48:54 +00:00
|
|
|
_shouldLockAt = 0;
|
|
|
|
notifications().updateAll();
|
|
|
|
});
|
2018-05-11 14:03:53 +00:00
|
|
|
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
|
|
|
_api->refreshProxyPromotion();
|
|
|
|
});
|
2018-05-15 16:38:27 +00:00
|
|
|
_api->refreshProxyPromotion();
|
|
|
|
|
2017-12-29 18:17:07 +00:00
|
|
|
Window::Theme::Background()->start();
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
bool AuthSession::Exists() {
|
2017-04-14 12:12:40 +00:00
|
|
|
if (auto messenger = Messenger::InstancePointer()) {
|
|
|
|
return (messenger->authSession() != nullptr);
|
|
|
|
}
|
|
|
|
return false;
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
UserData *AuthSession::user() const {
|
|
|
|
return App::user(userId());
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
base::Observable<void> &AuthSession::downloaderTaskFinished() {
|
|
|
|
return downloader().taskFinished();
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AuthSession::validateSelf(const MTPUser &user) {
|
2018-05-13 08:42:25 +00:00
|
|
|
if (user.type() != mtpc_user || !user.c_user().is_self()) {
|
|
|
|
LOG(("API Error: bad self user received."));
|
|
|
|
return false;
|
|
|
|
} else if (user.c_user().vid.v != userId()) {
|
2017-03-04 19:36:59 +00:00
|
|
|
LOG(("Auth Error: wrong self user received."));
|
|
|
|
App::logOutDelayed();
|
|
|
|
return false;
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
return true;
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void AuthSession::saveSettingsDelayed(TimeMs delay) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Expects(this == &Auth());
|
2018-05-13 08:42:25 +00:00
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
_saveDataTimer.callOnce(delay);
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:48:54 +00:00
|
|
|
void AuthSession::checkAutoLock() {
|
|
|
|
if (!Global::LocalPasscode() || App::passcoded()) return;
|
|
|
|
|
|
|
|
Messenger::Instance().checkLocalTime();
|
|
|
|
auto now = getms(true);
|
|
|
|
auto shouldLockInMs = Global::AutoLock() * 1000LL;
|
|
|
|
auto idleForMs = psIdleTime();
|
2018-01-04 10:22:53 +00:00
|
|
|
auto notPlayingVideoForMs = now - settings().lastTimeVideoPlayedAt();
|
2017-04-15 18:48:54 +00:00
|
|
|
auto checkTimeMs = qMin(idleForMs, notPlayingVideoForMs);
|
|
|
|
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
|
|
|
|
Messenger::Instance().setupPasscode();
|
|
|
|
} else {
|
|
|
|
_shouldLockAt = now + (shouldLockInMs - checkTimeMs);
|
|
|
|
_autoLockTimer.callOnce(shouldLockInMs - checkTimeMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AuthSession::checkAutoLockIn(TimeMs time) {
|
|
|
|
if (_autoLockTimer.isActive()) {
|
|
|
|
auto remain = _autoLockTimer.remainingTime();
|
|
|
|
if (remain > 0 && remain <= time) return;
|
|
|
|
}
|
|
|
|
_autoLockTimer.callOnce(time);
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
AuthSession::~AuthSession() = default;
|