diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b677abe99..644eed06a 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1751,6 +1751,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_mark_read_all" = "Mark all chats as read"; "lng_context_mark_read_all_sure" = "Are you sure you want to mark all chats as read?"; "lng_context_mark_read_mentions_all" = "Mark all mentions as read"; +"lng_context_mark_read_reactions_all" = "Read all reactions"; "lng_context_archive_expand" = "Expand"; "lng_context_archive_collapse" = "Collapse"; "lng_context_archive_to_menu" = "Move to main menu"; diff --git a/Telegram/SourceFiles/chat_helpers/send_context_menu.cpp b/Telegram/SourceFiles/chat_helpers/send_context_menu.cpp index 93ae5f1e1..e68abf700 100644 --- a/Telegram/SourceFiles/chat_helpers/send_context_menu.cpp +++ b/Telegram/SourceFiles/chat_helpers/send_context_menu.cpp @@ -15,7 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/widgets/popup_menu.h" #include "data/data_peer.h" +#include "data/data_session.h" #include "main/main_session.h" +#include "history/history.h" +#include "history/history_unread_things.h" #include "apiwrap.h" #include "styles/style_menu_icons.h" @@ -143,9 +146,11 @@ void SetupMenuAndShortcuts( }, button->lifetime()); } -void SetupUnreadMentionsMenu( +void SetupReadAllMenu( not_null button, - Fn currentPeer) { + Fn currentPeer, + const QString &text, + Fn, Fn)> sendReadRequest) { struct State { base::unique_qptr menu; base::flat_set> sentForPeers; @@ -159,19 +164,11 @@ void SetupUnreadMentionsMenu( state->menu = base::make_unique_q( button, st::popupMenuWithIcons); - const auto text = tr::lng_context_mark_read_mentions_all(tr::now); state->menu->addAction(text, [=] { if (!state->sentForPeers.emplace(peer).second) { return; } - peer->session().api().request(MTPmessages_ReadMentions( - peer->input - )).done([=](const MTPmessages_AffectedHistory &result) { - state->sentForPeers.remove(peer); - peer->session().api().applyAffectedHistory(peer, result); - }).fail([=] { - state->sentForPeers.remove(peer); - }).send(); + sendReadRequest(peer, [=] { state->sentForPeers.remove(peer); }); }, &st::menuIconMarkRead); state->menu->popup(QCursor::pos()); }; @@ -185,9 +182,36 @@ void SetupUnreadMentionsMenu( }); } +void SetupUnreadMentionsMenu( + not_null button, + Fn currentPeer) { + const auto text = tr::lng_context_mark_read_mentions_all(tr::now); + const auto sendRequest = [=](not_null peer, Fn done) { + peer->session().api().request(MTPmessages_ReadMentions( + peer->input + )).done([=](const MTPmessages_AffectedHistory &result) { + done(); + peer->session().api().applyAffectedHistory(peer, result); + peer->owner().history(peer)->unreadMentions().clear(); + }).fail(done).send(); + }; + SetupReadAllMenu(button, currentPeer, text, sendRequest); +} + void SetupUnreadReactionsMenu( not_null button, Fn currentPeer) { + const auto text = tr::lng_context_mark_read_reactions_all(tr::now); + const auto sendRequest = [=](not_null peer, Fn done) { + peer->session().api().request(MTPmessages_ReadReactions( + peer->input + )).done([=](const MTPmessages_AffectedHistory &result) { + done(); + peer->session().api().applyAffectedHistory(peer, result); + peer->owner().history(peer)->unreadReactions().clear(); + }).fail(done).send(); + }; + SetupReadAllMenu(button, currentPeer, text, sendRequest); } } // namespace SendMenu diff --git a/Telegram/SourceFiles/history/history_unread_things.cpp b/Telegram/SourceFiles/history/history_unread_things.cpp index 663ce371d..88701d9f2 100644 --- a/Telegram/SourceFiles/history/history_unread_things.cpp +++ b/Telegram/SourceFiles/history/history_unread_things.cpp @@ -16,6 +16,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" namespace HistoryUnreadThings { +namespace { + +[[nodiscard]] Data::HistoryUpdate::Flag UpdateFlag(Type type) { + using Flag = Data::HistoryUpdate::Flag; + switch (type) { + case Type::Mentions: return Flag::UnreadMentions; + case Type::Reactions: return Flag::UnreadReactions; + } + Unexpected("Type in Proxy::addSlice."); +} + +} // namespace void Proxy::setCount(int count) { if (!_known) { @@ -34,21 +46,20 @@ void Proxy::setCount(int count) { "real count is greater than received unread count")); count = loaded; } - if (!count) { - const auto &other = (_type == Type::Mentions) - ? _data->reactions - : _data->mentions; - if (other.count(-1) == 0) { - _data = nullptr; - return; - } - } - const auto had = (list.count() > 0); - list.setCount(count); + const auto &other = (_type == Type::Mentions) + ? _data->reactions + : _data->mentions; + if (!count && other.count(-1) == 0) { + _data = nullptr; + } else { + list.setCount(count); + } const auto has = (count > 0); if (has != had) { - _history->owner().chatsFilters().refreshHistory(_history); + if (_type == Type::Mentions) { + _history->owner().chatsFilters().refreshHistory(_history); + } _history->updateChatListEntry(); } } @@ -91,7 +102,19 @@ void Proxy::erase(MsgId msgId) { } _history->session().changes().historyUpdated( _history, - Data::HistoryUpdate::Flag::UnreadMentions); + UpdateFlag(_type)); +} + +void Proxy::clear() { + if (!_data || !count()) { + return; + } + auto &list = resolveList(); + list.clear(); + setCount(0); + _history->session().changes().historyUpdated( + _history, + UpdateFlag(_type)); } void Proxy::addSlice(const MTPmessages_Messages &slice) { @@ -158,15 +181,9 @@ void Proxy::addSlice(const MTPmessages_Messages &slice) { fullCount = list.loadedCount(); } setCount(fullCount); - const auto flag = [&] { - using Flag = Data::HistoryUpdate::Flag; - switch (_type) { - case Type::Mentions: return Flag::UnreadMentions; - case Type::Reactions: return Flag::UnreadReactions; - } - Unexpected("Type in Proxy::addSlice."); - }(); - _history->session().changes().historyUpdated(_history, flag); + _history->session().changes().historyUpdated( + _history, + UpdateFlag(_type)); } void Proxy::createData() { diff --git a/Telegram/SourceFiles/history/history_unread_things.h b/Telegram/SourceFiles/history/history_unread_things.h index 387cb58a4..019f5347f 100644 --- a/Telegram/SourceFiles/history/history_unread_things.h +++ b/Telegram/SourceFiles/history/history_unread_things.h @@ -47,6 +47,9 @@ public: void erase(MsgId msgId) { _messages.remove(msgId); } + void clear() { + _messages.clear(); + } private: std::optional _count; @@ -115,6 +118,7 @@ public: void setCount(int count); bool add(MsgId msgId, AddType type); void erase(MsgId msgId); + void clear(); void addSlice(const MTPmessages_Messages &slice);