Added ability to mark as read all chats from menu of filter button.
This commit is contained in:
parent
4017d8db7c
commit
19ba685cc3
|
@ -40,6 +40,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Window {
|
namespace Window {
|
||||||
namespace {
|
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(
|
[[nodiscard]] rpl::producer<Dialogs::UnreadState> MainListUnreadState(
|
||||||
not_null<Dialogs::MainList*> list) {
|
not_null<Dialogs::MainList*> list) {
|
||||||
return rpl::single(rpl::empty) | rpl::then(
|
return rpl::single(rpl::empty) | rpl::then(
|
||||||
|
@ -59,11 +69,7 @@ namespace {
|
||||||
return MainListUnreadState(
|
return MainListUnreadState(
|
||||||
session->data().chatsList()
|
session->data().chatsList()
|
||||||
) | rpl::map([=](const Dialogs::UnreadState &state) {
|
) | rpl::map([=](const Dialogs::UnreadState &state) {
|
||||||
const auto folderId = Data::Folder::kId;
|
return MainListMapUnreadState(session, state);
|
||||||
if (const auto folder = session->data().folderLoaded(folderId)) {
|
|
||||||
return state - folder->chatsList()->unreadState();
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +337,7 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
|
||||||
raw->setAcceptDrops(true);
|
raw->setAcceptDrops(true);
|
||||||
raw->events(
|
raw->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
) | 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::DragEnter
|
||||||
|| e->type() == QEvent::DragMove
|
|| e->type() == QEvent::DragMove
|
||||||
|| e->type() == QEvent::DragLeave;
|
|| e->type() == QEvent::DragLeave;
|
||||||
|
@ -368,7 +374,7 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto i = _filters.find(id);
|
const auto i = _filters.find(id);
|
||||||
if (i == end(_filters)) {
|
if ((i == end(_filters)) && id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
|
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
@ -382,23 +388,41 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
||||||
args.icon);
|
args.icon);
|
||||||
});
|
});
|
||||||
|
|
||||||
addAction(
|
if (id) {
|
||||||
tr::lng_filters_context_edit(tr::now),
|
addAction(
|
||||||
[=] { showEditBox(id); },
|
tr::lng_filters_context_edit(tr::now),
|
||||||
&st::menuIconEdit);
|
[=] { showEditBox(id); },
|
||||||
|
&st::menuIconEdit);
|
||||||
|
|
||||||
auto filteredChats = [=] {
|
auto filteredChats = [=] {
|
||||||
return _session->session().data().chatsFilters().chatsList(id);
|
return _session->session().data().chatsFilters().chatsList(id);
|
||||||
};
|
};
|
||||||
Window::MenuAddMarkAsReadChatListAction(
|
Window::MenuAddMarkAsReadChatListAction(
|
||||||
_session,
|
_session,
|
||||||
std::move(filteredChats),
|
std::move(filteredChats),
|
||||||
addAction);
|
addAction);
|
||||||
|
|
||||||
addAction(
|
addAction(
|
||||||
tr::lng_filters_context_remove(tr::now),
|
tr::lng_filters_context_remove(tr::now),
|
||||||
[=] { showRemoveBox(id); },
|
[=] { showRemoveBox(id); },
|
||||||
&st::menuIconDelete);
|
&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);
|
_popupMenu->popup(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2299,9 +2299,12 @@ void MenuAddMarkAsReadAllChatsAction(
|
||||||
void MenuAddMarkAsReadChatListAction(
|
void MenuAddMarkAsReadChatListAction(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Fn<not_null<Dialogs::MainList*>()> &&list,
|
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.
|
// 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) {
|
if (!unreadState.messages && !unreadState.marks && !unreadState.chats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Thread;
|
||||||
namespace Dialogs {
|
namespace Dialogs {
|
||||||
class MainList;
|
class MainList;
|
||||||
struct EntryState;
|
struct EntryState;
|
||||||
|
struct UnreadState;
|
||||||
} // namespace Dialogs
|
} // namespace Dialogs
|
||||||
|
|
||||||
namespace ChatHelpers {
|
namespace ChatHelpers {
|
||||||
|
@ -69,7 +70,8 @@ void MenuAddMarkAsReadAllChatsAction(
|
||||||
void MenuAddMarkAsReadChatListAction(
|
void MenuAddMarkAsReadChatListAction(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Fn<not_null<Dialogs::MainList*>()> &&list,
|
Fn<not_null<Dialogs::MainList*>()> &&list,
|
||||||
const PeerMenuCallback &addAction);
|
const PeerMenuCallback &addAction,
|
||||||
|
Fn<Dialogs::UnreadState()> customUnreadState = nullptr);
|
||||||
|
|
||||||
void PeerMenuExportChat(not_null<PeerData*> peer);
|
void PeerMenuExportChat(not_null<PeerData*> peer);
|
||||||
void PeerMenuDeleteContact(
|
void PeerMenuDeleteContact(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user