From f189ffc6ac9947758b759d5b7e2ad6562b338e5d Mon Sep 17 00:00:00 2001 From: test Date: Tue, 20 Jul 2021 22:10:04 +0300 Subject: [PATCH] Summary --- Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/history/history_widget.cpp | 25 +++++++++++++++++++ Telegram/SourceFiles/history/history_widget.h | 2 ++ 3 files changed, 28 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7a78cd6b4..25d3e5559 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1641,6 +1641,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_mark_read_sure" = "Are you sure you want to mark all chats from this folder 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_mentions_all" = "Mark all mentions as read" "lng_context_archive_expand" = "Expand"; "lng_context_archive_collapse" = "Collapse"; "lng_context_archive_to_menu" = "Move to main menu"; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 07ea802ba..8e08e78cf 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6964,6 +6964,31 @@ void HistoryWidget::synteticScrollToY(int y) { _synteticScrollEvent = false; } +void HistoryWidget::setupUnreadMentionsButtonContextMenu(not_null button) { + const auto menu = std::make_shared>(); + const auto showMenu = [=] { + *menu = base::make_unique_q(button); + (*menu)->addAction(tr::lng_context_mark_read_mentions_all(tr::now), [=] { + if (_history) { + // You must add checks for peer and peer->input validity here and everywhere else in code as well + // Store it somewhere in vector for each chat, if we don't have internet connection check if request already exists in vector, + // you can either drop and replace or simply put it inside if + // Delete this comments when you end + _history->session().api().request(MTPmessages_ReadMentions(_history->peer->input)).send(); + } + }); + (*menu)->popup(QCursor::pos()); + return true; + }; + + base::install_event_filter(button, [=](not_null e) { + if (e->type() == QEvent::ContextMenu && showMenu()) { + return base::EventFilterResult::Cancel; + } + return base::EventFilterResult::Continue; + }); +} + HistoryWidget::~HistoryWidget() { if (_history) { // Saving a draft on account switching. diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index ca7847214..cdf882b2e 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -597,6 +597,8 @@ private: bool kbWasHidden() const; + void setupUnreadMentionsButtonContextMenu(not_null button); + MTP::Sender _api; MsgId _replyToId = 0; Ui::Text::String _replyToName;