mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-23 10:47:11 +00:00
54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
|
/*
|
||
|
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
|