Moved out unread state values of main list to separated file.

This commit is contained in:
23rd 2024-11-02 17:00:18 +03:00
parent 36924da59a
commit b11b5caeb3
4 changed files with 86 additions and 38 deletions

View file

@ -636,6 +636,8 @@ PRIVATE
data/data_thread.h
data/data_types.cpp
data/data_types.h
data/data_unread_value.cpp
data/data_unread_value.h
data/data_user.cpp
data/data_user.h
data/data_user_photos.cpp

View file

@ -0,0 +1,53 @@
/*
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
*/
#include "data/data_unread_value.h"
#include "data/data_chat_filters.h"
#include "data/data_folder.h"
#include "data/data_session.h"
#include "main/main_session.h"
namespace Data {
namespace {
rpl::producer<Dialogs::UnreadState> MainListUnreadState(
not_null<Dialogs::MainList*> list) {
return rpl::single(rpl::empty) | rpl::then(
list->unreadStateChanges() | rpl::to_empty
) | rpl::map([=] {
return list->unreadState();
});
}
} // namespace
[[nodiscard]] Dialogs::UnreadState MainListMapUnreadState(
not_null<Main::Session*> session,
const Dialogs::UnreadState &state) {
const auto folderId = Data::Folder::kId;
if (const auto folder = session->data().folderLoaded(folderId)) {
return state - folder->chatsList()->unreadState();
}
return state;
}
rpl::producer<Dialogs::UnreadState> UnreadStateValue(
not_null<Main::Session*> session,
FilterId filterId) {
if (filterId > 0) {
const auto filters = &session->data().chatsFilters();
return MainListUnreadState(filters->chatsList(filterId));
}
return MainListUnreadState(
session->data().chatsList()
) | rpl::map([=](const Dialogs::UnreadState &state) {
return MainListMapUnreadState(session, state);
});
}
} // namespace Data

View file

@ -0,0 +1,28 @@
/*
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
*/
#pragma once
namespace Dialogs {
struct UnreadState;
} // namespace Dialogs
namespace Main {
class Session;
} // namespace Main
namespace Data {
[[nodiscard]] Dialogs::UnreadState MainListMapUnreadState(
not_null<Main::Session*> session,
const Dialogs::UnreadState &state);
[[nodiscard]] rpl::producer<Dialogs::UnreadState> UnreadStateValue(
not_null<Main::Session*> session,
FilterId filterId);
} // namespace Data

View file

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_peer_values.h"
#include "data/data_premium_limits.h"
#include "data/data_unread_value.h"
#include "lang/lang_keys.h"
#include "ui/filter_icons.h"
#include "ui/wrap/vertical_layout.h"
@ -41,42 +42,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_menu_icons.h"
namespace Window {
namespace {
[[nodiscard]] Dialogs::UnreadState MainListMapUnreadState(
not_null<Main::Session*> session,
const Dialogs::UnreadState &state) {
const auto folderId = Data::Folder::kId;
if (const auto folder = session->data().folderLoaded(folderId)) {
return state - folder->chatsList()->unreadState();
}
return state;
}
[[nodiscard]] rpl::producer<Dialogs::UnreadState> MainListUnreadState(
not_null<Dialogs::MainList*> list) {
return rpl::single(rpl::empty) | rpl::then(
list->unreadStateChanges() | rpl::to_empty
) | rpl::map([=] {
return list->unreadState();
});
}
[[nodiscard]] rpl::producer<Dialogs::UnreadState> UnreadStateValue(
not_null<Main::Session*> session,
FilterId filterId) {
if (filterId > 0) {
const auto filters = &session->data().chatsFilters();
return MainListUnreadState(filters->chatsList(filterId));
}
return MainListUnreadState(
session->data().chatsList()
) | rpl::map([=](const Dialogs::UnreadState &state) {
return MainListMapUnreadState(session, state);
});
}
} // namespace
FiltersMenu::FiltersMenu(
not_null<Ui::RpWidget*> parent,
@ -310,7 +275,7 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
raw->setIconOverride(icons.normal, icons.active);
if (id >= 0) {
rpl::combine(
UnreadStateValue(&_session->session(), id),
Data::UnreadStateValue(&_session->session(), id),
_includeMuted.value()
) | rpl::start_with_next([=](
const Dialogs::UnreadState &state,
@ -431,7 +396,7 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
} else {
auto customUnreadState = [=] {
const auto session = &_session->session();
return MainListMapUnreadState(
return Data::MainListMapUnreadState(
session,
session->data().chatsList()->unreadState());
};