From c0a0ad4ec5eaca07c47e2febe2fec4c724fa16cd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 15 Oct 2024 01:10:55 +0300 Subject: [PATCH] Added info to context menu for non-forwardable history. --- Telegram/Resources/langs/lang.strings | 4 ++ .../history/history_inner_widget.cpp | 9 +++++ .../view/history_view_context_menu.cpp | 39 +++++++++++++++++++ .../history/view/history_view_context_menu.h | 4 ++ Telegram/lib_ui | 2 +- 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b69b92614..60c7a6413 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3576,6 +3576,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_animated_reactions_many#one" = "Reactions contain emoji from **{count} pack**."; "lng_context_animated_reactions_many#other" = "Reactions contain emoji from **{count} packs**."; +"lng_context_noforwards_info_channel" = "Copying and forwarding is not allowed in this channel."; +"lng_context_noforwards_info_group" = "Copying and forwarding is not allowed in this group."; +"lng_context_noforwards_info_bot" = "Copying and forwarding is not allowed from this bot."; + "lng_context_spoiler_effect" = "Hide with Spoiler"; "lng_context_disable_spoiler" = "Remove Spoiler"; "lng_context_make_paid" = "Make This Content Paid"; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index cae2d2698..b7044f9b0 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2935,11 +2935,20 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (_dragStateItem) { const auto view = viewByItem(_dragStateItem); const auto textItem = view ? view->textItem() : _dragStateItem; + const auto wasAmount = _menu->actions().size(); HistoryView::AddEmojiPacksAction( _menu, textItem ? textItem : _dragStateItem, HistoryView::EmojiPacksSource::Message, _controller); + const auto added = (_menu->actions().size() > wasAmount); + if (!added) { + _menu->addSeparator(); + } + HistoryView::AddSelectRestrictionAction( + _menu, + textItem ? textItem : _dragStateItem, + !added); } if (hasWhoReactedItem) { HistoryView::AddWhoReactedAction( diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index b19ec27ff..a19991507 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -68,6 +68,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_file_click_handler.h" #include "data/data_file_origin.h" #include "data/data_message_reactions.h" +#include "data/data_user.h" #include "data/stickers/data_custom_emoji.h" #include "chat_helpers/message_field.h" // FactcheckFieldIniter. #include "core/file_utilities.h" @@ -1270,6 +1271,7 @@ base::unique_qptr FillContextMenu( } AddMessageActions(result, request, list); + const auto wasAmount = result->actions().size(); if (const auto textItem = view ? view->textItem() : item) { AddEmojiPacksAction( result, @@ -1277,6 +1279,13 @@ base::unique_qptr FillContextMenu( HistoryView::EmojiPacksSource::Message, list->controller()); } + { + const auto added = (result->actions().size() > wasAmount); + if (!added) { + result->addSeparator(); + } + AddSelectRestrictionAction(result, item, !added); + } if (hasWhoReactedItem) { AddWhoReactedAction(result, list, item, list->controller()); } @@ -1841,6 +1850,36 @@ void AddEmojiPacksAction( controller); } +void AddSelectRestrictionAction( + not_null menu, + not_null item, + bool addIcon) { + const auto peer = item->history()->peer; + if ((peer->allowsForwarding() && !item->forbidsForward()) + || item->isSponsored()) { + return; + } + auto button = base::make_unique_q( + menu->menu(), + menu->st().menu, + st::historyHasCustomEmoji, + addIcon + ? st::historySponsoredAboutMenuLabelPosition + : st::historyHasCustomEmojiPosition, + (peer->isMegagroup() + ? tr::lng_context_noforwards_info_group + : (peer->isChannel()) + ? tr::lng_context_noforwards_info_channel + : (peer->isUser() && peer->asUser()->isBot()) + ? tr::lng_context_noforwards_info_channel + : tr::lng_context_noforwards_info_bot)( + tr::now, + Ui::Text::RichLangValue), + addIcon ? &st::menuIconCopyright : nullptr); + button->setAttribute(Qt::WA_TransparentForMouseEvents); + menu->addAction(std::move(button)); +} + TextWithEntities TransribedText(not_null item) { const auto media = item->media(); const auto document = media ? media->document() : nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index efb2a5fdd..1b14804aa 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -122,6 +122,10 @@ void AddEmojiPacksAction( not_null item, EmojiPacksSource source, not_null controller); +void AddSelectRestrictionAction( + not_null menu, + not_null item, + bool addIcon); [[nodiscard]] TextWithEntities TransribedText(not_null item); diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 21b55b21c..f44ab56dd 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 21b55b21cc5fcc243ec01a9c3201e24b24dfd458 +Subproject commit f44ab56dddd431fabbb5f099006e2c92558d47f5