window_session_controller.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. #pragma once
  8. #include "base/timer.h"
  9. #include "chat_helpers/compose/compose_show.h"
  10. #include "data/data_chat_participant_status.h"
  11. #include "data/data_report.h"
  12. #include "dialogs/dialogs_key.h"
  13. #include "mtproto/sender.h"
  14. #include "settings/settings_type.h"
  15. #include "window/window_adaptive.h"
  16. class PhotoData;
  17. class MainWidget;
  18. class MainWindow;
  19. namespace Adaptive {
  20. enum class WindowLayout;
  21. } // namespace Adaptive
  22. namespace Data {
  23. struct StoriesContext;
  24. enum class StorySourcesList : uchar;
  25. } // namespace Data
  26. namespace ChatHelpers {
  27. class TabbedSelector;
  28. class EmojiInteractions;
  29. struct FileChosen;
  30. } // namespace ChatHelpers
  31. namespace Main {
  32. class Session;
  33. } // namespace Main
  34. namespace InlineBots {
  35. class AttachWebView;
  36. enum class PeerType : uint8;
  37. using PeerTypes = base::flags<PeerType>;
  38. } // namespace InlineBots
  39. namespace Calls {
  40. struct StartGroupCallArgs;
  41. } // namespace Calls
  42. namespace Passport {
  43. struct FormRequest;
  44. class FormController;
  45. } // namespace Passport
  46. namespace Ui {
  47. class LayerWidget;
  48. class ChatStyle;
  49. class ChatTheme;
  50. struct ChatThemeKey;
  51. struct ChatPaintContext;
  52. struct ChatThemeBackground;
  53. struct ChatThemeBackgroundData;
  54. class MessageSendingAnimationController;
  55. struct BoostCounters;
  56. struct ChatPaintContextArgs;
  57. } // namespace Ui
  58. namespace Data {
  59. struct CloudTheme;
  60. enum class CloudThemeType;
  61. class Thread;
  62. class Forum;
  63. class ForumTopic;
  64. class WallPaper;
  65. } // namespace Data
  66. namespace HistoryView::Reactions {
  67. class CachedIconFactory;
  68. } // namespace HistoryView::Reactions
  69. namespace Window {
  70. using GifPauseReason = ChatHelpers::PauseReason;
  71. using GifPauseReasons = ChatHelpers::PauseReasons;
  72. class SectionMemento;
  73. class Controller;
  74. class FiltersMenu;
  75. class ChatPreviewManager;
  76. struct PeerByLinkInfo;
  77. struct SeparateId;
  78. struct PeerThemeOverride {
  79. PeerData *peer = nullptr;
  80. std::shared_ptr<Ui::ChatTheme> theme;
  81. EmojiPtr emoji = nullptr;
  82. };
  83. bool operator==(const PeerThemeOverride &a, const PeerThemeOverride &b);
  84. bool operator!=(const PeerThemeOverride &a, const PeerThemeOverride &b);
  85. class DateClickHandler : public ClickHandler {
  86. public:
  87. DateClickHandler(Dialogs::Key chat, QDate date);
  88. void setDate(QDate date);
  89. void onClick(ClickContext context) const override;
  90. private:
  91. Dialogs::Key _chat;
  92. base::weak_ptr<Data::ForumTopic> _weak;
  93. QDate _date;
  94. };
  95. struct SectionShow {
  96. enum class Way {
  97. Forward,
  98. Backward,
  99. ClearStack,
  100. };
  101. struct OriginMessage {
  102. FullMsgId id;
  103. };
  104. using Origin = std::variant<v::null_t, OriginMessage>;
  105. SectionShow(
  106. Way way = Way::Forward,
  107. anim::type animated = anim::type::normal,
  108. anim::activation activation = anim::activation::normal)
  109. : way(way)
  110. , animated(animated)
  111. , activation(activation) {
  112. }
  113. SectionShow(
  114. anim::type animated,
  115. anim::activation activation = anim::activation::normal)
  116. : animated(animated)
  117. , activation(activation) {
  118. }
  119. [[nodiscard]] SectionShow withWay(Way newWay) const {
  120. return SectionShow(newWay, animated, activation);
  121. }
  122. [[nodiscard]] SectionShow withThirdColumn() const {
  123. auto copy = *this;
  124. copy.thirdColumn = true;
  125. return copy;
  126. }
  127. [[nodiscard]] SectionShow withChildColumn() const {
  128. auto copy = *this;
  129. copy.childColumn = true;
  130. return copy;
  131. }
  132. TextWithEntities highlightPart;
  133. int highlightPartOffsetHint = 0;
  134. std::optional<TimeId> videoTimestamp;
  135. Way way = Way::Forward;
  136. anim::type animated = anim::type::normal;
  137. anim::activation activation = anim::activation::normal;
  138. bool thirdColumn = false;
  139. bool childColumn = false;
  140. bool forbidLayer = false;
  141. bool reapplyLocalDraft = false;
  142. bool dropSameFromStack = false;
  143. Origin origin;
  144. };
  145. class SessionController;
  146. class SessionNavigation : public base::has_weak_ptr {
  147. public:
  148. explicit SessionNavigation(not_null<Main::Session*> session);
  149. virtual ~SessionNavigation();
  150. [[nodiscard]] Main::Session &session() const;
  151. virtual void showSection(
  152. std::shared_ptr<SectionMemento> memento,
  153. const SectionShow &params = SectionShow()) = 0;
  154. virtual void showBackFromStack(
  155. const SectionShow &params = SectionShow()) = 0;
  156. virtual not_null<SessionController*> parentController() = 0;
  157. void showPeerByLink(const PeerByLinkInfo &info);
  158. void showRepliesForMessage(
  159. not_null<History*> history,
  160. MsgId rootId,
  161. MsgId commentId = 0,
  162. const SectionShow &params = SectionShow());
  163. void showTopic(
  164. not_null<Data::ForumTopic*> topic,
  165. MsgId itemId = 0,
  166. const SectionShow &params = SectionShow());
  167. void showThread(
  168. not_null<Data::Thread*> thread,
  169. MsgId itemId = 0,
  170. const SectionShow &params = SectionShow());
  171. void showPeerInfo(
  172. PeerId peerId,
  173. const SectionShow &params = SectionShow());
  174. void showPeerInfo(
  175. not_null<PeerData*> peer,
  176. const SectionShow &params = SectionShow());
  177. void showPeerInfo(
  178. not_null<Data::Thread*> thread,
  179. const SectionShow &params = SectionShow());
  180. virtual void showPeerHistory(
  181. PeerId peerId,
  182. const SectionShow &params = SectionShow::Way::ClearStack,
  183. MsgId msgId = ShowAtUnreadMsgId) = 0;
  184. void showPeerHistory(
  185. not_null<PeerData*> peer,
  186. const SectionShow &params = SectionShow::Way::ClearStack,
  187. MsgId msgId = ShowAtUnreadMsgId);
  188. void showPeerHistory(
  189. not_null<History*> history,
  190. const SectionShow &params = SectionShow::Way::ClearStack,
  191. MsgId msgId = ShowAtUnreadMsgId);
  192. void clearSectionStack(
  193. const SectionShow &params = SectionShow::Way::ClearStack) {
  194. showPeerHistory(
  195. PeerId(0),
  196. params,
  197. ShowAtUnreadMsgId);
  198. }
  199. void showByInitialId(
  200. const SectionShow &params = SectionShow::Way::ClearStack,
  201. MsgId msgId = ShowAtUnreadMsgId);
  202. void showSettings(
  203. Settings::Type type,
  204. const SectionShow &params = SectionShow());
  205. void showSettings(const SectionShow &params = SectionShow());
  206. void showPollResults(
  207. not_null<PollData*> poll,
  208. FullMsgId contextId,
  209. const SectionShow &params = SectionShow());
  210. void searchInChat(Dialogs::Key inChat, PeerData *searchFrom = nullptr);
  211. void searchMessages(
  212. const QString &query,
  213. Dialogs::Key inChat,
  214. PeerData *searchFrom = nullptr);
  215. void resolveBoostState(
  216. not_null<ChannelData*> channel,
  217. int boostsToLift = 0);
  218. void resolveCollectible(
  219. PeerId ownerId,
  220. const QString &entity,
  221. Fn<void(QString)> fail = nullptr);
  222. base::weak_ptr<Ui::Toast::Instance> showToast(
  223. Ui::Toast::Config &&config);
  224. base::weak_ptr<Ui::Toast::Instance> showToast(
  225. TextWithEntities &&text,
  226. crl::time duration = 0);
  227. base::weak_ptr<Ui::Toast::Instance> showToast(
  228. const QString &text,
  229. crl::time duration = 0);
  230. [[nodiscard]] virtual std::shared_ptr<ChatHelpers::Show> uiShow();
  231. private:
  232. void resolvePhone(
  233. const QString &phone,
  234. Fn<void(not_null<PeerData*>)> done);
  235. void resolveChatLink(
  236. const QString &slug,
  237. Fn<void(not_null<PeerData*> peer, TextWithEntities draft)> done);
  238. void resolveUsername(
  239. const QString &username,
  240. Fn<void(not_null<PeerData*>)> done,
  241. const QString &starref = QString());
  242. void resolveChannelById(
  243. ChannelId channelId,
  244. Fn<void(not_null<ChannelData*>)> done);
  245. void resolveDone(
  246. const MTPcontacts_ResolvedPeer &result,
  247. Fn<void(not_null<PeerData*>)> done);
  248. void showMessageByLinkResolved(
  249. not_null<HistoryItem*> item,
  250. const PeerByLinkInfo &info);
  251. void showPeerByLinkResolved(
  252. not_null<PeerData*> peer,
  253. const PeerByLinkInfo &info);
  254. void joinVoiceChatFromLink(
  255. not_null<PeerData*> peer,
  256. const PeerByLinkInfo &info);
  257. void applyBoost(
  258. not_null<ChannelData*> channel,
  259. Fn<void(Ui::BoostCounters)> done);
  260. void applyBoostsChecked(
  261. not_null<ChannelData*> channel,
  262. std::vector<int> slots,
  263. Fn<void(Ui::BoostCounters)> done);
  264. const not_null<Main::Session*> _session;
  265. MTP::Sender _api;
  266. mtpRequestId _resolveRequestId = 0;
  267. History *_showingRepliesHistory = nullptr;
  268. MsgId _showingRepliesRootId = 0;
  269. mtpRequestId _showingRepliesRequestId = 0;
  270. ChannelData *_boostStateResolving = nullptr;
  271. int _boostsToLift = 0;
  272. QString _collectibleEntity;
  273. mtpRequestId _collectibleRequestId = 0;
  274. };
  275. class SessionController : public SessionNavigation {
  276. public:
  277. SessionController(
  278. not_null<Main::Session*> session,
  279. not_null<Controller*> window);
  280. ~SessionController();
  281. [[nodiscard]] Controller &window() const {
  282. return *_window;
  283. }
  284. [[nodiscard]] SeparateId windowId() const;
  285. [[nodiscard]] bool isPrimary() const;
  286. [[nodiscard]] not_null<::MainWindow*> widget() const;
  287. [[nodiscard]] not_null<MainWidget*> content() const;
  288. [[nodiscard]] Adaptive &adaptive() const;
  289. [[nodiscard]] ChatHelpers::EmojiInteractions &emojiInteractions() const {
  290. return *_emojiInteractions;
  291. }
  292. void setConnectingBottomSkip(int skip);
  293. rpl::producer<int> connectingBottomSkipValue() const;
  294. using FileChosen = ChatHelpers::FileChosen;
  295. void stickerOrEmojiChosen(FileChosen chosen);
  296. [[nodiscard]] rpl::producer<FileChosen> stickerOrEmojiChosen() const;
  297. QPointer<Ui::BoxContent> show(
  298. object_ptr<Ui::BoxContent> content,
  299. Ui::LayerOptions options = Ui::LayerOption::KeepOther,
  300. anim::type animated = anim::type::normal);
  301. void hideLayer(anim::type animated = anim::type::normal);
  302. [[nodiscard]] auto sendingAnimation() const
  303. -> Ui::MessageSendingAnimationController &;
  304. [[nodiscard]] auto tabbedSelector() const
  305. -> not_null<ChatHelpers::TabbedSelector*>;
  306. void takeTabbedSelectorOwnershipFrom(not_null<QWidget*> parent);
  307. [[nodiscard]] bool hasTabbedSelectorOwnership() const;
  308. // This is needed for History TopBar updating when searchInChat
  309. // is changed in the Dialogs::Widget of the current window.
  310. rpl::producer<Dialogs::Key> searchInChatValue() const {
  311. return _searchInChat.value();
  312. }
  313. void setSearchInChat(Dialogs::Key value) {
  314. _searchInChat = value;
  315. }
  316. bool uniqueChatsInSearchResults() const;
  317. void openFolder(not_null<Data::Folder*> folder);
  318. void closeFolder();
  319. const rpl::variable<Data::Folder*> &openedFolder() const;
  320. void showForum(
  321. not_null<Data::Forum*> forum,
  322. const SectionShow &params = SectionShow::Way::ClearStack);
  323. void closeForum();
  324. const rpl::variable<Data::Forum*> &shownForum() const;
  325. void setActiveChatEntry(Dialogs::RowDescriptor row);
  326. void setActiveChatEntry(Dialogs::Key key);
  327. Dialogs::RowDescriptor activeChatEntryCurrent() const;
  328. Dialogs::Key activeChatCurrent() const;
  329. rpl::producer<Dialogs::RowDescriptor> activeChatEntryChanges() const;
  330. rpl::producer<Dialogs::Key> activeChatChanges() const;
  331. rpl::producer<Dialogs::RowDescriptor> activeChatEntryValue() const;
  332. rpl::producer<Dialogs::Key> activeChatValue() const;
  333. bool jumpToChatListEntry(Dialogs::RowDescriptor row);
  334. void setDialogsEntryState(Dialogs::EntryState state);
  335. [[nodiscard]] Dialogs::EntryState dialogsEntryStateCurrent() const;
  336. [[nodiscard]] auto dialogsEntryStateValue() const
  337. -> rpl::producer<Dialogs::EntryState>;
  338. bool switchInlineQuery(
  339. Dialogs::EntryState to,
  340. not_null<UserData*> bot,
  341. const QString &query);
  342. bool switchInlineQuery(
  343. not_null<Data::Thread*> thread,
  344. not_null<UserData*> bot,
  345. const QString &query);
  346. [[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
  347. Dialogs::RowDescriptor from = {}) const;
  348. [[nodiscard]] Dialogs::RowDescriptor resolveChatPrevious(
  349. Dialogs::RowDescriptor from = {}) const;
  350. void showEditPeerBox(PeerData *peer);
  351. void enableGifPauseReason(GifPauseReason reason);
  352. void disableGifPauseReason(GifPauseReason reason);
  353. rpl::producer<> gifPauseLevelChanged() const {
  354. return _gifPauseLevelChanged.events();
  355. }
  356. bool isGifPausedAtLeastFor(GifPauseReason reason) const;
  357. void floatPlayerAreaUpdated();
  358. struct ColumnLayout {
  359. int bodyWidth = 0;
  360. int dialogsWidth = 0;
  361. int chatWidth = 0;
  362. int thirdWidth = 0;
  363. Adaptive::WindowLayout windowLayout = Adaptive::WindowLayout();
  364. };
  365. [[nodiscard]] ColumnLayout computeColumnLayout() const;
  366. int dialogsSmallColumnWidth() const;
  367. void updateColumnLayout() const;
  368. bool canShowThirdSection() const;
  369. bool canShowThirdSectionWithoutResize() const;
  370. bool takeThirdSectionFromLayer();
  371. void resizeForThirdSection();
  372. void closeThirdSection();
  373. [[nodiscard]] bool canShowSeparateWindow(SeparateId id) const;
  374. void showPeer(not_null<PeerData*> peer, MsgId msgId = ShowAtUnreadMsgId);
  375. void startOrJoinGroupCall(not_null<PeerData*> peer);
  376. void startOrJoinGroupCall(
  377. not_null<PeerData*> peer,
  378. Calls::StartGroupCallArgs args);
  379. void showSection(
  380. std::shared_ptr<SectionMemento> memento,
  381. const SectionShow &params = SectionShow()) override;
  382. void showBackFromStack(
  383. const SectionShow &params = SectionShow()) override;
  384. using SessionNavigation::showPeerHistory;
  385. void showPeerHistory(
  386. PeerId peerId,
  387. const SectionShow &params = SectionShow::Way::ClearStack,
  388. MsgId msgId = ShowAtUnreadMsgId) override;
  389. void showMessage(
  390. not_null<const HistoryItem*> item,
  391. const SectionShow &params = SectionShow::Way::ClearStack);
  392. void cancelUploadLayer(not_null<HistoryItem*> item);
  393. void showLayer(
  394. std::unique_ptr<Ui::LayerWidget> &&layer,
  395. Ui::LayerOptions options,
  396. anim::type animated = anim::type::normal);
  397. void showSpecialLayer(
  398. object_ptr<Ui::LayerWidget> &&layer,
  399. anim::type animated = anim::type::normal);
  400. void hideSpecialLayer(
  401. anim::type animated = anim::type::normal) {
  402. showSpecialLayer(nullptr, animated);
  403. }
  404. void removeLayerBlackout();
  405. [[nodiscard]] bool isLayerShown() const;
  406. void showCalendar(
  407. Dialogs::Key chat,
  408. QDate requestedDate);
  409. void showAddContact();
  410. void showNewGroup();
  411. void showNewChannel();
  412. void showPassportForm(const Passport::FormRequest &request);
  413. void clearPassportForm();
  414. struct MessageContext {
  415. FullMsgId id;
  416. MsgId topicRootId;
  417. };
  418. void openPhoto(
  419. not_null<PhotoData*> photo,
  420. MessageContext message,
  421. const Data::StoriesContext *stories = nullptr);
  422. void openPhoto(not_null<PhotoData*> photo, not_null<PeerData*> peer);
  423. void openDocument(
  424. not_null<DocumentData*> document,
  425. bool showInMediaView,
  426. MessageContext message,
  427. const Data::StoriesContext *stories = nullptr,
  428. std::optional<TimeId> videoTimestampOverride = {});
  429. bool openSharedStory(HistoryItem *item);
  430. bool openFakeItemStory(
  431. FullMsgId fakeItemId,
  432. const Data::StoriesContext *stories = nullptr);
  433. void showChooseReportMessages(
  434. not_null<PeerData*> peer,
  435. Data::ReportInput reportInput,
  436. Fn<void(std::vector<MsgId>)> done) const;
  437. void clearChooseReportMessages() const;
  438. void showInNewWindow(
  439. SeparateId id,
  440. MsgId msgId = ShowAtUnreadMsgId);
  441. void toggleChooseChatTheme(
  442. not_null<PeerData*> peer,
  443. std::optional<bool> show = std::nullopt) const;
  444. void finishChatThemeEdit(not_null<PeerData*> peer);
  445. [[nodiscard]] bool mainSectionShown() const {
  446. return _mainSectionShown.current();
  447. }
  448. [[nodiscard]] rpl::producer<bool> mainSectionShownChanges() const {
  449. return _mainSectionShown.changes();
  450. }
  451. void setMainSectionShown(bool value) {
  452. _mainSectionShown = value;
  453. }
  454. [[nodiscard]] bool chatsForceDisplayWide() const {
  455. return _chatsForceDisplayWide.current();
  456. }
  457. [[nodiscard]] auto chatsForceDisplayWideChanges() const
  458. -> rpl::producer<bool> {
  459. return _chatsForceDisplayWide.changes();
  460. }
  461. void setChatsForceDisplayWide(bool value) {
  462. _chatsForceDisplayWide = value;
  463. }
  464. not_null<SessionController*> parentController() override {
  465. return this;
  466. }
  467. [[nodiscard]] int filtersWidth() const;
  468. [[nodiscard]] bool enoughSpaceForFilters() const;
  469. [[nodiscard]] rpl::producer<bool> enoughSpaceForFiltersValue() const;
  470. [[nodiscard]] rpl::producer<FilterId> activeChatsFilter() const;
  471. [[nodiscard]] FilterId activeChatsFilterCurrent() const;
  472. void setActiveChatsFilter(
  473. FilterId id,
  474. const SectionShow &params = SectionShow::Way::ClearStack);
  475. void toggleFiltersMenu(bool enabled);
  476. [[nodiscard]] rpl::producer<> filtersMenuChanged() const;
  477. [[nodiscard]] auto defaultChatTheme() const
  478. -> const std::shared_ptr<Ui::ChatTheme> & {
  479. return _defaultChatTheme;
  480. }
  481. [[nodiscard]] auto cachedChatThemeValue(
  482. const Data::CloudTheme &data,
  483. const Data::WallPaper &paper,
  484. Data::CloudThemeType type)
  485. -> rpl::producer<std::shared_ptr<Ui::ChatTheme>>;
  486. [[nodiscard]] bool chatThemeAlreadyCached(
  487. const Data::CloudTheme &data,
  488. const Data::WallPaper &paper,
  489. Data::CloudThemeType type);
  490. void setChatStyleTheme(const std::shared_ptr<Ui::ChatTheme> &theme);
  491. void clearCachedChatThemes();
  492. void pushLastUsedChatTheme(const std::shared_ptr<Ui::ChatTheme> &theme);
  493. [[nodiscard]] not_null<Ui::ChatTheme*> currentChatTheme() const;
  494. void overridePeerTheme(
  495. not_null<PeerData*> peer,
  496. std::shared_ptr<Ui::ChatTheme> theme,
  497. EmojiPtr emoji);
  498. void clearPeerThemeOverride(not_null<PeerData*> peer);
  499. [[nodiscard]] auto peerThemeOverrideValue() const
  500. -> rpl::producer<PeerThemeOverride> {
  501. return _peerThemeOverride.value();
  502. }
  503. void openPeerStory(
  504. not_null<PeerData*> peer,
  505. StoryId storyId,
  506. Data::StoriesContext context);
  507. void openPeerStories(
  508. PeerId peerId,
  509. std::optional<Data::StorySourcesList> list = std::nullopt);
  510. [[nodiscard]] Ui::ChatPaintContext preparePaintContext(
  511. Ui::ChatPaintContextArgs &&args);
  512. [[nodiscard]] not_null<const Ui::ChatStyle*> chatStyle() const {
  513. return _chatStyle.get();
  514. }
  515. [[nodiscard]] QString authedName() const {
  516. return _authedName;
  517. }
  518. void setPremiumRef(const QString &ref);
  519. [[nodiscard]] QString premiumRef() const;
  520. bool showChatPreview(
  521. Dialogs::RowDescriptor row,
  522. Fn<void(bool shown)> callback = nullptr,
  523. QPointer<QWidget> parentOverride = nullptr,
  524. std::optional<QPoint> positionOverride = {});
  525. bool scheduleChatPreview(
  526. Dialogs::RowDescriptor row,
  527. Fn<void(bool shown)> callback = nullptr,
  528. QPointer<QWidget> parentOverride = nullptr,
  529. std::optional<QPoint> positionOverride = {});
  530. void cancelScheduledPreview();
  531. [[nodiscard]] bool contentOverlapped(QWidget *w, QPaintEvent *e) const;
  532. [[nodiscard]] std::shared_ptr<ChatHelpers::Show> uiShow() override;
  533. [[nodiscard]] rpl::lifetime &lifetime() {
  534. return _lifetime;
  535. }
  536. private:
  537. struct CachedThemeKey;
  538. struct CachedTheme;
  539. void init();
  540. void setupShortcuts();
  541. void checkOpenedFilter();
  542. void suggestArchiveAndMute();
  543. void activateFirstChatsFilter();
  544. int minimalThreeColumnWidth() const;
  545. int countDialogsWidthFromRatio(int bodyWidth) const;
  546. int countThirdColumnWidthFromRatio(int bodyWidth) const;
  547. struct ShrinkResult {
  548. int dialogsWidth;
  549. int thirdWidth;
  550. };
  551. ShrinkResult shrinkDialogsAndThirdColumns(
  552. int dialogsWidth,
  553. int thirdWidth,
  554. int bodyWidth) const;
  555. void pushToChatEntryHistory(Dialogs::RowDescriptor row);
  556. bool chatEntryHistoryMove(int steps);
  557. void resetFakeUnreadWhileOpened();
  558. void checkInvitePeek();
  559. void setupPremiumToast();
  560. void pushDefaultChatBackground();
  561. void cacheChatTheme(
  562. CachedThemeKey key,
  563. const Data::CloudTheme &data,
  564. const Data::WallPaper &paper,
  565. Data::CloudThemeType type);
  566. void cacheChatThemeDone(std::shared_ptr<Ui::ChatTheme> result);
  567. void updateCustomThemeBackground(CachedTheme &theme);
  568. [[nodiscard]] Ui::ChatThemeBackgroundData backgroundData(
  569. CachedTheme &theme,
  570. bool generateGradient = true) const;
  571. [[nodiscard]] bool skipNonPremiumLimitToast(bool download) const;
  572. void checkNonPremiumLimitToastDownload(DocumentId id);
  573. void checkNonPremiumLimitToastUpload(FullMsgId id);
  574. bool openFolderInDifferentWindow(not_null<Data::Folder*> folder);
  575. bool showForumInDifferentWindow(
  576. not_null<Data::Forum*> forum,
  577. const SectionShow &params);
  578. const not_null<Controller*> _window;
  579. const std::unique_ptr<ChatHelpers::EmojiInteractions> _emojiInteractions;
  580. const std::unique_ptr<ChatPreviewManager> _chatPreviewManager;
  581. const bool _isPrimary = false;
  582. const bool _hasDialogs = false;
  583. mutable std::shared_ptr<ChatHelpers::Show> _cachedShow;
  584. QString _authedName;
  585. using SendingAnimation = Ui::MessageSendingAnimationController;
  586. const std::unique_ptr<SendingAnimation> _sendingAnimation;
  587. std::unique_ptr<Passport::FormController> _passportForm;
  588. std::unique_ptr<FiltersMenu> _filters;
  589. GifPauseReasons _gifPauseReasons = 0;
  590. rpl::event_stream<> _gifPauseLevelChanged;
  591. // Depends on _gifPause*.
  592. const std::unique_ptr<ChatHelpers::TabbedSelector> _tabbedSelector;
  593. rpl::variable<Dialogs::Key> _searchInChat;
  594. rpl::variable<Dialogs::RowDescriptor> _activeChatEntry;
  595. rpl::lifetime _activeHistoryLifetime;
  596. rpl::variable<bool> _mainSectionShown = false;
  597. rpl::variable<bool> _chatsForceDisplayWide = false;
  598. std::deque<Dialogs::RowDescriptor> _chatEntryHistory;
  599. int _chatEntryHistoryPosition = -1;
  600. bool _filtersActivated = false;
  601. rpl::variable<Dialogs::EntryState> _dialogsEntryState;
  602. base::Timer _invitePeekTimer;
  603. rpl::variable<FilterId> _activeChatsFilter;
  604. rpl::variable<int> _connectingBottomSkip;
  605. rpl::event_stream<ChatHelpers::FileChosen> _stickerOrEmojiChosen;
  606. PeerData *_showEditPeer = nullptr;
  607. rpl::variable<Data::Folder*> _openedFolder;
  608. rpl::variable<Data::Forum*> _shownForum;
  609. rpl::lifetime _shownForumLifetime;
  610. rpl::event_stream<> _filtersMenuChanged;
  611. const std::shared_ptr<Ui::ChatTheme> _defaultChatTheme;
  612. base::flat_map<CachedThemeKey, CachedTheme> _customChatThemes;
  613. rpl::event_stream<std::shared_ptr<Ui::ChatTheme>> _cachedThemesStream;
  614. const std::unique_ptr<Ui::ChatStyle> _chatStyle;
  615. std::weak_ptr<Ui::ChatTheme> _chatStyleTheme;
  616. std::deque<std::shared_ptr<Ui::ChatTheme>> _lastUsedCustomChatThemes;
  617. rpl::variable<PeerThemeOverride> _peerThemeOverride;
  618. base::has_weak_ptr _storyOpenGuard;
  619. QString _premiumRef;
  620. rpl::lifetime _lifetime;
  621. };
  622. void ActivateWindow(not_null<SessionController*> controller);
  623. [[nodiscard]] bool IsPaused(
  624. not_null<SessionController*> controller,
  625. GifPauseReason level);
  626. [[nodiscard]] Fn<bool()> PausedIn(
  627. not_null<SessionController*> controller,
  628. GifPauseReason level);
  629. bool CheckAndJumpToNearChatsFilter(
  630. not_null<SessionController*> controller,
  631. bool isNext,
  632. bool jump);
  633. } // namespace Window