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

Mark [un]read from chats list.

This commit is contained in:
John Preston
2018-06-26 19:03:45 +01:00
parent 372cf275e0
commit 35c759c6bc
15 changed files with 196 additions and 33 deletions

View File

@@ -50,6 +50,7 @@ private:
void addPinToggle();
void addInfo();
void addSearch();
void addToggleUnreadMark();
void addUserActions(not_null<UserData*> user);
void addBlockUser(not_null<UserData*> user);
void addChatActions(not_null<ChatData*> chat);
@@ -229,6 +230,48 @@ void Filler::addSearch() {
});
}
void Filler::addToggleUnreadMark() {
const auto peer = _peer;
const auto isUnread = [](not_null<PeerData*> peer) {
if (const auto history = App::historyLoaded(peer)) {
return (history->chatListUnreadCount() > 0)
|| (history->chatListUnreadMark());
}
return false;
};
const auto label = [=](not_null<PeerData*> peer) {
return lang(isUnread(peer)
? lng_context_mark_read
: lng_context_mark_unread);
};
auto action = _addAction(label(peer), [=] {
const auto markAsRead = isUnread(peer);
const auto handle = [&](not_null<History*> history) {
if (markAsRead) {
Auth().api().readServerHistory(history);
} else {
Auth().api().changeDialogUnreadMark(history, !markAsRead);
}
};
const auto history = App::history(peer);
handle(history);
if (markAsRead) {
if (const auto migrated = history->migrateSibling()) {
handle(migrated);
}
}
});
auto lifetime = Notify::PeerUpdateViewer(
_peer,
Notify::PeerUpdate::Flag::UnreadViewChanged
) | rpl::start_with_next([=] {
action->setText(label(peer));
});
Ui::AttachAsChild(action, std::move(lifetime));
}
void Filler::addBlockUser(not_null<UserData*> user) {
auto blockText = [](not_null<UserData*> user) {
return lang(user->isBlocked()
@@ -401,6 +444,7 @@ void Filler::fill() {
}
if (_source == PeerMenuSource::ChatsList) {
addSearch();
addToggleUnreadMark();
}
if (const auto user = _peer->asUser()) {