From 9c1ce702bb2ea50d7055028ffb30d3995220e8e6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 May 2019 09:55:16 +0200 Subject: [PATCH] Display channel posts in discussion groups. --- .../history/history_item_components.cpp | 17 ++++++++++++++--- .../SourceFiles/history/history_message.cpp | 10 +++++++++- Telegram/SourceFiles/history/history_message.h | 2 +- .../history/view/history_view_element.cpp | 15 ++++++++++----- .../history/view/history_view_message.cpp | 14 +++++--------- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 902a52e7a..01fc882ad 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -233,9 +233,20 @@ bool HistoryMessageReply::isNameUpdated() const { void HistoryMessageReply::updateName() const { if (replyToMsg) { - QString name = (replyToVia && replyToMsg->author()->isUser()) - ? replyToMsg->author()->asUser()->firstName - : App::peerName(replyToMsg->author()); + const auto from = [&] { + if (const auto message = replyToMsg->toHistoryMessage()) { + if (const auto from = message->displayFrom()) { + return from; + } + } + return replyToMsg->author().get(); + }(); + const auto name = [&] { + if (replyToVia && from->isUser()) { + return from->asUser()->firstName; + } + return App::peerName(from); + }(); replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions()); replyToVersion = replyToMsg->author()->nameVersion; bool hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 35ee9620b..937be612d 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -553,8 +553,16 @@ int HistoryMessage::viewsCount() const { return HistoryItem::viewsCount(); } +bool HistoryMessage::displayForwardedAsOriginal() const { + if (const auto forwarded = Get()) { + const auto peer = history()->peer; + return peer->isSelf() || (peer->isMegagroup() && (peer == from())); + } + return false; +} + PeerData *HistoryMessage::displayFrom() const { - return history()->peer->isSelf() + return displayForwardedAsOriginal() ? senderOriginal() : author().get(); } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 80c34e68e..cf0703015 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -131,6 +131,7 @@ public: MsgId dependencyMsgId() const override { return replyToId(); } + bool displayForwardedAsOriginal() const; HistoryMessage *toHistoryMessage() override { // dynamic_cast optimize return this; @@ -170,7 +171,6 @@ private: const MTPDmessageFwdHeader &data); void updateAdminBadgeState(); - ClickHandlerPtr fastReplyLink() const; QString _timeText; int _timeWidth = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index df7fcc47a..5193a590c 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -358,15 +358,20 @@ void Element::refreshDataId() { } bool Element::computeIsAttachToPrevious(not_null previous) { + const auto mayBeAttached = [](not_null item) { + return !item->serviceMsg() + && !item->isEmpty() + && !item->isPost() + && (item->from() != item->history()->peer + || !item->from()->isChannel()); + }; const auto item = data(); if (!Has() && !Has()) { const auto prev = previous->data(); - const auto possible = !item->serviceMsg() && !prev->serviceMsg() - && !item->isEmpty() && !prev->isEmpty() - && (std::abs(prev->date() - item->date()) + const auto possible = (std::abs(prev->date() - item->date()) < kAttachMessageToPreviousSecondsDelta) - && (/*_context == Context::Feed // #feed - || */(!item->isPost() && !prev->isPost())); + && mayBeAttached(item) + && mayBeAttached(prev); if (possible) { if (item->history()->peer->isSelf()) { return IsAttachedToPreviousInSavedMessages(prev, item); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index ac2e15177..91f53881c 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1335,10 +1335,9 @@ bool Message::displayFromName() const { bool Message::displayForwardedFrom() const { const auto item = message(); - if (const auto forwarded = item->Get()) { - if (item->history()->peer->isSelf()) { - return false; - } + if (item->displayForwardedAsOriginal()) { + return false; + } else if (const auto forwarded = item->Get()) { const auto media = this->media(); return item->Has() || !media @@ -1419,11 +1418,8 @@ bool Message::displayFastShare() const { bool Message::displayGoToOriginal() const { const auto item = message(); - const auto peer = item->history()->peer; - if (peer->isSelf()) { - if (const auto forwarded = item->Get()) { - return forwarded->savedFromPeer && forwarded->savedFromMsgId; - } + if (const auto forwarded = item->Get()) { + return forwarded->savedFromPeer && forwarded->savedFromMsgId; } return false; }