main_session_settings.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "main/main_session_settings.h"
  8. #include "chat_helpers/tabbed_selector.h"
  9. #include "ui/widgets/fields/input_field.h"
  10. #include "ui/chat/attach/attach_send_files_way.h"
  11. #include "window/section_widget.h"
  12. #include "support/support_common.h"
  13. #include "storage/serialize_common.h"
  14. #include "boxes/send_files_box.h"
  15. #include "core/application.h"
  16. #include "core/core_settings.h"
  17. namespace Main {
  18. namespace {
  19. constexpr auto kLegacyCallsPeerToPeerNobody = 4;
  20. constexpr auto kVersionTag = -1;
  21. constexpr auto kVersion = 2;
  22. } // namespace
  23. SessionSettings::SessionSettings()
  24. : _selectorTab(ChatHelpers::SelectorTab::Emoji)
  25. , _supportSwitch(Support::SwitchSettings::Next) {
  26. }
  27. QByteArray SessionSettings::serialize() const {
  28. const auto autoDownload = _autoDownload.serialize();
  29. const auto size = sizeof(qint32) * 4
  30. + _groupStickersSectionHidden.size() * sizeof(quint64)
  31. + sizeof(qint32) * 4
  32. + Serialize::bytearraySize(autoDownload)
  33. + sizeof(qint32) * 11
  34. + (_mutePeriods.size() * sizeof(quint64))
  35. + sizeof(qint32) * 2
  36. + _hiddenPinnedMessages.size() * (sizeof(quint64) * 3)
  37. + sizeof(qint32)
  38. + _groupEmojiSectionHidden.size() * sizeof(quint64)
  39. + sizeof(qint32) * 2;
  40. auto result = QByteArray();
  41. result.reserve(size);
  42. {
  43. QDataStream stream(&result, QIODevice::WriteOnly);
  44. stream.setVersion(QDataStream::Qt_5_1);
  45. stream
  46. << qint32(kVersionTag) << qint32(kVersion)
  47. << static_cast<qint32>(_selectorTab)
  48. << qint32(_groupStickersSectionHidden.size());
  49. for (const auto &peerId : _groupStickersSectionHidden) {
  50. stream << SerializePeerId(peerId);
  51. }
  52. stream
  53. << qint32(_supportSwitch)
  54. << qint32(_supportFixChatsOrder ? 1 : 0)
  55. << qint32(_supportTemplatesAutocomplete ? 1 : 0)
  56. << qint32(_supportChatsTimeSlice.current())
  57. << autoDownload
  58. << qint32(_supportAllSearchResults.current() ? 1 : 0)
  59. << qint32(_archiveCollapsed.current() ? 1 : 0)
  60. << qint32(_archiveInMainMenu.current() ? 1 : 0)
  61. << qint32(_skipArchiveInSearch.current() ? 1 : 0)
  62. << qint32(0) // old _mediaLastPlaybackPosition.size());
  63. << qint32(0) // very old _hiddenPinnedMessages.size());
  64. << qint32(_dialogsFiltersEnabled ? 1 : 0)
  65. << qint32(_supportAllSilent ? 1 : 0)
  66. << qint32(_photoEditorHintShowsCount)
  67. << qint32(0) // old _hiddenPinnedMessages.size());
  68. << qint32(_mutePeriods.size());
  69. for (const auto &period : _mutePeriods) {
  70. stream << quint64(period);
  71. }
  72. stream
  73. << qint32(0) // old _skipPremiumStickersSet
  74. << qint32(_hiddenPinnedMessages.size());
  75. for (const auto &[key, value] : _hiddenPinnedMessages) {
  76. stream
  77. << SerializePeerId(key.peerId)
  78. << qint64(key.topicRootId.bare)
  79. << qint64(value.bare);
  80. }
  81. stream
  82. << qint32(_groupEmojiSectionHidden.size());
  83. for (const auto &peerId : _groupEmojiSectionHidden) {
  84. stream << SerializePeerId(peerId);
  85. }
  86. stream
  87. << qint32(_lastNonPremiumLimitDownload)
  88. << qint32(_lastNonPremiumLimitUpload);
  89. }
  90. Ensures(result.size() == size);
  91. return result;
  92. }
  93. void SessionSettings::addFromSerialized(const QByteArray &serialized) {
  94. if (serialized.isEmpty()) {
  95. return;
  96. }
  97. auto &app = Core::App().settings();
  98. QDataStream stream(serialized);
  99. stream.setVersion(QDataStream::Qt_5_1);
  100. qint32 versionTag = 0;
  101. qint32 version = 0;
  102. qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
  103. qint32 appLastSeenWarningSeen = app.lastSeenWarningSeen() ? 1 : 0;
  104. qint32 appTabbedSelectorSectionEnabled = 1;
  105. qint32 legacyTabbedSelectorSectionTooltipShown = 0;
  106. qint32 appFloatPlayerColumn = static_cast<qint32>(Window::Column::Second);
  107. qint32 appFloatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
  108. base::flat_map<QString, QString> appSoundOverrides;
  109. base::flat_set<PeerId> groupStickersSectionHidden;
  110. base::flat_set<PeerId> groupEmojiSectionHidden;
  111. qint32 appThirdSectionInfoEnabled = 0;
  112. qint32 legacySmallDialogsList = 0;
  113. float64 appDialogsWidthRatio = app.dialogsWidthRatio(false);
  114. int appThirdColumnWidth = app.thirdColumnWidth();
  115. int appThirdSectionExtendedBy = app.thirdSectionExtendedBy();
  116. qint32 appSendFilesWay = app.sendFilesWay().serialize();
  117. qint32 legacyCallsPeerToPeer = qint32(0);
  118. qint32 appSendSubmitWay = static_cast<qint32>(app.sendSubmitWay());
  119. qint32 supportSwitch = static_cast<qint32>(_supportSwitch);
  120. qint32 supportFixChatsOrder = _supportFixChatsOrder ? 1 : 0;
  121. qint32 supportTemplatesAutocomplete = _supportTemplatesAutocomplete ? 1 : 0;
  122. qint32 supportChatsTimeSlice = _supportChatsTimeSlice.current();
  123. qint32 appIncludeMutedCounter = app.includeMutedCounter() ? 1 : 0;
  124. qint32 appCountUnreadMessages = app.countUnreadMessages() ? 1 : 0;
  125. qint32 legacyAppExeLaunchWarning = 1;
  126. QByteArray autoDownload;
  127. qint32 supportAllSearchResults = _supportAllSearchResults.current() ? 1 : 0;
  128. qint32 archiveCollapsed = _archiveCollapsed.current() ? 1 : 0;
  129. qint32 appNotifyAboutPinned = app.notifyAboutPinned() ? 1 : 0;
  130. qint32 archiveInMainMenu = _archiveInMainMenu.current() ? 1 : 0;
  131. qint32 skipArchiveInSearch = _skipArchiveInSearch.current() ? 1 : 0;
  132. qint32 legacyAutoplayGifs = 1;
  133. qint32 appLoopAnimatedStickers = app.loopAnimatedStickers() ? 1 : 0;
  134. qint32 appLargeEmoji = app.largeEmoji() ? 1 : 0;
  135. qint32 appReplaceEmoji = app.replaceEmoji() ? 1 : 0;
  136. qint32 appSuggestEmoji = app.suggestEmoji() ? 1 : 0;
  137. qint32 appSuggestStickersByEmoji = app.suggestStickersByEmoji() ? 1 : 0;
  138. qint32 appSpellcheckerEnabled = app.spellcheckerEnabled() ? 1 : 0;
  139. qint32 appVideoPlaybackSpeed = app.videoPlaybackSpeedSerialized();
  140. QByteArray appVideoPipGeometry = app.videoPipGeometry();
  141. std::vector<int> appDictionariesEnabled;
  142. qint32 appAutoDownloadDictionaries = app.autoDownloadDictionaries() ? 1 : 0;
  143. base::flat_map<ThreadId, MsgId> hiddenPinnedMessages;
  144. qint32 dialogsFiltersEnabled = _dialogsFiltersEnabled ? 1 : 0;
  145. qint32 supportAllSilent = _supportAllSilent ? 1 : 0;
  146. qint32 photoEditorHintShowsCount = _photoEditorHintShowsCount;
  147. std::vector<TimeId> mutePeriods;
  148. qint32 legacySkipPremiumStickersSet = 0;
  149. qint32 lastNonPremiumLimitDownload = 0;
  150. qint32 lastNonPremiumLimitUpload = 0;
  151. stream >> versionTag;
  152. if (versionTag == kVersionTag) {
  153. stream >> version;
  154. stream >> selectorTab;
  155. } else {
  156. selectorTab = versionTag;
  157. }
  158. if (version < 2) {
  159. stream >> appLastSeenWarningSeen;
  160. if (!stream.atEnd()) {
  161. stream >> appTabbedSelectorSectionEnabled;
  162. }
  163. if (!stream.atEnd()) {
  164. auto count = qint32(0);
  165. stream >> count;
  166. if (stream.status() == QDataStream::Ok) {
  167. for (auto i = 0; i != count; ++i) {
  168. QString key, value;
  169. stream >> key >> value;
  170. if (stream.status() != QDataStream::Ok) {
  171. LOG(("App Error: "
  172. "Bad data for SessionSettings::addFromSerialized()"));
  173. return;
  174. }
  175. appSoundOverrides.emplace(key, value);
  176. }
  177. }
  178. }
  179. if (!stream.atEnd()) {
  180. stream >> legacyTabbedSelectorSectionTooltipShown;
  181. }
  182. if (!stream.atEnd()) {
  183. stream >> appFloatPlayerColumn >> appFloatPlayerCorner;
  184. }
  185. }
  186. if (!stream.atEnd()) {
  187. auto count = qint32(0);
  188. stream >> count;
  189. if (stream.status() == QDataStream::Ok) {
  190. for (auto i = 0; i != count; ++i) {
  191. quint64 peerId;
  192. stream >> peerId;
  193. if (stream.status() != QDataStream::Ok) {
  194. LOG(("App Error: "
  195. "Bad data for SessionSettings::addFromSerialized()"));
  196. return;
  197. }
  198. groupStickersSectionHidden.emplace(
  199. DeserializePeerId(peerId));
  200. }
  201. }
  202. }
  203. if (version < 2) {
  204. if (!stream.atEnd()) {
  205. stream >> appThirdSectionInfoEnabled;
  206. stream >> legacySmallDialogsList;
  207. }
  208. if (!stream.atEnd()) {
  209. qint32 value = 0;
  210. stream >> value;
  211. appDialogsWidthRatio = std::clamp(value / 1000000., 0., 1.);
  212. stream >> value;
  213. appThirdColumnWidth = value;
  214. stream >> value;
  215. appThirdSectionExtendedBy = value;
  216. }
  217. if (!stream.atEnd()) {
  218. stream >> appSendFilesWay;
  219. }
  220. if (!stream.atEnd()) {
  221. stream >> legacyCallsPeerToPeer;
  222. }
  223. }
  224. if (!stream.atEnd()) {
  225. if (version < 2) {
  226. stream >> appSendSubmitWay;
  227. }
  228. stream >> supportSwitch;
  229. stream >> supportFixChatsOrder;
  230. }
  231. if (!stream.atEnd()) {
  232. stream >> supportTemplatesAutocomplete;
  233. }
  234. if (!stream.atEnd()) {
  235. stream >> supportChatsTimeSlice;
  236. }
  237. if (version < 2) {
  238. if (!stream.atEnd()) {
  239. stream >> appIncludeMutedCounter;
  240. stream >> appCountUnreadMessages;
  241. }
  242. if (!stream.atEnd()) {
  243. stream >> legacyAppExeLaunchWarning;
  244. }
  245. }
  246. if (!stream.atEnd()) {
  247. stream >> autoDownload;
  248. }
  249. if (!stream.atEnd()) {
  250. stream >> supportAllSearchResults;
  251. }
  252. if (!stream.atEnd()) {
  253. stream >> archiveCollapsed;
  254. }
  255. if (version < 2) {
  256. if (!stream.atEnd()) {
  257. stream >> appNotifyAboutPinned;
  258. }
  259. }
  260. if (!stream.atEnd()) {
  261. stream >> archiveInMainMenu;
  262. }
  263. if (!stream.atEnd()) {
  264. stream >> skipArchiveInSearch;
  265. }
  266. if (version < 2) {
  267. if (!stream.atEnd()) {
  268. stream >> legacyAutoplayGifs;
  269. stream >> appLoopAnimatedStickers;
  270. stream >> appLargeEmoji;
  271. stream >> appReplaceEmoji;
  272. stream >> appSuggestEmoji;
  273. stream >> appSuggestStickersByEmoji;
  274. }
  275. if (!stream.atEnd()) {
  276. stream >> appSpellcheckerEnabled;
  277. }
  278. }
  279. if (!stream.atEnd()) {
  280. auto count = qint32(0);
  281. stream >> count;
  282. if (stream.status() == QDataStream::Ok) {
  283. for (auto i = 0; i != count; ++i) {
  284. quint64 documentId;
  285. qint64 time;
  286. stream >> documentId >> time;
  287. if (stream.status() != QDataStream::Ok) {
  288. LOG(("App Error: "
  289. "Bad data for SessionSettings::addFromSerialized()"));
  290. return;
  291. }
  292. // Old mediaLastPlaybackPosition.
  293. }
  294. }
  295. }
  296. if (version < 2) {
  297. if (!stream.atEnd()) {
  298. stream >> appVideoPlaybackSpeed;
  299. }
  300. if (!stream.atEnd()) {
  301. stream >> appVideoPipGeometry;
  302. }
  303. if (!stream.atEnd()) {
  304. auto count = qint32(0);
  305. stream >> count;
  306. if (stream.status() == QDataStream::Ok) {
  307. for (auto i = 0; i != count; ++i) {
  308. qint64 langId;
  309. stream >> langId;
  310. if (stream.status() != QDataStream::Ok) {
  311. LOG(("App Error: "
  312. "Bad data for SessionSettings::addFromSerialized()"));
  313. return;
  314. }
  315. appDictionariesEnabled.emplace_back(langId);
  316. }
  317. }
  318. }
  319. if (!stream.atEnd()) {
  320. stream >> appAutoDownloadDictionaries;
  321. }
  322. }
  323. if (!stream.atEnd()) {
  324. auto count = qint32(0);
  325. stream >> count;
  326. if (stream.status() == QDataStream::Ok) {
  327. // Legacy.
  328. for (auto i = 0; i != count; ++i) {
  329. auto key = quint64();
  330. auto value = qint32();
  331. stream >> key >> value;
  332. if (stream.status() != QDataStream::Ok) {
  333. LOG(("App Error: "
  334. "Bad data for SessionSettings::addFromSerialized()"));
  335. return;
  336. }
  337. hiddenPinnedMessages.emplace(
  338. ThreadId{ DeserializePeerId(key), MsgId(0) },
  339. value);
  340. }
  341. }
  342. }
  343. if (!stream.atEnd()) {
  344. stream >> dialogsFiltersEnabled;
  345. }
  346. if (!stream.atEnd()) {
  347. stream >> supportAllSilent;
  348. }
  349. if (!stream.atEnd()) {
  350. stream >> photoEditorHintShowsCount;
  351. }
  352. if (!stream.atEnd()) {
  353. auto count = qint32(0);
  354. stream >> count;
  355. if (stream.status() == QDataStream::Ok) {
  356. for (auto i = 0; i != count; ++i) {
  357. auto key = quint64();
  358. auto value = qint64();
  359. stream >> key >> value;
  360. if (stream.status() != QDataStream::Ok) {
  361. LOG(("App Error: "
  362. "Bad data for SessionSettings::addFromSerialized()"));
  363. return;
  364. }
  365. hiddenPinnedMessages.emplace(
  366. ThreadId{ DeserializePeerId(key), MsgId(0) },
  367. value);
  368. }
  369. }
  370. }
  371. if (!stream.atEnd()) {
  372. auto count = qint32(0);
  373. stream >> count;
  374. if (stream.status() == QDataStream::Ok) {
  375. for (auto i = 0; i != count; ++i) {
  376. quint64 period;
  377. stream >> period;
  378. mutePeriods.emplace_back(period);
  379. }
  380. }
  381. }
  382. if (!stream.atEnd()) {
  383. stream >> legacySkipPremiumStickersSet;
  384. }
  385. if (!stream.atEnd()) {
  386. auto count = qint32(0);
  387. stream >> count;
  388. if (stream.status() == QDataStream::Ok) {
  389. for (auto i = 0; i != count; ++i) {
  390. auto keyPeerId = quint64();
  391. auto keyTopicRootId = qint64();
  392. auto value = qint64();
  393. stream >> keyPeerId >> keyTopicRootId >> value;
  394. if (stream.status() != QDataStream::Ok) {
  395. LOG(("App Error: "
  396. "Bad data for SessionSettings::addFromSerialized()"));
  397. return;
  398. }
  399. hiddenPinnedMessages.emplace(
  400. ThreadId{ DeserializePeerId(keyPeerId), keyTopicRootId },
  401. value);
  402. }
  403. }
  404. }
  405. if (!stream.atEnd()) {
  406. auto count = qint32(0);
  407. stream >> count;
  408. if (stream.status() == QDataStream::Ok) {
  409. for (auto i = 0; i != count; ++i) {
  410. quint64 peerId;
  411. stream >> peerId;
  412. if (stream.status() != QDataStream::Ok) {
  413. LOG(("App Error: "
  414. "Bad data for SessionSettings::addFromSerialized()"));
  415. return;
  416. }
  417. groupEmojiSectionHidden.emplace(DeserializePeerId(peerId));
  418. }
  419. }
  420. }
  421. if (!stream.atEnd()) {
  422. stream
  423. >> lastNonPremiumLimitDownload
  424. >> lastNonPremiumLimitUpload;
  425. }
  426. if (stream.status() != QDataStream::Ok) {
  427. LOG(("App Error: "
  428. "Bad data for SessionSettings::addFromSerialized()"));
  429. return;
  430. }
  431. if (!autoDownload.isEmpty()
  432. && !_autoDownload.setFromSerialized(autoDownload)) {
  433. return;
  434. }
  435. if (!version) {
  436. if (!legacyAutoplayGifs) {
  437. using namespace Data::AutoDownload;
  438. _autoDownload = WithDisabledAutoPlay(_autoDownload);
  439. }
  440. }
  441. auto uncheckedTab = static_cast<ChatHelpers::SelectorTab>(selectorTab);
  442. switch (uncheckedTab) {
  443. case ChatHelpers::SelectorTab::Emoji:
  444. case ChatHelpers::SelectorTab::Stickers:
  445. case ChatHelpers::SelectorTab::Gifs: _selectorTab = uncheckedTab; break;
  446. }
  447. _groupStickersSectionHidden = std::move(groupStickersSectionHidden);
  448. _groupEmojiSectionHidden = std::move(groupEmojiSectionHidden);
  449. auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>(
  450. supportSwitch);
  451. switch (uncheckedSupportSwitch) {
  452. case Support::SwitchSettings::None:
  453. case Support::SwitchSettings::Next:
  454. case Support::SwitchSettings::Previous: _supportSwitch = uncheckedSupportSwitch; break;
  455. }
  456. _supportFixChatsOrder = (supportFixChatsOrder == 1);
  457. _supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1);
  458. _supportChatsTimeSlice = supportChatsTimeSlice;
  459. _hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody);
  460. _supportAllSearchResults = (supportAllSearchResults == 1);
  461. _archiveCollapsed = (archiveCollapsed == 1);
  462. _archiveInMainMenu = (archiveInMainMenu == 1);
  463. _skipArchiveInSearch = (skipArchiveInSearch == 1);
  464. _hiddenPinnedMessages = std::move(hiddenPinnedMessages);
  465. _dialogsFiltersEnabled = (dialogsFiltersEnabled == 1);
  466. _supportAllSilent = (supportAllSilent == 1);
  467. _photoEditorHintShowsCount = std::move(photoEditorHintShowsCount);
  468. _mutePeriods = std::move(mutePeriods);
  469. _lastNonPremiumLimitDownload = lastNonPremiumLimitDownload;
  470. _lastNonPremiumLimitUpload = lastNonPremiumLimitUpload;
  471. if (version < 2) {
  472. app.setLastSeenWarningSeen(appLastSeenWarningSeen == 1);
  473. for (const auto &[key, value] : appSoundOverrides) {
  474. app.setSoundOverride(key, value);
  475. }
  476. if (const auto sendFilesWay = Ui::SendFilesWay::FromSerialized(appSendFilesWay)) {
  477. app.setSendFilesWay(*sendFilesWay);
  478. }
  479. auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
  480. appSendSubmitWay);
  481. switch (uncheckedSendSubmitWay) {
  482. case Ui::InputSubmitSettings::Enter:
  483. case Ui::InputSubmitSettings::CtrlEnter: app.setSendSubmitWay(uncheckedSendSubmitWay); break;
  484. }
  485. app.setIncludeMutedCounter(appIncludeMutedCounter == 1);
  486. app.setCountUnreadMessages(appCountUnreadMessages == 1);
  487. app.setNotifyAboutPinned(appNotifyAboutPinned == 1);
  488. app.setLoopAnimatedStickers(appLoopAnimatedStickers == 1);
  489. app.setLargeEmoji(appLargeEmoji == 1);
  490. app.setReplaceEmoji(appReplaceEmoji == 1);
  491. app.setSuggestEmoji(appSuggestEmoji == 1);
  492. app.setSuggestStickersByEmoji(appSuggestStickersByEmoji == 1);
  493. app.setSpellcheckerEnabled(appSpellcheckerEnabled == 1);
  494. app.setVideoPlaybackSpeedSerialized(appVideoPlaybackSpeed);
  495. app.setVideoPipGeometry(appVideoPipGeometry);
  496. app.setDictionariesEnabled(std::move(appDictionariesEnabled));
  497. app.setAutoDownloadDictionaries(appAutoDownloadDictionaries == 1);
  498. app.setTabbedSelectorSectionEnabled(appTabbedSelectorSectionEnabled == 1);
  499. auto uncheckedColumn = static_cast<Window::Column>(appFloatPlayerColumn);
  500. switch (uncheckedColumn) {
  501. case Window::Column::First:
  502. case Window::Column::Second:
  503. case Window::Column::Third: app.setFloatPlayerColumn(uncheckedColumn); break;
  504. }
  505. auto uncheckedCorner = static_cast<RectPart>(appFloatPlayerCorner);
  506. switch (uncheckedCorner) {
  507. case RectPart::TopLeft:
  508. case RectPart::TopRight:
  509. case RectPart::BottomLeft:
  510. case RectPart::BottomRight: app.setFloatPlayerCorner(uncheckedCorner); break;
  511. }
  512. app.setThirdSectionInfoEnabled(appThirdSectionInfoEnabled);
  513. app.updateDialogsWidthRatio(appDialogsWidthRatio, false);
  514. app.setThirdColumnWidth(appThirdColumnWidth);
  515. app.setThirdSectionExtendedBy(appThirdSectionExtendedBy);
  516. }
  517. }
  518. void SessionSettings::setSupportChatsTimeSlice(int slice) {
  519. _supportChatsTimeSlice = slice;
  520. }
  521. int SessionSettings::supportChatsTimeSlice() const {
  522. return _supportChatsTimeSlice.current();
  523. }
  524. rpl::producer<int> SessionSettings::supportChatsTimeSliceValue() const {
  525. return _supportChatsTimeSlice.value();
  526. }
  527. void SessionSettings::setSupportAllSearchResults(bool all) {
  528. _supportAllSearchResults = all;
  529. }
  530. bool SessionSettings::supportAllSearchResults() const {
  531. return _supportAllSearchResults.current();
  532. }
  533. rpl::producer<bool> SessionSettings::supportAllSearchResultsValue() const {
  534. return _supportAllSearchResults.value();
  535. }
  536. void SessionSettings::setArchiveCollapsed(bool collapsed) {
  537. _archiveCollapsed = collapsed;
  538. }
  539. bool SessionSettings::archiveCollapsed() const {
  540. return _archiveCollapsed.current();
  541. }
  542. rpl::producer<bool> SessionSettings::archiveCollapsedChanges() const {
  543. return _archiveCollapsed.changes();
  544. }
  545. void SessionSettings::setArchiveInMainMenu(bool inMainMenu) {
  546. _archiveInMainMenu = inMainMenu;
  547. }
  548. bool SessionSettings::archiveInMainMenu() const {
  549. return _archiveInMainMenu.current();
  550. }
  551. rpl::producer<bool> SessionSettings::archiveInMainMenuChanges() const {
  552. return _archiveInMainMenu.changes();
  553. }
  554. void SessionSettings::setSkipArchiveInSearch(bool skip) {
  555. _skipArchiveInSearch = skip;
  556. }
  557. bool SessionSettings::skipArchiveInSearch() const {
  558. return _skipArchiveInSearch.current();
  559. }
  560. rpl::producer<bool> SessionSettings::skipArchiveInSearchChanges() const {
  561. return _skipArchiveInSearch.changes();
  562. }
  563. MsgId SessionSettings::hiddenPinnedMessageId(
  564. PeerId peerId,
  565. MsgId topicRootId) const {
  566. const auto i = _hiddenPinnedMessages.find({ peerId, topicRootId });
  567. return (i != end(_hiddenPinnedMessages)) ? i->second : 0;
  568. }
  569. void SessionSettings::setHiddenPinnedMessageId(
  570. PeerId peerId,
  571. MsgId topicRootId,
  572. MsgId msgId) {
  573. const auto id = ThreadId{ peerId, topicRootId };
  574. if (msgId) {
  575. _hiddenPinnedMessages[id] = msgId;
  576. } else {
  577. _hiddenPinnedMessages.remove(id);
  578. }
  579. }
  580. bool SessionSettings::photoEditorHintShown() const {
  581. return _photoEditorHintShowsCount < kPhotoEditorHintMaxShowsCount;
  582. }
  583. void SessionSettings::incrementPhotoEditorHintShown() {
  584. if (photoEditorHintShown()) {
  585. _photoEditorHintShowsCount++;
  586. }
  587. }
  588. std::vector<TimeId> SessionSettings::mutePeriods() const {
  589. return _mutePeriods;
  590. }
  591. void SessionSettings::addMutePeriod(TimeId period) {
  592. if (_mutePeriods.empty()) {
  593. _mutePeriods.push_back(period);
  594. } else if (_mutePeriods.back() != period) {
  595. if (_mutePeriods.back() < period) {
  596. _mutePeriods = { _mutePeriods.back(), period };
  597. } else {
  598. _mutePeriods = { period, _mutePeriods.back() };
  599. }
  600. }
  601. }
  602. } // namespace Main