mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added ability to mark as read all chats from menu of filter button.
This commit is contained in:
parent
4017d8db7c
commit
19ba685cc3
3 changed files with 54 additions and 25 deletions
|
@ -40,6 +40,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
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(
|
||||
|
@ -59,11 +69,7 @@ namespace {
|
|||
return MainListUnreadState(
|
||||
session->data().chatsList()
|
||||
) | rpl::map([=](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;
|
||||
return MainListMapUnreadState(session, state);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -331,7 +337,7 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
|
|||
raw->setAcceptDrops(true);
|
||||
raw->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||
return ((e->type() == QEvent::ContextMenu) && (id > 0))
|
||||
return ((e->type() == QEvent::ContextMenu) && (id >= 0))
|
||||
|| e->type() == QEvent::DragEnter
|
||||
|| e->type() == QEvent::DragMove
|
||||
|| e->type() == QEvent::DragLeave;
|
||||
|
@ -368,7 +374,7 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
|||
return;
|
||||
}
|
||||
const auto i = _filters.find(id);
|
||||
if (i == end(_filters)) {
|
||||
if ((i == end(_filters)) && id) {
|
||||
return;
|
||||
}
|
||||
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||
|
@ -382,23 +388,41 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
|||
args.icon);
|
||||
});
|
||||
|
||||
addAction(
|
||||
tr::lng_filters_context_edit(tr::now),
|
||||
[=] { showEditBox(id); },
|
||||
&st::menuIconEdit);
|
||||
if (id) {
|
||||
addAction(
|
||||
tr::lng_filters_context_edit(tr::now),
|
||||
[=] { showEditBox(id); },
|
||||
&st::menuIconEdit);
|
||||
|
||||
auto filteredChats = [=] {
|
||||
return _session->session().data().chatsFilters().chatsList(id);
|
||||
};
|
||||
Window::MenuAddMarkAsReadChatListAction(
|
||||
_session,
|
||||
std::move(filteredChats),
|
||||
addAction);
|
||||
auto filteredChats = [=] {
|
||||
return _session->session().data().chatsFilters().chatsList(id);
|
||||
};
|
||||
Window::MenuAddMarkAsReadChatListAction(
|
||||
_session,
|
||||
std::move(filteredChats),
|
||||
addAction);
|
||||
|
||||
addAction(
|
||||
tr::lng_filters_context_remove(tr::now),
|
||||
[=] { showRemoveBox(id); },
|
||||
&st::menuIconDelete);
|
||||
addAction(
|
||||
tr::lng_filters_context_remove(tr::now),
|
||||
[=] { showRemoveBox(id); },
|
||||
&st::menuIconDelete);
|
||||
} else {
|
||||
auto customUnreadState = [=] {
|
||||
const auto session = &_session->session();
|
||||
return MainListMapUnreadState(
|
||||
session,
|
||||
session->data().chatsList()->unreadState());
|
||||
};
|
||||
Window::MenuAddMarkAsReadChatListAction(
|
||||
_session,
|
||||
[=] { return _session->session().data().chatsList(); },
|
||||
addAction,
|
||||
std::move(customUnreadState));
|
||||
}
|
||||
if (_popupMenu->empty()) {
|
||||
_popupMenu = nullptr;
|
||||
return;
|
||||
}
|
||||
_popupMenu->popup(position);
|
||||
}
|
||||
|
||||
|
|
|
@ -2299,9 +2299,12 @@ void MenuAddMarkAsReadAllChatsAction(
|
|||
void MenuAddMarkAsReadChatListAction(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<not_null<Dialogs::MainList*>()> &&list,
|
||||
const PeerMenuCallback &addAction) {
|
||||
const PeerMenuCallback &addAction,
|
||||
Fn<Dialogs::UnreadState()> customUnreadState) {
|
||||
// There is no async to make weak from controller.
|
||||
const auto unreadState = list()->unreadState();
|
||||
const auto unreadState = customUnreadState
|
||||
? customUnreadState()
|
||||
: list()->unreadState();
|
||||
if (!unreadState.messages && !unreadState.marks && !unreadState.chats) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ class Thread;
|
|||
namespace Dialogs {
|
||||
class MainList;
|
||||
struct EntryState;
|
||||
struct UnreadState;
|
||||
} // namespace Dialogs
|
||||
|
||||
namespace ChatHelpers {
|
||||
|
@ -69,7 +70,8 @@ void MenuAddMarkAsReadAllChatsAction(
|
|||
void MenuAddMarkAsReadChatListAction(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<not_null<Dialogs::MainList*>()> &&list,
|
||||
const PeerMenuCallback &addAction);
|
||||
const PeerMenuCallback &addAction,
|
||||
Fn<Dialogs::UnreadState()> customUnreadState = nullptr);
|
||||
|
||||
void PeerMenuExportChat(not_null<PeerData*> peer);
|
||||
void PeerMenuDeleteContact(
|
||||
|
|
Loading…
Add table
Reference in a new issue