Mark all reactions as read context menu.
This commit is contained in:
parent
15719b73b4
commit
f6bfe2c9a8
4 changed files with 79 additions and 33 deletions
|
@ -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" = "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_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_mentions_all" = "Mark all mentions as read";
|
||||||
|
"lng_context_mark_read_reactions_all" = "Read all reactions";
|
||||||
"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";
|
||||||
|
|
|
@ -15,7 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "history/history.h"
|
||||||
|
#include "history/history_unread_things.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
|
@ -143,9 +146,11 @@ void SetupMenuAndShortcuts(
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupUnreadMentionsMenu(
|
void SetupReadAllMenu(
|
||||||
not_null<Ui::RpWidget*> button,
|
not_null<Ui::RpWidget*> button,
|
||||||
Fn<PeerData*()> currentPeer) {
|
Fn<PeerData*()> currentPeer,
|
||||||
|
const QString &text,
|
||||||
|
Fn<void(not_null<PeerData*>, Fn<void()>)> sendReadRequest) {
|
||||||
struct State {
|
struct State {
|
||||||
base::unique_qptr<Ui::PopupMenu> menu;
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
base::flat_set<not_null<PeerData*>> sentForPeers;
|
base::flat_set<not_null<PeerData*>> sentForPeers;
|
||||||
|
@ -159,19 +164,11 @@ void SetupUnreadMentionsMenu(
|
||||||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
button,
|
button,
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
const auto text = tr::lng_context_mark_read_mentions_all(tr::now);
|
|
||||||
state->menu->addAction(text, [=] {
|
state->menu->addAction(text, [=] {
|
||||||
if (!state->sentForPeers.emplace(peer).second) {
|
if (!state->sentForPeers.emplace(peer).second) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
peer->session().api().request(MTPmessages_ReadMentions(
|
sendReadRequest(peer, [=] { state->sentForPeers.remove(peer); });
|
||||||
peer->input
|
|
||||||
)).done([=](const MTPmessages_AffectedHistory &result) {
|
|
||||||
state->sentForPeers.remove(peer);
|
|
||||||
peer->session().api().applyAffectedHistory(peer, result);
|
|
||||||
}).fail([=] {
|
|
||||||
state->sentForPeers.remove(peer);
|
|
||||||
}).send();
|
|
||||||
}, &st::menuIconMarkRead);
|
}, &st::menuIconMarkRead);
|
||||||
state->menu->popup(QCursor::pos());
|
state->menu->popup(QCursor::pos());
|
||||||
};
|
};
|
||||||
|
@ -185,9 +182,36 @@ void SetupUnreadMentionsMenu(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupUnreadMentionsMenu(
|
||||||
|
not_null<Ui::RpWidget*> button,
|
||||||
|
Fn<PeerData*()> currentPeer) {
|
||||||
|
const auto text = tr::lng_context_mark_read_mentions_all(tr::now);
|
||||||
|
const auto sendRequest = [=](not_null<PeerData*> peer, Fn<void()> 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(
|
void SetupUnreadReactionsMenu(
|
||||||
not_null<Ui::RpWidget*> button,
|
not_null<Ui::RpWidget*> button,
|
||||||
Fn<PeerData*()> currentPeer) {
|
Fn<PeerData*()> currentPeer) {
|
||||||
|
const auto text = tr::lng_context_mark_read_reactions_all(tr::now);
|
||||||
|
const auto sendRequest = [=](not_null<PeerData*> peer, Fn<void()> 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
|
} // namespace SendMenu
|
||||||
|
|
|
@ -16,6 +16,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
|
||||||
namespace HistoryUnreadThings {
|
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) {
|
void Proxy::setCount(int count) {
|
||||||
if (!_known) {
|
if (!_known) {
|
||||||
|
@ -34,21 +46,20 @@ void Proxy::setCount(int count) {
|
||||||
"real count is greater than received unread count"));
|
"real count is greater than received unread count"));
|
||||||
count = loaded;
|
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);
|
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);
|
const auto has = (count > 0);
|
||||||
if (has != had) {
|
if (has != had) {
|
||||||
_history->owner().chatsFilters().refreshHistory(_history);
|
if (_type == Type::Mentions) {
|
||||||
|
_history->owner().chatsFilters().refreshHistory(_history);
|
||||||
|
}
|
||||||
_history->updateChatListEntry();
|
_history->updateChatListEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +102,19 @@ void Proxy::erase(MsgId msgId) {
|
||||||
}
|
}
|
||||||
_history->session().changes().historyUpdated(
|
_history->session().changes().historyUpdated(
|
||||||
_history,
|
_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) {
|
void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
||||||
|
@ -158,15 +181,9 @@ void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
||||||
fullCount = list.loadedCount();
|
fullCount = list.loadedCount();
|
||||||
}
|
}
|
||||||
setCount(fullCount);
|
setCount(fullCount);
|
||||||
const auto flag = [&] {
|
_history->session().changes().historyUpdated(
|
||||||
using Flag = Data::HistoryUpdate::Flag;
|
_history,
|
||||||
switch (_type) {
|
UpdateFlag(_type));
|
||||||
case Type::Mentions: return Flag::UnreadMentions;
|
|
||||||
case Type::Reactions: return Flag::UnreadReactions;
|
|
||||||
}
|
|
||||||
Unexpected("Type in Proxy::addSlice.");
|
|
||||||
}();
|
|
||||||
_history->session().changes().historyUpdated(_history, flag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Proxy::createData() {
|
void Proxy::createData() {
|
||||||
|
|
|
@ -47,6 +47,9 @@ public:
|
||||||
void erase(MsgId msgId) {
|
void erase(MsgId msgId) {
|
||||||
_messages.remove(msgId);
|
_messages.remove(msgId);
|
||||||
}
|
}
|
||||||
|
void clear() {
|
||||||
|
_messages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<int> _count;
|
std::optional<int> _count;
|
||||||
|
@ -115,6 +118,7 @@ public:
|
||||||
void setCount(int count);
|
void setCount(int count);
|
||||||
bool add(MsgId msgId, AddType type);
|
bool add(MsgId msgId, AddType type);
|
||||||
void erase(MsgId msgId);
|
void erase(MsgId msgId);
|
||||||
|
void clear();
|
||||||
|
|
||||||
void addSlice(const MTPmessages_Messages &slice);
|
void addSlice(const MTPmessages_Messages &slice);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue