From 2c7089d47f1b5c557b6406586214f039c2856d65 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 23 Nov 2024 10:47:36 +0400 Subject: [PATCH] Ctrl+Reply+Click replies in another chat. --- Telegram/Resources/langs/lang.strings | 1 + .../history/history_inner_widget.cpp | 67 +++++++------------ .../history/history_inner_widget.h | 2 + .../SourceFiles/history/history_widget.cpp | 10 ++- .../history/view/history_view_list_widget.cpp | 2 +- 5 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 43fa84602..b9c61205a 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -290,6 +290,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_error_cant_add_admin_invite" = "You can't add this user as an admin because they are not a member of this group and you are not allowed to add them."; "lng_error_cant_add_admin_unban" = "Sorry, you can't add this user as an admin because they are in the Removed Users list and you can't unban them."; "lng_error_cant_ban_admin" = "You can't ban this user because they are an admin in this group and you are not allowed to demote them."; +"lng_error_cant_reply_other" = "This message can't be replied in another chat."; "lng_error_admin_limit" = "Sorry, you've reached the maximum number of admins for this group."; "lng_error_admin_limit_channel" = "Sorry, you've reached the maximum number of admins for this channel."; "lng_error_post_link_invalid" = "Unfortunately, you can't access this message. You aren't a member of the chat where it was posted."; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 2753b0dc0..a6b9f2669 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -124,15 +124,6 @@ int BinarySearchBlocksOrItems(const T &list, int edge) { return start; } -[[nodiscard]] bool CanSendReply(not_null item) { - const auto peer = item->history()->peer; - const auto topic = item->topic(); - return topic - ? Data::CanSendAnything(topic) - : (Data::CanSendAnything(peer) - && (!peer->isChannel() || peer->asChannel()->amIn())); -} - } // namespace // flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html @@ -576,21 +567,13 @@ void HistoryInner::setupSwipeReply() { const auto replyToItemId = (selected.item ? selected.item : still)->fullId(); - if (canSendReply) { - _widget->replyToMessage({ - .messageId = replyToItemId, - .quote = selected.text, - .quoteOffset = selected.offset, - }); - if (!selected.text.empty()) { - _widget->clearSelected(); - } - } else { - HistoryView::Controls::ShowReplyToChatBox(show, { - .messageId = replyToItemId, - .quote = selected.text, - .quoteOffset = selected.offset, - }); + _widget->replyToMessage({ + .messageId = replyToItemId, + .quote = selected.text, + .quoteOffset = selected.offset, + }); + if (!selected.text.empty()) { + _widget->clearSelected(); } }; return false; @@ -2575,26 +2558,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { const auto quoteOffset = selected.offset; text.replace('&', u"&&"_q); _menu->addAction(text, [=] { - const auto still = session->data().message(itemId); - const auto forceAnotherChat = base::IsCtrlPressed() - && still - && still->allowsForward(); - if (canSendReply && !forceAnotherChat) { - _widget->replyToMessage({ - .messageId = itemId, - .quote = quote, - .quoteOffset = quoteOffset, - }); - if (!quote.empty()) { - _widget->clearSelected(); - } - } else { - const auto show = controller->uiShow(); - HistoryView::Controls::ShowReplyToChatBox(show, { - .messageId = itemId, - .quote = quote, - .quoteOffset = quoteOffset, - }); + _widget->replyToMessage({ + .messageId = itemId, + .quote = quote, + .quoteOffset = quoteOffset, + }); + if (!quote.empty()) { + _widget->clearSelected(); } }, &st::menuIconReply); } @@ -4774,3 +4744,12 @@ auto HistoryInner::DelegateMixin() -> std::unique_ptr { return std::make_unique(); } + +bool CanSendReply(not_null item) { + const auto peer = item->history()->peer; + const auto topic = item->topic(); + return topic + ? Data::CanSendAnything(topic) + : (Data::CanSendAnything(peer) + && (!peer->isChannel() || peer->asChannel()->amIn())); +} diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index e3d671a97..356609a26 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -553,3 +553,5 @@ private: ClickHandlerPtr _scrollDateLink; }; + +[[nodiscard]] bool CanSendReply(not_null item); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e9d097a27..f9f3445de 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -7884,7 +7884,15 @@ void HistoryWidget::clearFieldText( void HistoryWidget::replyToMessage(FullReplyTo id) { if (const auto item = session().data().message(id.messageId)) { - replyToMessage(item, id.quote, id.quoteOffset); + if (CanSendReply(item) && !base::IsCtrlPressed()) { + replyToMessage(item, id.quote, id.quoteOffset); + } else if (item->allowsForward()) { + const auto show = controller()->uiShow(); + HistoryView::Controls::ShowReplyToChatBox(show, id); + } else { + controller()->showToast( + tr::lng_error_cant_reply_other(tr::now)); + } } } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 1a67af4ec..35d0d8073 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1879,7 +1879,7 @@ not_null ListWidget::elementPathShiftGradient() { } void ListWidget::elementReplyTo(const FullReplyTo &to) { - replyToMessageRequestNotify(to); + replyToMessageRequestNotify(to, base::IsCtrlPressed()); } void ListWidget::elementStartInteraction(not_null view) {