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_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";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Ui::RpWidget*> button,
 | 
			
		||||
		Fn<PeerData*()> currentPeer) {
 | 
			
		||||
		Fn<PeerData*()> currentPeer,
 | 
			
		||||
		const QString &text,
 | 
			
		||||
		Fn<void(not_null<PeerData*>, Fn<void()>)> sendReadRequest) {
 | 
			
		||||
	struct State {
 | 
			
		||||
		base::unique_qptr<Ui::PopupMenu> menu;
 | 
			
		||||
		base::flat_set<not_null<PeerData*>> sentForPeers;
 | 
			
		||||
| 
						 | 
				
			
			@ -159,19 +164,11 @@ void SetupUnreadMentionsMenu(
 | 
			
		|||
		state->menu = base::make_unique_q<Ui::PopupMenu>(
 | 
			
		||||
			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<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(
 | 
			
		||||
		not_null<Ui::RpWidget*> button,
 | 
			
		||||
		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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 had = (list.count() > 0);
 | 
			
		||||
	const auto &other = (_type == Type::Mentions)
 | 
			
		||||
		? _data->reactions
 | 
			
		||||
		: _data->mentions;
 | 
			
		||||
		if (other.count(-1) == 0) {
 | 
			
		||||
	if (!count && other.count(-1) == 0) {
 | 
			
		||||
		_data = nullptr;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const auto had = (list.count() > 0);
 | 
			
		||||
	} else {
 | 
			
		||||
		list.setCount(count);
 | 
			
		||||
	}
 | 
			
		||||
	const auto has = (count > 0);
 | 
			
		||||
	if (has != had) {
 | 
			
		||||
		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() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,9 @@ public:
 | 
			
		|||
	void erase(MsgId msgId) {
 | 
			
		||||
		_messages.remove(msgId);
 | 
			
		||||
	}
 | 
			
		||||
	void clear() {
 | 
			
		||||
		_messages.clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	std::optional<int> _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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue