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"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.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"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.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"
|
2018-09-29 12:18:26 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
|
|
|
#include "support/support_common.h"
|
2018-11-15 15:36:04 +00:00
|
|
|
#include "support/support_helper.h"
|
2018-09-11 14:36:09 +00:00
|
|
|
#include "observer_peer.h"
|
2017-04-15 18:48:54 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
2018-11-04 16:51:59 +00:00
|
|
|
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
2017-04-15 18:48:54 +00:00
|
|
|
|
|
|
|
} // 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)
|
2018-09-29 12:18:26 +00:00
|
|
|
, floatPlayerCorner(RectPart::TopRight)
|
|
|
|
, sendSubmitWay(Ui::InputSubmitSettings::Enter)
|
2018-10-11 11:17:51 +00:00
|
|
|
, supportSwitch(Support::SwitchSettings::Next) {
|
2017-05-24 10:04:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
QByteArray AuthSessionSettings::serialize() const {
|
2018-11-30 12:49:30 +00:00
|
|
|
const auto autoDownload = _variables.autoDownload.serialize();
|
2018-12-05 08:07:17 +00:00
|
|
|
auto size = sizeof(qint32) * 23;
|
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);
|
2018-11-30 12:49:30 +00:00
|
|
|
size += Serialize::bytearraySize(autoDownload);
|
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);
|
2018-11-04 16:51:59 +00:00
|
|
|
stream << qint32(0);// LEGACY _variables.callsPeerToPeer.current());
|
2018-09-29 12:18:26 +00:00
|
|
|
stream << qint32(_variables.sendSubmitWay);
|
|
|
|
stream << qint32(_variables.supportSwitch);
|
|
|
|
stream << qint32(_variables.supportFixChatsOrder ? 1 : 0);
|
2018-10-11 11:17:51 +00:00
|
|
|
stream << qint32(_variables.supportTemplatesAutocomplete ? 1 : 0);
|
2018-11-09 13:54:34 +00:00
|
|
|
stream << qint32(_variables.supportChatsTimeSlice.current());
|
2018-12-04 10:32:06 +00:00
|
|
|
stream << qint32(_variables.includeMutedCounter ? 1 : 0);
|
|
|
|
stream << qint32(_variables.countUnreadMessages ? 1 : 0);
|
2018-12-05 08:07:17 +00:00
|
|
|
stream << qint32(_variables.exeLaunchWarning ? 1 : 0);
|
2018-11-30 12:49:30 +00:00
|
|
|
stream << autoDownload;
|
2018-12-30 08:40:25 +00:00
|
|
|
stream << qint32(_variables.supportAllSearchResults.current() ? 1 : 0);
|
2019-05-03 10:55:44 +00:00
|
|
|
stream << qint32(_variables.archiveCollapsed.current() ? 1 : 0);
|
2019-05-28 14:53:36 +00:00
|
|
|
stream << qint32(_variables.notifyAboutPinned.current() ? 1 : 0);
|
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);
|
2018-11-04 16:51:59 +00:00
|
|
|
qint32 legacyCallsPeerToPeer = qint32(0);
|
2018-09-29 12:18:26 +00:00
|
|
|
qint32 sendSubmitWay = static_cast<qint32>(_variables.sendSubmitWay);
|
|
|
|
qint32 supportSwitch = static_cast<qint32>(_variables.supportSwitch);
|
|
|
|
qint32 supportFixChatsOrder = _variables.supportFixChatsOrder ? 1 : 0;
|
2018-10-11 11:17:51 +00:00
|
|
|
qint32 supportTemplatesAutocomplete = _variables.supportTemplatesAutocomplete ? 1 : 0;
|
2018-11-09 13:54:34 +00:00
|
|
|
qint32 supportChatsTimeSlice = _variables.supportChatsTimeSlice.current();
|
2018-12-04 10:32:06 +00:00
|
|
|
qint32 includeMutedCounter = _variables.includeMutedCounter ? 1 : 0;
|
|
|
|
qint32 countUnreadMessages = _variables.countUnreadMessages ? 1 : 0;
|
2018-12-05 08:07:17 +00:00
|
|
|
qint32 exeLaunchWarning = _variables.exeLaunchWarning ? 1 : 0;
|
2018-11-30 12:49:30 +00:00
|
|
|
QByteArray autoDownload;
|
2018-12-30 08:40:25 +00:00
|
|
|
qint32 supportAllSearchResults = _variables.supportAllSearchResults.current() ? 1 : 0;
|
2019-05-03 10:55:44 +00:00
|
|
|
qint32 archiveCollapsed = _variables.archiveCollapsed.current() ? 1 : 0;
|
2019-05-28 14:53:36 +00:00
|
|
|
qint32 notifyAboutPinned = _variables.notifyAboutPinned.current() ? 1 : 0;
|
2018-09-29 12:18:26 +00:00
|
|
|
|
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
|
|
|
}
|
2018-09-12 17:02:30 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> sendFilesWay;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
2018-11-04 16:51:59 +00:00
|
|
|
stream >> legacyCallsPeerToPeer;
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
2018-09-29 12:18:26 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> sendSubmitWay;
|
|
|
|
stream >> supportSwitch;
|
|
|
|
stream >> supportFixChatsOrder;
|
|
|
|
}
|
2018-10-11 11:17:51 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportTemplatesAutocomplete;
|
|
|
|
}
|
2018-11-09 13:54:34 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportChatsTimeSlice;
|
|
|
|
}
|
2018-12-04 10:32:06 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> includeMutedCounter;
|
|
|
|
stream >> countUnreadMessages;
|
|
|
|
}
|
2018-12-05 08:07:17 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> exeLaunchWarning;
|
|
|
|
}
|
2018-11-30 12:49:30 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> autoDownload;
|
|
|
|
}
|
2018-12-30 08:40:25 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportAllSearchResults;
|
|
|
|
}
|
2019-05-03 10:55:44 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> archiveCollapsed;
|
|
|
|
}
|
2019-05-28 14:53:36 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> notifyAboutPinned;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2018-11-30 12:49:30 +00:00
|
|
|
if (!autoDownload.isEmpty()
|
|
|
|
&& !_variables.autoDownload.setFromSerialized(autoDownload)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
|
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:
|
2018-09-12 17:02:30 +00:00
|
|
|
case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay; break;
|
|
|
|
}
|
2018-09-29 12:18:26 +00:00
|
|
|
auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
|
|
|
|
sendSubmitWay);
|
|
|
|
switch (uncheckedSendSubmitWay) {
|
|
|
|
case Ui::InputSubmitSettings::Enter:
|
|
|
|
case Ui::InputSubmitSettings::CtrlEnter: _variables.sendSubmitWay = uncheckedSendSubmitWay; break;
|
|
|
|
}
|
|
|
|
auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>(
|
|
|
|
supportSwitch);
|
|
|
|
switch (uncheckedSupportSwitch) {
|
|
|
|
case Support::SwitchSettings::None:
|
|
|
|
case Support::SwitchSettings::Next:
|
|
|
|
case Support::SwitchSettings::Previous: _variables.supportSwitch = uncheckedSupportSwitch; break;
|
|
|
|
}
|
2018-10-11 11:17:51 +00:00
|
|
|
_variables.supportFixChatsOrder = (supportFixChatsOrder == 1);
|
|
|
|
_variables.supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1);
|
2018-11-09 13:54:34 +00:00
|
|
|
_variables.supportChatsTimeSlice = supportChatsTimeSlice;
|
2018-11-04 16:51:59 +00:00
|
|
|
_variables.hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody);
|
2018-12-04 10:32:06 +00:00
|
|
|
_variables.includeMutedCounter = (includeMutedCounter == 1);
|
|
|
|
_variables.countUnreadMessages = (countUnreadMessages == 1);
|
2018-12-05 08:07:17 +00:00
|
|
|
_variables.exeLaunchWarning = (exeLaunchWarning == 1);
|
2018-12-30 08:40:25 +00:00
|
|
|
_variables.supportAllSearchResults = (supportAllSearchResults == 1);
|
2019-05-03 10:55:44 +00:00
|
|
|
_variables.archiveCollapsed = (archiveCollapsed == 1);
|
2019-05-28 14:53:36 +00:00
|
|
|
_variables.notifyAboutPinned = (notifyAboutPinned == 1);
|
2018-11-09 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AuthSessionSettings::setSupportChatsTimeSlice(int slice) {
|
|
|
|
_variables.supportChatsTimeSlice = slice;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AuthSessionSettings::supportChatsTimeSlice() const {
|
|
|
|
return _variables.supportChatsTimeSlice.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> AuthSessionSettings::supportChatsTimeSliceValue() const {
|
|
|
|
return _variables.supportChatsTimeSlice.value();
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 08:40:25 +00:00
|
|
|
void AuthSessionSettings::setSupportAllSearchResults(bool all) {
|
|
|
|
_variables.supportAllSearchResults = all;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AuthSessionSettings::supportAllSearchResults() const {
|
|
|
|
return _variables.supportAllSearchResults.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> AuthSessionSettings::supportAllSearchResultsValue() const {
|
|
|
|
return _variables.supportAllSearchResults.value();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-05-03 10:55:44 +00:00
|
|
|
void AuthSessionSettings::setArchiveCollapsed(bool collapsed) {
|
|
|
|
_variables.archiveCollapsed = collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AuthSessionSettings::archiveCollapsed() const {
|
|
|
|
return _variables.archiveCollapsed.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> AuthSessionSettings::archiveCollapsedChanges() const {
|
|
|
|
return _variables.archiveCollapsed.changes();
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:53:36 +00:00
|
|
|
void AuthSessionSettings::setNotifyAboutPinned(bool notify) {
|
|
|
|
_variables.notifyAboutPinned = notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AuthSessionSettings::notifyAboutPinned() const {
|
|
|
|
return _variables.notifyAboutPinned.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> AuthSessionSettings::notifyAboutPinnedChanges() const {
|
|
|
|
return _variables.notifyAboutPinned.changes();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
AuthSession &Auth() {
|
2019-05-03 10:55:44 +00:00
|
|
|
const auto result = Core::App().authSession();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(result != nullptr);
|
2017-08-04 14:54:32 +00:00
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
AuthSession::AuthSession(const MTPUser &user)
|
2019-01-03 12:36:01 +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))
|
2019-01-18 12:27:37 +00:00
|
|
|
, _user(_data->processUser(user))
|
2018-10-02 20:39:54 +00:00
|
|
|
, _changelogs(Core::Changelogs::Create(this))
|
2019-01-03 12:36:01 +00:00
|
|
|
, _supportHelper(Support::Helper::Create(this)) {
|
2019-04-16 16:28:41 +00:00
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
_saveDataTimer.setCallback([=] {
|
2017-04-09 18:06:06 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
});
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().passcodeLockChanges(
|
2018-06-03 13:30:40 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2017-04-15 18:48:54 +00:00
|
|
|
_shouldLockAt = 0;
|
2018-06-03 13:30:40 +00:00
|
|
|
}, _lifetime);
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().lockChanges(
|
2018-06-03 13:30:40 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2017-04-15 18:48:54 +00:00
|
|
|
notifications().updateAll();
|
2018-06-03 13:30:40 +00:00
|
|
|
}, _lifetime);
|
2018-05-11 14:03:53 +00:00
|
|
|
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
|
|
|
_api->refreshProxyPromotion();
|
|
|
|
});
|
2018-05-15 16:38:27 +00:00
|
|
|
_api->refreshProxyPromotion();
|
2018-06-03 13:30:40 +00:00
|
|
|
_api->requestTermsUpdate();
|
2018-09-11 12:50:40 +00:00
|
|
|
_api->requestFullPeer(_user);
|
2018-05-15 16:38:27 +00:00
|
|
|
|
2018-09-11 14:36:09 +00:00
|
|
|
crl::on_main(this, [=] {
|
|
|
|
using Flag = Notify::PeerUpdate::Flag;
|
|
|
|
const auto events = Flag::NameChanged
|
|
|
|
| Flag::UsernameChanged
|
|
|
|
| Flag::PhotoChanged
|
|
|
|
| Flag::AboutChanged
|
|
|
|
| Flag::UserPhoneChanged;
|
|
|
|
subscribe(
|
|
|
|
Notify::PeerUpdated(),
|
|
|
|
Notify::PeerUpdatedHandler(
|
|
|
|
events,
|
|
|
|
[=](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer == _user) {
|
|
|
|
Local::writeSelf();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
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() {
|
2019-02-04 13:34:50 +00:00
|
|
|
return Core::IsAppLaunched() && (Core::App().authSession() != nullptr);
|
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
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
UserId AuthSession::userId() const {
|
|
|
|
return _user->bareId();
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerId AuthSession::userPeerId() const {
|
|
|
|
return _user->id;
|
|
|
|
}
|
|
|
|
|
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."));
|
2019-01-21 13:42:21 +00:00
|
|
|
crl::on_main(this, [] { Core::App().logOut(); });
|
2017-03-04 19:36:59 +00:00
|
|
|
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-11-04 16:51:59 +00:00
|
|
|
void AuthSession::moveSettingsFrom(AuthSessionSettings &&other) {
|
|
|
|
_settings.moveFrom(std::move(other));
|
|
|
|
if (_settings.hadLegacyCallsPeerToPeerNobody()) {
|
|
|
|
api().savePrivacy(
|
|
|
|
MTP_inputPrivacyKeyPhoneP2P(),
|
|
|
|
QVector<MTPInputPrivacyRule>(
|
|
|
|
1,
|
|
|
|
MTP_inputPrivacyValueDisallowAll()));
|
|
|
|
saveSettingsDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void AuthSession::saveSettingsDelayed(crl::time 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);
|
|
|
|
}
|
|
|
|
|
2019-03-04 18:40:21 +00:00
|
|
|
void AuthSession::localPasscodeChanged() {
|
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
|
|
|
checkAutoLock();
|
|
|
|
}
|
|
|
|
|
2019-03-27 08:37:25 +00:00
|
|
|
void AuthSession::termsDeleteNow() {
|
|
|
|
api().request(MTPaccount_DeleteAccount(
|
|
|
|
MTP_string("Decline ToS update")
|
|
|
|
)).send();
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:48:54 +00:00
|
|
|
void AuthSession::checkAutoLock() {
|
2018-06-03 13:30:40 +00:00
|
|
|
if (!Global::LocalPasscode()
|
2019-01-21 13:42:21 +00:00
|
|
|
|| Core::App().passcodeLocked()) {
|
2019-03-04 18:40:21 +00:00
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
2018-06-03 13:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-04-15 18:48:54 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().checkLocalTime();
|
2019-03-09 17:10:51 +00:00
|
|
|
const auto now = crl::now();
|
|
|
|
const auto shouldLockInMs = Global::AutoLock() * 1000LL;
|
|
|
|
const auto checkTimeMs = now - Core::App().lastNonIdleTime();
|
2017-04-15 18:48:54 +00:00
|
|
|
if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
|
2019-03-04 18:40:21 +00:00
|
|
|
_shouldLockAt = 0;
|
|
|
|
_autoLockTimer.cancel();
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().lockByPasscode();
|
2017-04-15 18:48:54 +00:00
|
|
|
} else {
|
|
|
|
_shouldLockAt = now + (shouldLockInMs - checkTimeMs);
|
|
|
|
_autoLockTimer.callOnce(shouldLockInMs - checkTimeMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void AuthSession::checkAutoLockIn(crl::time time) {
|
2017-04-15 18:48:54 +00:00
|
|
|
if (_autoLockTimer.isActive()) {
|
|
|
|
auto remain = _autoLockTimer.remainingTime();
|
|
|
|
if (remain > 0 && remain <= time) return;
|
|
|
|
}
|
|
|
|
_autoLockTimer.callOnce(time);
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:56:21 +00:00
|
|
|
bool AuthSession::supportMode() const {
|
2018-11-15 15:36:04 +00:00
|
|
|
return (_supportHelper != nullptr);
|
2018-10-02 20:39:54 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
Support::Helper &AuthSession::supportHelper() const {
|
2018-10-02 20:39:54 +00:00
|
|
|
Expects(supportMode());
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
return *_supportHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
Support::Templates& AuthSession::supportTemplates() const {
|
|
|
|
return supportHelper().templates();
|
2018-09-28 11:56:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
AuthSession::~AuthSession() {
|
|
|
|
ClickHandler::clearActive();
|
|
|
|
ClickHandler::unpressed();
|
|
|
|
}
|