2019-08-23 13:52:59 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
|
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
|
|
|
#include "ui/widgets/input_fields.h"
|
2020-10-15 14:27:16 +00:00
|
|
|
#include "ui/chat/attach/attach_send_files_way.h"
|
2020-06-25 12:16:09 +00:00
|
|
|
#include "window/section_widget.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "support/support_common.h"
|
|
|
|
#include "storage/serialize_common.h"
|
|
|
|
#include "boxes/send_files_box.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
2019-12-24 10:09:04 +00:00
|
|
|
constexpr auto kVersionTag = -1;
|
2020-06-18 18:04:16 +00:00
|
|
|
constexpr auto kVersion = 2;
|
2019-12-25 15:19:52 +00:00
|
|
|
constexpr auto kMaxSavedPlaybackPositions = 16;
|
2019-08-23 13:52:59 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
SessionSettings::SessionSettings()
|
|
|
|
: _selectorTab(ChatHelpers::SelectorTab::Emoji)
|
|
|
|
, _supportSwitch(Support::SwitchSettings::Next) {
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
QByteArray SessionSettings::serialize() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto autoDownload = _autoDownload.serialize();
|
2022-08-04 14:29:49 +00:00
|
|
|
auto size = sizeof(qint32) * 4
|
|
|
|
+ _groupStickersSectionHidden.size() * sizeof(quint64)
|
|
|
|
+ sizeof(qint32) * 4
|
|
|
|
+ Serialize::bytearraySize(autoDownload)
|
|
|
|
+ sizeof(qint32) * 5
|
|
|
|
+ _mediaLastPlaybackPosition.size() * 2 * sizeof(quint64)
|
|
|
|
+ sizeof(qint32) * 5
|
|
|
|
+ sizeof(qint32)
|
|
|
|
+ (_mutePeriods.size() * sizeof(quint64))
|
2022-10-28 05:19:27 +00:00
|
|
|
+ sizeof(qint32) * 2
|
|
|
|
+ _hiddenPinnedMessages.size() * (sizeof(quint64) * 3);
|
2019-08-23 13:52:59 +00:00
|
|
|
|
|
|
|
auto result = QByteArray();
|
|
|
|
result.reserve(size);
|
|
|
|
{
|
|
|
|
QDataStream stream(&result, QIODevice::WriteOnly);
|
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
2022-10-28 05:19:27 +00:00
|
|
|
stream
|
|
|
|
<< qint32(kVersionTag) << qint32(kVersion)
|
|
|
|
<< static_cast<qint32>(_selectorTab)
|
|
|
|
<< qint32(_groupStickersSectionHidden.size());
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &peerId : _groupStickersSectionHidden) {
|
2021-04-01 21:04:10 +00:00
|
|
|
stream << SerializePeerId(peerId);
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
stream
|
|
|
|
<< qint32(_supportSwitch)
|
|
|
|
<< qint32(_supportFixChatsOrder ? 1 : 0)
|
|
|
|
<< qint32(_supportTemplatesAutocomplete ? 1 : 0)
|
|
|
|
<< qint32(_supportChatsTimeSlice.current())
|
|
|
|
<< autoDownload
|
|
|
|
<< qint32(_supportAllSearchResults.current() ? 1 : 0)
|
|
|
|
<< qint32(_archiveCollapsed.current() ? 1 : 0)
|
|
|
|
<< qint32(_archiveInMainMenu.current() ? 1 : 0)
|
|
|
|
<< qint32(_skipArchiveInSearch.current() ? 1 : 0)
|
|
|
|
<< qint32(_mediaLastPlaybackPosition.size());
|
2020-06-18 18:04:16 +00:00
|
|
|
for (const auto &[id, time] : _mediaLastPlaybackPosition) {
|
2019-12-25 15:19:52 +00:00
|
|
|
stream << quint64(id) << qint64(time);
|
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
stream
|
|
|
|
<< qint32(0) // very old _hiddenPinnedMessages.size());
|
|
|
|
<< qint32(_dialogsFiltersEnabled ? 1 : 0)
|
|
|
|
<< qint32(_supportAllSilent ? 1 : 0)
|
|
|
|
<< qint32(_photoEditorHintShowsCount)
|
|
|
|
<< qint32(0) // old _hiddenPinnedMessages.size());
|
|
|
|
<< qint32(_mutePeriods.size());
|
2022-04-01 22:02:34 +00:00
|
|
|
for (const auto &period : _mutePeriods) {
|
|
|
|
stream << quint64(period);
|
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
stream
|
|
|
|
<< qint32(_skipPremiumStickersSet ? 1 : 0)
|
|
|
|
<< qint32(_hiddenPinnedMessages.size());
|
|
|
|
for (const auto &[key, value] : _hiddenPinnedMessages) {
|
|
|
|
stream
|
|
|
|
<< SerializePeerId(key.peerId)
|
|
|
|
<< qint64(key.topicRootId.bare)
|
|
|
|
<< qint64(value.bare);
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void SessionSettings::addFromSerialized(const QByteArray &serialized) {
|
2019-08-23 13:52:59 +00:00
|
|
|
if (serialized.isEmpty()) {
|
2020-06-18 18:04:16 +00:00
|
|
|
return;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
auto &app = Core::App().settings();
|
2020-06-18 12:47:09 +00:00
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
QDataStream stream(serialized);
|
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
2019-12-24 10:09:04 +00:00
|
|
|
qint32 versionTag = 0;
|
|
|
|
qint32 version = 0;
|
2019-08-23 13:52:59 +00:00
|
|
|
qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0;
|
2020-06-25 12:16:09 +00:00
|
|
|
qint32 appTabbedSelectorSectionEnabled = 1;
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 legacyTabbedSelectorSectionTooltipShown = 0;
|
2020-06-25 12:16:09 +00:00
|
|
|
qint32 appFloatPlayerColumn = static_cast<qint32>(Window::Column::Second);
|
|
|
|
qint32 appFloatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
|
2020-06-18 18:04:16 +00:00
|
|
|
base::flat_map<QString, QString> appSoundOverrides;
|
2019-08-23 13:52:59 +00:00
|
|
|
base::flat_set<PeerId> groupStickersSectionHidden;
|
2020-06-25 12:16:09 +00:00
|
|
|
qint32 appThirdSectionInfoEnabled = 0;
|
|
|
|
qint32 legacySmallDialogsList = 0;
|
|
|
|
float64 appDialogsWidthRatio = app.dialogsWidthRatio();
|
|
|
|
int appThirdColumnWidth = app.thirdColumnWidth();
|
|
|
|
int appThirdSectionExtendedBy = app.thirdSectionExtendedBy();
|
2020-10-15 14:27:16 +00:00
|
|
|
qint32 appSendFilesWay = app.sendFilesWay().serialize();
|
2019-08-23 13:52:59 +00:00
|
|
|
qint32 legacyCallsPeerToPeer = qint32(0);
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 appSendSubmitWay = static_cast<qint32>(app.sendSubmitWay());
|
|
|
|
qint32 supportSwitch = static_cast<qint32>(_supportSwitch);
|
|
|
|
qint32 supportFixChatsOrder = _supportFixChatsOrder ? 1 : 0;
|
|
|
|
qint32 supportTemplatesAutocomplete = _supportTemplatesAutocomplete ? 1 : 0;
|
|
|
|
qint32 supportChatsTimeSlice = _supportChatsTimeSlice.current();
|
|
|
|
qint32 appIncludeMutedCounter = app.includeMutedCounter() ? 1 : 0;
|
|
|
|
qint32 appCountUnreadMessages = app.countUnreadMessages() ? 1 : 0;
|
|
|
|
qint32 appExeLaunchWarning = app.exeLaunchWarning() ? 1 : 0;
|
2019-08-23 13:52:59 +00:00
|
|
|
QByteArray autoDownload;
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 supportAllSearchResults = _supportAllSearchResults.current() ? 1 : 0;
|
|
|
|
qint32 archiveCollapsed = _archiveCollapsed.current() ? 1 : 0;
|
|
|
|
qint32 appNotifyAboutPinned = app.notifyAboutPinned() ? 1 : 0;
|
|
|
|
qint32 archiveInMainMenu = _archiveInMainMenu.current() ? 1 : 0;
|
|
|
|
qint32 skipArchiveInSearch = _skipArchiveInSearch.current() ? 1 : 0;
|
|
|
|
qint32 legacyAutoplayGifs = 1;
|
|
|
|
qint32 appLoopAnimatedStickers = app.loopAnimatedStickers() ? 1 : 0;
|
|
|
|
qint32 appLargeEmoji = app.largeEmoji() ? 1 : 0;
|
|
|
|
qint32 appReplaceEmoji = app.replaceEmoji() ? 1 : 0;
|
|
|
|
qint32 appSuggestEmoji = app.suggestEmoji() ? 1 : 0;
|
|
|
|
qint32 appSuggestStickersByEmoji = app.suggestStickersByEmoji() ? 1 : 0;
|
|
|
|
qint32 appSpellcheckerEnabled = app.spellcheckerEnabled() ? 1 : 0;
|
2019-12-25 15:19:52 +00:00
|
|
|
std::vector<std::pair<DocumentId, crl::time>> mediaLastPlaybackPosition;
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 appVideoPlaybackSpeed = Core::Settings::SerializePlaybackSpeed(app.videoPlaybackSpeed());
|
|
|
|
QByteArray appVideoPipGeometry = app.videoPipGeometry();
|
|
|
|
std::vector<int> appDictionariesEnabled;
|
|
|
|
qint32 appAutoDownloadDictionaries = app.autoDownloadDictionaries() ? 1 : 0;
|
2022-10-28 05:19:27 +00:00
|
|
|
base::flat_map<ThreadId, MsgId> hiddenPinnedMessages;
|
2020-06-18 18:04:16 +00:00
|
|
|
qint32 dialogsFiltersEnabled = _dialogsFiltersEnabled ? 1 : 0;
|
2020-11-19 13:23:51 +00:00
|
|
|
qint32 supportAllSilent = _supportAllSilent ? 1 : 0;
|
2021-04-23 16:31:21 +00:00
|
|
|
qint32 photoEditorHintShowsCount = _photoEditorHintShowsCount;
|
2022-04-01 22:02:34 +00:00
|
|
|
std::vector<TimeId> mutePeriods;
|
2022-08-04 14:29:49 +00:00
|
|
|
qint32 skipPremiumStickersSet = _skipPremiumStickersSet ? 1 : 0;
|
2019-08-23 13:52:59 +00:00
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
stream >> versionTag;
|
|
|
|
if (versionTag == kVersionTag) {
|
|
|
|
stream >> version;
|
|
|
|
stream >> selectorTab;
|
|
|
|
} else {
|
|
|
|
selectorTab = versionTag;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
stream >> appLastSeenWarningSeen;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appTabbedSelectorSectionEnabled;
|
|
|
|
}
|
2020-06-18 18:04:16 +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;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
appSoundOverrides.emplace(key, value);
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> legacyTabbedSelectorSectionTooltipShown;
|
|
|
|
}
|
2020-06-25 12:16:09 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appFloatPlayerColumn >> appFloatPlayerCorner;
|
|
|
|
}
|
2019-08-23 13:52:59 +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;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2021-04-01 21:04:10 +00:00
|
|
|
groupStickersSectionHidden.emplace(
|
|
|
|
DeserializePeerId(peerId));
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 12:16:09 +00:00
|
|
|
if (version < 2) {
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appThirdSectionInfoEnabled;
|
|
|
|
stream >> legacySmallDialogsList;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
qint32 value = 0;
|
|
|
|
stream >> value;
|
2021-01-23 03:29:50 +00:00
|
|
|
appDialogsWidthRatio = std::clamp(value / 1000000., 0., 1.);
|
2019-08-23 13:52:59 +00:00
|
|
|
|
2020-06-25 12:16:09 +00:00
|
|
|
stream >> value;
|
|
|
|
appThirdColumnWidth = value;
|
2019-08-23 13:52:59 +00:00
|
|
|
|
2020-06-25 12:16:09 +00:00
|
|
|
stream >> value;
|
|
|
|
appThirdSectionExtendedBy = value;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appSendFilesWay;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> legacyCallsPeerToPeer;
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
stream >> appSendSubmitWay;
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
stream >> supportSwitch;
|
|
|
|
stream >> supportFixChatsOrder;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportTemplatesAutocomplete;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportChatsTimeSlice;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appIncludeMutedCounter;
|
|
|
|
stream >> appCountUnreadMessages;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appExeLaunchWarning;
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> autoDownload;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportAllSearchResults;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> archiveCollapsed;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appNotifyAboutPinned;
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> archiveInMainMenu;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> skipArchiveInSearch;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> legacyAutoplayGifs;
|
|
|
|
stream >> appLoopAnimatedStickers;
|
|
|
|
stream >> appLargeEmoji;
|
|
|
|
stream >> appReplaceEmoji;
|
|
|
|
stream >> appSuggestEmoji;
|
|
|
|
stream >> appSuggestStickersByEmoji;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appSpellcheckerEnabled;
|
|
|
|
}
|
2019-10-05 16:38:25 +00:00
|
|
|
}
|
2019-12-25 15:19:52 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
quint64 documentId;
|
|
|
|
qint64 time;
|
|
|
|
stream >> documentId >> time;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2019-12-25 15:19:52 +00:00
|
|
|
mediaLastPlaybackPosition.emplace_back(documentId, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (version < 2) {
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appVideoPlaybackSpeed;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appVideoPipGeometry;
|
|
|
|
}
|
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
qint64 langId;
|
|
|
|
stream >> langId;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
appDictionariesEnabled.emplace_back(langId);
|
|
|
|
}
|
2020-01-30 20:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> appAutoDownloadDictionaries;
|
|
|
|
}
|
2020-02-20 19:27:21 +00:00
|
|
|
}
|
2020-06-18 11:17:58 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
2021-09-30 06:04:55 +00:00
|
|
|
// Legacy.
|
2020-06-18 11:17:58 +00:00
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
auto key = quint64();
|
|
|
|
auto value = qint32();
|
|
|
|
stream >> key >> value;
|
2020-06-25 12:16:09 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
hiddenPinnedMessages.emplace(
|
|
|
|
ThreadId{ DeserializePeerId(key), MsgId(0) },
|
|
|
|
value);
|
2020-06-18 11:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> dialogsFiltersEnabled;
|
|
|
|
}
|
2020-11-19 13:23:51 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> supportAllSilent;
|
|
|
|
}
|
2021-04-23 16:31:21 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> photoEditorHintShowsCount;
|
|
|
|
}
|
2021-09-30 06:04:55 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
auto key = quint64();
|
|
|
|
auto value = qint64();
|
|
|
|
stream >> key >> value;
|
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
hiddenPinnedMessages.emplace(
|
|
|
|
ThreadId{ DeserializePeerId(key), MsgId(0) },
|
|
|
|
value);
|
2021-09-30 06:04:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-01 22:02:34 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
quint64 period;
|
|
|
|
stream >> period;
|
|
|
|
mutePeriods.emplace_back(period);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 14:29:49 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
stream >> skipPremiumStickersSet;
|
|
|
|
}
|
2022-10-28 05:19:27 +00:00
|
|
|
if (!stream.atEnd()) {
|
|
|
|
auto count = qint32(0);
|
|
|
|
stream >> count;
|
|
|
|
if (stream.status() == QDataStream::Ok) {
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
auto keyPeerId = quint64();
|
|
|
|
auto keyTopicRootId = qint64();
|
|
|
|
auto value = qint64();
|
|
|
|
stream >> keyPeerId >> keyTopicRootId >> value;
|
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hiddenPinnedMessages.emplace(
|
|
|
|
ThreadId{ DeserializePeerId(keyPeerId), keyTopicRootId },
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("App Error: "
|
2020-06-25 12:16:09 +00:00
|
|
|
"Bad data for SessionSettings::addFromSerialized()"));
|
2020-06-18 18:04:16 +00:00
|
|
|
return;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
if (!autoDownload.isEmpty()
|
2020-06-18 18:04:16 +00:00
|
|
|
&& !_autoDownload.setFromSerialized(autoDownload)) {
|
|
|
|
return;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
2019-12-24 10:09:04 +00:00
|
|
|
if (!version) {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (!legacyAutoplayGifs) {
|
2019-12-24 10:09:04 +00:00
|
|
|
using namespace Data::AutoDownload;
|
2020-06-18 18:04:16 +00:00
|
|
|
_autoDownload = WithDisabledAutoPlay(_autoDownload);
|
2019-12-24 10:09:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-23 13:52:59 +00:00
|
|
|
|
|
|
|
auto uncheckedTab = static_cast<ChatHelpers::SelectorTab>(selectorTab);
|
|
|
|
switch (uncheckedTab) {
|
|
|
|
case ChatHelpers::SelectorTab::Emoji:
|
|
|
|
case ChatHelpers::SelectorTab::Stickers:
|
2020-06-18 18:04:16 +00:00
|
|
|
case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
_groupStickersSectionHidden = std::move(groupStickersSectionHidden);
|
2019-08-23 13:52:59 +00:00
|
|
|
auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>(
|
|
|
|
supportSwitch);
|
|
|
|
switch (uncheckedSupportSwitch) {
|
|
|
|
case Support::SwitchSettings::None:
|
|
|
|
case Support::SwitchSettings::Next:
|
2020-06-18 18:04:16 +00:00
|
|
|
case Support::SwitchSettings::Previous: _supportSwitch = uncheckedSupportSwitch; break;
|
|
|
|
}
|
|
|
|
_supportFixChatsOrder = (supportFixChatsOrder == 1);
|
|
|
|
_supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1);
|
|
|
|
_supportChatsTimeSlice = supportChatsTimeSlice;
|
|
|
|
_hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody);
|
|
|
|
_supportAllSearchResults = (supportAllSearchResults == 1);
|
|
|
|
_archiveCollapsed = (archiveCollapsed == 1);
|
|
|
|
_archiveInMainMenu = (archiveInMainMenu == 1);
|
|
|
|
_skipArchiveInSearch = (skipArchiveInSearch == 1);
|
|
|
|
_mediaLastPlaybackPosition = std::move(mediaLastPlaybackPosition);
|
|
|
|
_hiddenPinnedMessages = std::move(hiddenPinnedMessages);
|
|
|
|
_dialogsFiltersEnabled = (dialogsFiltersEnabled == 1);
|
2020-11-19 13:23:51 +00:00
|
|
|
_supportAllSilent = (supportAllSilent == 1);
|
2021-04-23 16:31:21 +00:00
|
|
|
_photoEditorHintShowsCount = std::move(photoEditorHintShowsCount);
|
2022-04-01 22:02:34 +00:00
|
|
|
_mutePeriods = std::move(mutePeriods);
|
2022-08-04 14:29:49 +00:00
|
|
|
_skipPremiumStickersSet = (skipPremiumStickersSet == 1);
|
2020-06-18 18:04:16 +00:00
|
|
|
|
|
|
|
if (version < 2) {
|
|
|
|
app.setLastSeenWarningSeen(appLastSeenWarningSeen == 1);
|
|
|
|
for (const auto &[key, value] : appSoundOverrides) {
|
|
|
|
app.setSoundOverride(key, value);
|
|
|
|
}
|
2020-10-15 14:27:16 +00:00
|
|
|
if (const auto sendFilesWay = Ui::SendFilesWay::FromSerialized(appSendFilesWay)) {
|
|
|
|
app.setSendFilesWay(*sendFilesWay);
|
2020-06-18 18:04:16 +00:00
|
|
|
}
|
|
|
|
auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
|
|
|
|
appSendSubmitWay);
|
|
|
|
switch (uncheckedSendSubmitWay) {
|
|
|
|
case Ui::InputSubmitSettings::Enter:
|
|
|
|
case Ui::InputSubmitSettings::CtrlEnter: app.setSendSubmitWay(uncheckedSendSubmitWay); break;
|
|
|
|
}
|
|
|
|
app.setIncludeMutedCounter(appIncludeMutedCounter == 1);
|
|
|
|
app.setCountUnreadMessages(appCountUnreadMessages == 1);
|
|
|
|
app.setExeLaunchWarning(appExeLaunchWarning == 1);
|
|
|
|
app.setNotifyAboutPinned(appNotifyAboutPinned == 1);
|
|
|
|
app.setLoopAnimatedStickers(appLoopAnimatedStickers == 1);
|
|
|
|
app.setLargeEmoji(appLargeEmoji == 1);
|
|
|
|
app.setReplaceEmoji(appReplaceEmoji == 1);
|
|
|
|
app.setSuggestEmoji(appSuggestEmoji == 1);
|
|
|
|
app.setSuggestStickersByEmoji(appSuggestStickersByEmoji == 1);
|
|
|
|
app.setSpellcheckerEnabled(appSpellcheckerEnabled == 1);
|
|
|
|
app.setVideoPlaybackSpeed(Core::Settings::DeserializePlaybackSpeed(appVideoPlaybackSpeed));
|
|
|
|
app.setVideoPipGeometry(appVideoPipGeometry);
|
|
|
|
app.setDictionariesEnabled(std::move(appDictionariesEnabled));
|
|
|
|
app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1);
|
2020-06-25 12:16:09 +00:00
|
|
|
app.setTabbedSelectorSectionEnabled(appTabbedSelectorSectionEnabled == 1);
|
|
|
|
auto uncheckedColumn = static_cast<Window::Column>(appFloatPlayerColumn);
|
|
|
|
switch (uncheckedColumn) {
|
|
|
|
case Window::Column::First:
|
|
|
|
case Window::Column::Second:
|
|
|
|
case Window::Column::Third: app.setFloatPlayerColumn(uncheckedColumn); break;
|
|
|
|
}
|
|
|
|
auto uncheckedCorner = static_cast<RectPart>(appFloatPlayerCorner);
|
|
|
|
switch (uncheckedCorner) {
|
|
|
|
case RectPart::TopLeft:
|
|
|
|
case RectPart::TopRight:
|
|
|
|
case RectPart::BottomLeft:
|
|
|
|
case RectPart::BottomRight: app.setFloatPlayerCorner(uncheckedCorner); break;
|
|
|
|
}
|
|
|
|
app.setThirdSectionInfoEnabled(appThirdSectionInfoEnabled);
|
|
|
|
app.setDialogsWidthRatio(appDialogsWidthRatio);
|
|
|
|
app.setThirdColumnWidth(appThirdColumnWidth);
|
|
|
|
app.setThirdSectionExtendedBy(appThirdSectionExtendedBy);
|
2020-06-18 18:04:16 +00:00
|
|
|
}
|
2020-06-18 12:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionSettings::setSupportChatsTimeSlice(int slice) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_supportChatsTimeSlice = slice;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
int SessionSettings::supportChatsTimeSlice() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _supportChatsTimeSlice.current();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
rpl::producer<int> SessionSettings::supportChatsTimeSliceValue() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _supportChatsTimeSlice.value();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void SessionSettings::setSupportAllSearchResults(bool all) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_supportAllSearchResults = all;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
bool SessionSettings::supportAllSearchResults() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _supportAllSearchResults.current();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
rpl::producer<bool> SessionSettings::supportAllSearchResultsValue() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _supportAllSearchResults.value();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void SessionSettings::setMediaLastPlaybackPosition(DocumentId id, crl::time time) {
|
2020-06-18 18:04:16 +00:00
|
|
|
auto &map = _mediaLastPlaybackPosition;
|
2019-12-25 15:19:52 +00:00
|
|
|
const auto i = ranges::find(
|
|
|
|
map,
|
|
|
|
id,
|
|
|
|
&std::pair<DocumentId, crl::time>::first);
|
|
|
|
if (i != map.end()) {
|
|
|
|
if (time > 0) {
|
|
|
|
i->second = time;
|
|
|
|
} else {
|
|
|
|
map.erase(i);
|
|
|
|
}
|
|
|
|
} else if (time > 0) {
|
|
|
|
if (map.size() >= kMaxSavedPlaybackPositions) {
|
|
|
|
map.erase(map.begin());
|
|
|
|
}
|
|
|
|
map.emplace_back(id, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
crl::time SessionSettings::mediaLastPlaybackPosition(DocumentId id) const {
|
2019-12-25 15:19:52 +00:00
|
|
|
const auto i = ranges::find(
|
2020-06-18 18:04:16 +00:00
|
|
|
_mediaLastPlaybackPosition,
|
2019-12-25 15:19:52 +00:00
|
|
|
id,
|
|
|
|
&std::pair<DocumentId, crl::time>::first);
|
2020-06-18 18:04:16 +00:00
|
|
|
return (i != _mediaLastPlaybackPosition.end()) ? i->second : 0;
|
2019-12-25 15:19:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void SessionSettings::setArchiveCollapsed(bool collapsed) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_archiveCollapsed = collapsed;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
bool SessionSettings::archiveCollapsed() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _archiveCollapsed.current();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
rpl::producer<bool> SessionSettings::archiveCollapsedChanges() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _archiveCollapsed.changes();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void SessionSettings::setArchiveInMainMenu(bool inMainMenu) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_archiveInMainMenu = inMainMenu;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
bool SessionSettings::archiveInMainMenu() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _archiveInMainMenu.current();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
rpl::producer<bool> SessionSettings::archiveInMainMenuChanges() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _archiveInMainMenu.changes();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
void SessionSettings::setSkipArchiveInSearch(bool skip) {
|
2020-06-18 18:04:16 +00:00
|
|
|
_skipArchiveInSearch = skip;
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
bool SessionSettings::skipArchiveInSearch() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _skipArchiveInSearch.current();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
rpl::producer<bool> SessionSettings::skipArchiveInSearchChanges() const {
|
2020-06-18 18:04:16 +00:00
|
|
|
return _skipArchiveInSearch.changes();
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 05:19:27 +00:00
|
|
|
MsgId SessionSettings::hiddenPinnedMessageId(
|
|
|
|
PeerId peerId,
|
|
|
|
MsgId topicRootId) const {
|
|
|
|
const auto i = _hiddenPinnedMessages.find({ peerId, topicRootId });
|
|
|
|
return (i != end(_hiddenPinnedMessages)) ? i->second : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionSettings::setHiddenPinnedMessageId(
|
|
|
|
PeerId peerId,
|
|
|
|
MsgId topicRootId,
|
|
|
|
MsgId msgId) {
|
|
|
|
const auto id = ThreadId{ peerId, topicRootId };
|
|
|
|
if (msgId) {
|
|
|
|
_hiddenPinnedMessages[id] = msgId;
|
|
|
|
} else {
|
|
|
|
_hiddenPinnedMessages.remove(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 16:31:21 +00:00
|
|
|
bool SessionSettings::photoEditorHintShown() const {
|
|
|
|
return _photoEditorHintShowsCount < kPhotoEditorHintMaxShowsCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionSettings::incrementPhotoEditorHintShown() {
|
|
|
|
if (photoEditorHintShown()) {
|
|
|
|
_photoEditorHintShowsCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 22:02:34 +00:00
|
|
|
std::vector<TimeId> SessionSettings::mutePeriods() const {
|
|
|
|
return _mutePeriods;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionSettings::addMutePeriod(TimeId period) {
|
|
|
|
if (_mutePeriods.empty()) {
|
|
|
|
_mutePeriods.push_back(period);
|
|
|
|
} else if (_mutePeriods.back() != period) {
|
|
|
|
if (_mutePeriods.back() < period) {
|
|
|
|
_mutePeriods = { _mutePeriods.back(), period };
|
|
|
|
} else {
|
|
|
|
_mutePeriods = { period, _mutePeriods.back() };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
} // namespace Main
|