Added ability to mark as read chats from folder from context menu.

Fixed #7507.
Fixed #6004.
This commit is contained in:
23rd 2020-09-16 17:09:04 +03:00 committed by John Preston
parent 5968219fe4
commit bdce2d5e25
5 changed files with 109 additions and 19 deletions

View file

@ -1457,6 +1457,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_unpin_from_top" = "Unpin from top"; "lng_context_unpin_from_top" = "Unpin from top";
"lng_context_mark_unread" = "Mark as unread"; "lng_context_mark_unread" = "Mark as unread";
"lng_context_mark_read" = "Mark as read"; "lng_context_mark_read" = "Mark as read";
"lng_context_mark_read_sure" = "Are you sure you want to mark all chats from this folder as read?";
"lng_context_archive_expand" = "Expand"; "lng_context_archive_expand" = "Expand";
"lng_context_archive_collapse" = "Collapse"; "lng_context_archive_collapse" = "Collapse";
"lng_context_archive_to_menu" = "Move to main menu"; "lng_context_archive_to_menu" = "Move to main menu";

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "window/window_main_menu.h" #include "window/window_main_menu.h"
#include "window/window_peer_menu.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_chat_filters.h" #include "data/data_chat_filters.h"
@ -307,12 +308,27 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
return; return;
} }
_popupMenu = base::make_unique_q<Ui::PopupMenu>(i->second.get()); _popupMenu = base::make_unique_q<Ui::PopupMenu>(i->second.get());
_popupMenu->addAction( const auto addAction = [&](const QString &text, Fn<void()> callback) {
return _popupMenu->addAction(
text,
crl::guard(&_outer, std::move(callback)));
};
addAction(
tr::lng_filters_context_edit(tr::now), tr::lng_filters_context_edit(tr::now),
crl::guard(&_outer, [=] { showEditBox(id); })); [=] { showEditBox(id); });
_popupMenu->addAction(
auto filteredChats = [=] {
return _session->session().data().chatsFilters().chatsList(id);
};
Window::MenuAddMarkAsReadChatListAction(
&_session->session().data(),
std::move(filteredChats),
addAction);
addAction(
tr::lng_filters_context_remove(tr::now), tr::lng_filters_context_remove(tr::now),
crl::guard(&_outer, [=] { showRemoveBox(id); })); [=] { showRemoveBox(id); });
_popupMenu->popup(position); _popupMenu->popup(position);
} }

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_main_menu.h" #include "window/window_main_menu.h"
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
#include "window/window_peer_menu.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
@ -599,20 +600,21 @@ MainMenu::MainMenu(
} }
void MainMenu::setupArchiveButton() { void MainMenu::setupArchiveButton() {
const auto controller = _controller;
const auto folder = [=] {
return controller->session().data().folderLoaded(Data::Folder::kId);
};
const auto showArchive = [=] { const auto showArchive = [=] {
const auto folder = _controller->session().data().folderLoaded( if (const auto f = folder()) {
Data::Folder::kId); controller->openFolder(f);
if (folder) {
_controller->openFolder(folder);
Ui::hideSettingsAndLayer(); Ui::hideSettingsAndLayer();
} }
}; };
const auto checkArchive = [=] { const auto checkArchive = [=] {
const auto folder = _controller->session().data().folderLoaded( const auto f = folder();
Data::Folder::kId); return f
return folder && !f->chatsList()->empty()
&& !folder->chatsList()->empty() && controller->session().settings().archiveInMainMenu();
&& _controller->session().settings().archiveInMainMenu();
}; };
_archiveButton->setVisible(checkArchive()); _archiveButton->setVisible(checkArchive());
_archiveButton->setAcceptBoth(true); _archiveButton->setAcceptBoth(true);
@ -625,16 +627,26 @@ void MainMenu::setupArchiveButton() {
return; return;
} }
_contextMenu = base::make_unique_q<Ui::PopupMenu>(this); _contextMenu = base::make_unique_q<Ui::PopupMenu>(this);
_contextMenu->addAction( const auto addAction = [&](const QString &text, Fn<void()> callback) {
tr::lng_context_archive_to_list(tr::now), [=] { return _contextMenu->addAction(text, std::move(callback));
_controller->session().settings().setArchiveInMainMenu(false); };
_controller->session().saveSettingsDelayed();
const auto hide = [=] {
controller->session().settings().setArchiveInMainMenu(false);
controller->session().saveSettingsDelayed();
Ui::hideSettingsAndLayer(); Ui::hideSettingsAndLayer();
}); };
addAction(tr::lng_context_archive_to_list(tr::now), std::move(hide));
MenuAddMarkAsReadChatListAction(
&controller->session().data(),
[f = folder()] { return f->chatsList(); },
addAction);
_contextMenu->popup(QCursor::pos()); _contextMenu->popup(QCursor::pos());
}, _archiveButton->lifetime()); }, _archiveButton->lifetime());
_controller->session().data().chatsListChanges( controller->session().data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) { ) | rpl::filter([](Data::Folder *folder) {
return folder && (folder->id() == Data::Folder::kId); return folder && (folder->id() == Data::Folder::kId);
}) | rpl::start_with_next([=](Data::Folder *folder) { }) | rpl::start_with_next([=](Data::Folder *folder) {

View file

@ -65,6 +65,7 @@ namespace Window {
namespace { namespace {
constexpr auto kArchivedToastDuration = crl::time(5000); constexpr auto kArchivedToastDuration = crl::time(5000);
constexpr auto kMaxUnreadWithoutConfirmation = 10000;
class Filler { class Filler {
public: public:
@ -710,6 +711,11 @@ void FolderFiller::addTogglesForArchive() {
!controller->session().settings().archiveInMainMenu()); !controller->session().settings().archiveInMainMenu());
controller->session().saveSettingsDelayed(); controller->session().saveSettingsDelayed();
}); });
MenuAddMarkAsReadChatListAction(
&controller->session().data(),
[folder = _folder] { return folder->chatsList(); },
_addAction);
} }
// //
//void FolderFiller::addInfo() { //void FolderFiller::addInfo() {
@ -1130,6 +1136,51 @@ void PeerMenuAddMuteAction(
muteAction->setText(muteText(!enabled)); muteAction->setText(muteText(!enabled));
}, *lifetime); }, *lifetime);
} }
void MenuAddMarkAsReadChatListAction(
not_null<Data::Session*> data,
Fn<not_null<Dialogs::MainList*>()> list,
const PeerMenuCallback &addAction) {
const auto owner = data;
const auto unreadState = list()->unreadState();
if (unreadState.empty()) {
return;
}
const auto read = [=](not_null<History*> history) {
if ((history->chatListUnreadCount() > 0)
|| history->chatListUnreadMark()) {
owner->histories().readInbox(history);
}
};
const auto markAsRead = [=] {
for (const auto row : list()->indexed()->all()) {
if (const auto history = row->history()) {
read(history);
if (const auto migrated = history->migrateSibling()) {
read(migrated);
}
}
}
};
auto callback = [=] {
if (unreadState.messages > kMaxUnreadWithoutConfirmation) {
auto boxCallback = [=](Fn<void()> &&close) {
markAsRead();
close();
};
Ui::show(Box<ConfirmBox>(
tr::lng_context_mark_read_sure(tr::now),
std::move(boxCallback)));
} else {
markAsRead();
}
};
addAction(
tr::lng_context_mark_read(tr::now),
std::move(callback));
}
// #feed // #feed
//void PeerMenuUngroupFeed(not_null<Data::Feed*> feed) { //void PeerMenuUngroupFeed(not_null<Data::Feed*> feed) {
// Ui::show(Box<ConfirmBox>( // Ui::show(Box<ConfirmBox>(

View file

@ -19,8 +19,13 @@ class GenericBox;
namespace Data { namespace Data {
class Folder; class Folder;
class Session;
} // namespace Data } // namespace Data
namespace Dialogs {
class MainList;
} // namespace Dialogs
namespace Window { namespace Window {
class Controller; class Controller;
@ -54,6 +59,11 @@ void PeerMenuAddMuteAction(
not_null<PeerData*> peer, not_null<PeerData*> peer,
const PeerMenuCallback &addAction); const PeerMenuCallback &addAction);
void MenuAddMarkAsReadChatListAction(
not_null<Data::Session*> data,
Fn<not_null<Dialogs::MainList*>()> list,
const PeerMenuCallback &addAction);
void PeerMenuExportChat(not_null<PeerData*> peer); void PeerMenuExportChat(not_null<PeerData*> peer);
void PeerMenuDeleteContact(not_null<UserData*> user); void PeerMenuDeleteContact(not_null<UserData*> user);
void PeerMenuShareContactBox( void PeerMenuShareContactBox(