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_mark_unread" = "Mark as unread";
"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_collapse" = "Collapse";
"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_controller.h"
#include "window/window_main_menu.h"
#include "window/window_peer_menu.h"
#include "main/main_session.h"
#include "data/data_session.h"
#include "data/data_chat_filters.h"
@ -307,12 +308,27 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
return;
}
_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),
crl::guard(&_outer, [=] { showEditBox(id); }));
_popupMenu->addAction(
[=] { showEditBox(id); });
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),
crl::guard(&_outer, [=] { showRemoveBox(id); }));
[=] { showRemoveBox(id); });
_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/themes/window_theme.h"
#include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
@ -599,20 +600,21 @@ MainMenu::MainMenu(
}
void MainMenu::setupArchiveButton() {
const auto controller = _controller;
const auto folder = [=] {
return controller->session().data().folderLoaded(Data::Folder::kId);
};
const auto showArchive = [=] {
const auto folder = _controller->session().data().folderLoaded(
Data::Folder::kId);
if (folder) {
_controller->openFolder(folder);
if (const auto f = folder()) {
controller->openFolder(f);
Ui::hideSettingsAndLayer();
}
};
const auto checkArchive = [=] {
const auto folder = _controller->session().data().folderLoaded(
Data::Folder::kId);
return folder
&& !folder->chatsList()->empty()
&& _controller->session().settings().archiveInMainMenu();
const auto f = folder();
return f
&& !f->chatsList()->empty()
&& controller->session().settings().archiveInMainMenu();
};
_archiveButton->setVisible(checkArchive());
_archiveButton->setAcceptBoth(true);
@ -625,16 +627,26 @@ void MainMenu::setupArchiveButton() {
return;
}
_contextMenu = base::make_unique_q<Ui::PopupMenu>(this);
_contextMenu->addAction(
tr::lng_context_archive_to_list(tr::now), [=] {
_controller->session().settings().setArchiveInMainMenu(false);
_controller->session().saveSettingsDelayed();
const auto addAction = [&](const QString &text, Fn<void()> callback) {
return _contextMenu->addAction(text, std::move(callback));
};
const auto hide = [=] {
controller->session().settings().setArchiveInMainMenu(false);
controller->session().saveSettingsDelayed();
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());
}, _archiveButton->lifetime());
_controller->session().data().chatsListChanges(
controller->session().data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) {
return folder && (folder->id() == Data::Folder::kId);
}) | rpl::start_with_next([=](Data::Folder *folder) {

View File

@ -65,6 +65,7 @@ namespace Window {
namespace {
constexpr auto kArchivedToastDuration = crl::time(5000);
constexpr auto kMaxUnreadWithoutConfirmation = 10000;
class Filler {
public:
@ -710,6 +711,11 @@ void FolderFiller::addTogglesForArchive() {
!controller->session().settings().archiveInMainMenu());
controller->session().saveSettingsDelayed();
});
MenuAddMarkAsReadChatListAction(
&controller->session().data(),
[folder = _folder] { return folder->chatsList(); },
_addAction);
}
//
//void FolderFiller::addInfo() {
@ -1130,6 +1136,51 @@ void PeerMenuAddMuteAction(
muteAction->setText(muteText(!enabled));
}, *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
//void PeerMenuUngroupFeed(not_null<Data::Feed*> feed) {
// Ui::show(Box<ConfirmBox>(

View File

@ -19,8 +19,13 @@ class GenericBox;
namespace Data {
class Folder;
class Session;
} // namespace Data
namespace Dialogs {
class MainList;
} // namespace Dialogs
namespace Window {
class Controller;
@ -54,6 +59,11 @@ void PeerMenuAddMuteAction(
not_null<PeerData*> peer,
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 PeerMenuDeleteContact(not_null<UserData*> user);
void PeerMenuShareContactBox(