From b4c72723510f8769c9f926873203729b85113db1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 31 Oct 2023 12:21:07 +0400 Subject: [PATCH] Keep external replies in forwards. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/history/history_item.cpp | 8 ++++++++ .../history/history_item_components.cpp | 15 ++++++++------- .../SourceFiles/history/history_item_components.h | 4 ++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ddfdafbde..183b86acd 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2685,6 +2685,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_reply_options_quote" = "Update Quote"; "lng_reply_header_short" = "Reply"; "lng_reply_quote_selected" = "Quote Selected"; +"lng_reply_from_private_chat" = "This reply is from a private chat."; "lng_link_options_header" = "Link Preview Settings"; "lng_link_header_short" = "Link"; "lng_link_move_up" = "Move Up"; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 7fd3fe5df..b4949c93f 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -449,6 +449,14 @@ HistoryItem::HistoryItem( const auto dropForwardInfo = original->computeDropForwardedInfo(); config.reply.messageId = config.reply.topMessageId = topicRootId; config.reply.topicPost = (topicRootId != 0); + if (const auto originalReply = original->Get()) { + if (originalReply->external()) { + config.reply = originalReply->fields(); + if (!config.reply.externalPeerId) { + config.reply.messageId = 0; + } + } + } if (!dropForwardInfo) { config.originalDate = original->originalDate(); if (const auto info = original->hiddenSenderInfo()) { diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 9ee8f0944..5dfadd9f6 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -397,9 +397,6 @@ ReplyFields ReplyFieldsFromMTP( auto result = ReplyFields(); if (const auto peer = data.vreply_to_peer_id()) { result.externalPeerId = peerFromMTP(*peer); - if (result.externalPeerId == history->peer->id) { - result.externalPeerId = 0; - } } const auto owner = &history->owner(); if (const auto id = data.vreply_to_msg_id().value_or_empty()) { @@ -526,8 +523,7 @@ bool HistoryMessageReply::updateData( } } - const auto external = _fields.externalSenderId - || !_fields.externalSenderName.isEmpty(); + const auto external = this->external(); if (resolvedMessage || resolvedStory || (external && (!_fields.messageId || force))) { @@ -625,9 +621,8 @@ void HistoryMessageReply::setLinkFrom( if (externalPeerId) { controller->showPeerInfo( controller->session().data().peer(externalPeerId)); - } else { - controller->showToast(u"External reply"_q); } + controller->showToast(tr::lng_reply_from_private_chat(tr::now)); } }; _link = resolvedMessage @@ -666,6 +661,12 @@ void HistoryMessageReply::clearData(not_null holder) { refreshReplyToMedia(); } +bool HistoryMessageReply::external() const { + return _fields.externalPeerId + || _fields.externalSenderId + || !_fields.externalSenderName.isEmpty(); +} + PeerData *HistoryMessageReply::sender(not_null holder) const { if (resolvedStory) { return resolvedStory->peer(); diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 2b5a90c57..c250e91fb 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -274,6 +274,7 @@ struct HistoryMessageReply // Must be called before destructor. void clearData(not_null holder); + [[nodiscard]] bool external() const; [[nodiscard]] PeerData *sender(not_null holder) const; [[nodiscard]] QString senderName(not_null holder) const; [[nodiscard]] QString senderName(not_null peer) const; @@ -301,6 +302,9 @@ struct HistoryMessageReply bool inBubble) const; void unloadPersistentAnimation(); + [[nodiscard]] ReplyFields fields() const { + return _fields; + } [[nodiscard]] PeerId externalPeerId() const { return _fields.externalPeerId; }