2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

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

@@ -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>(