data_unread_value.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "data/data_unread_value.h"
  8. #include "core/application.h"
  9. #include "core/core_settings.h"
  10. #include "data/data_chat_filters.h"
  11. #include "data/data_folder.h"
  12. #include "data/data_session.h"
  13. #include "main/main_session.h"
  14. #include "window/notifications_manager.h"
  15. namespace Data {
  16. namespace {
  17. rpl::producer<Dialogs::UnreadState> MainListUnreadState(
  18. not_null<Dialogs::MainList*> list) {
  19. return rpl::single(rpl::empty) | rpl::then(
  20. list->unreadStateChanges() | rpl::to_empty
  21. ) | rpl::map([=] {
  22. return list->unreadState();
  23. });
  24. }
  25. } // namespace
  26. [[nodiscard]] Dialogs::UnreadState MainListMapUnreadState(
  27. not_null<Main::Session*> session,
  28. const Dialogs::UnreadState &state) {
  29. const auto folderId = Data::Folder::kId;
  30. if (const auto folder = session->data().folderLoaded(folderId)) {
  31. return state - folder->chatsList()->unreadState();
  32. }
  33. return state;
  34. }
  35. rpl::producer<Dialogs::UnreadState> UnreadStateValue(
  36. not_null<Main::Session*> session,
  37. FilterId filterId) {
  38. if (filterId > 0) {
  39. const auto filters = &session->data().chatsFilters();
  40. return MainListUnreadState(filters->chatsList(filterId));
  41. }
  42. return MainListUnreadState(
  43. session->data().chatsList()
  44. ) | rpl::map([=](const Dialogs::UnreadState &state) {
  45. return MainListMapUnreadState(session, state);
  46. });
  47. }
  48. rpl::producer<bool> IncludeMutedCounterFoldersValue() {
  49. using namespace Window::Notifications;
  50. return rpl::single(rpl::empty_value()) | rpl::then(
  51. Core::App().notifications().settingsChanged(
  52. ) | rpl::filter(
  53. rpl::mappers::_1 == ChangeType::IncludeMuted
  54. ) | rpl::to_empty
  55. ) | rpl::map([] {
  56. return Core::App().settings().includeMutedCounterFolders();
  57. });
  58. }
  59. } // namespace Data