From 24b3b2a6586c1fe217882b86ea21eaa9ef6872e4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 Jul 2017 09:05:06 +0300 Subject: [PATCH] Fix forwarded from for single message forward. Closes #3699, closes #3701, closes #3700. --- Telegram/SourceFiles/history/history_item.h | 11 ++++---- .../SourceFiles/history/history_message.cpp | 25 ++++++++++--------- .../SourceFiles/history/history_message.h | 2 +- .../SourceFiles/history/history_widget.cpp | 4 +-- Telegram/SourceFiles/mediaview.cpp | 4 +-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 67447c3a1..d660d21c1 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -138,7 +138,7 @@ struct HistoryMessageForwarded : public RuntimeComponent()) { - return forwarded->_originalPeer; + return forwarded->_originalSender; } - return history()->peer; + auto peer = history()->peer; + return (peer->isChannel() && !peer->isMegagroup()) ? peer : from(); } PeerData *fromOriginal() const { if (auto forwarded = Get()) { - if (auto user = forwarded->_originalPeer->asUser()) { + if (auto user = forwarded->_originalSender->asUser()) { return user; } } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 8bab8ab71..16ebb3672 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -372,19 +372,20 @@ int HistoryMessageEdited::maxWidth() const { void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { QString text; + auto fromChannel = (_originalSender->isChannel() && !_originalSender->isMegagroup()); if (!_originalAuthor.isEmpty()) { - text = lng_forwarded_signed(lt_channel, App::peerName(_originalPeer), lt_user, _originalAuthor); + text = lng_forwarded_signed(lt_channel, App::peerName(_originalSender), lt_user, _originalAuthor); } else { - text = App::peerName(_originalPeer); + text = App::peerName(_originalSender); } if (via) { - if (_originalPeer->isChannel()) { + if (fromChannel) { text = lng_forwarded_channel_via(lt_channel, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username)); } else { text = lng_forwarded_via(lt_user, textcmdLink(1, text), lt_inline_bot, textcmdLink(2, '@' + via->_bot->username)); } } else { - if (_originalPeer->isChannel()) { + if (fromChannel) { text = lng_forwarded_channel(lt_channel, textcmdLink(1, text)); } else { text = lng_forwarded(lt_user, textcmdLink(1, text)); @@ -392,7 +393,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { } TextParseOptions opts = { TextParseRichText, 0, 0, Qt::LayoutDirectionAuto }; _text.setText(st::fwdTextStyle, text, opts); - _text.setLink(1, (_originalId && _originalPeer->isChannel()) ? goToMessageClickHandler(_originalPeer, _originalId) : _originalPeer->openLink()); + _text.setLink(1, fromChannel ? goToMessageClickHandler(_originalSender, _originalId) : _originalSender->openLink()); if (via) { _text.setLink(2, via->_lnk); } @@ -611,7 +612,7 @@ HistoryMessage::HistoryMessage(gsl::not_null history, const MTPDmessag auto &f = msg.vfwd_from.c_messageFwdHeader(); config.originalDate = ::date(f.vdate); if (f.has_from_id() || f.has_channel_id()) { - config.peerIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); + config.senderOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); if (f.has_channel_post()) config.originalId = f.vchannel_post.v; if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author); } @@ -658,10 +659,10 @@ HistoryMessage::HistoryMessage(gsl::not_null history, MsgId id, MTPDme if (fwd->Has() || !fwd->history()->peer->isSelf()) { // Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself. config.originalDate = fwd->dateOriginal(); - auto peerOriginal = fwd->peerOriginal(); - config.peerIdOriginal = peerOriginal->id; + auto senderOriginal = fwd->senderOriginal(); + config.senderOriginal = senderOriginal->id; config.authorOriginal = fwd->authorOriginal(); - if (peerOriginal->isChannel()) { + if (senderOriginal->isChannel()) { config.originalId = fwd->idOriginal(); } } @@ -844,7 +845,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (displayEditedBadge(hasViaBot || hasInlineMarkup())) { mask |= HistoryMessageEdited::Bit(); } - if (config.peerIdOriginal) { + if (config.senderOriginal) { mask |= HistoryMessageForwarded::Bit(); } if (config.mtpMarkup) { @@ -881,7 +882,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { } if (auto forwarded = Get()) { forwarded->_originalDate = config.originalDate; - forwarded->_originalPeer = App::peer(config.peerIdOriginal); + forwarded->_originalSender = App::peer(config.senderOriginal); forwarded->_originalId = config.originalId; forwarded->_originalAuthor = config.authorOriginal; } @@ -1237,7 +1238,7 @@ bool HistoryMessage::displayForwardedFrom() const { || !_media || !_media->isDisplayed() || !_media->hideForwardedFrom() - || forwarded->_originalPeer->isChannel(); + || forwarded->_originalSender->isChannel(); } return false; } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index ea9f6280a..c4c1c9128 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -193,7 +193,7 @@ private: UserId viaBotId = 0; int viewsCount = -1; QString author; - PeerId peerIdOriginal = 0; + PeerId senderOriginal = 0; MsgId originalId = 0; QString authorOriginal; QDateTime originalDate; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 7e896e936..1fd18ede6 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6414,7 +6414,7 @@ void HistoryWidget::updateForwardingTexts() { QVector fromUsers; fromUsers.reserve(_toForward.size()); for (auto i = _toForward.cbegin(), e = _toForward.cend(); i != e; ++i) { - auto from = i.value()->peerOriginal(); + auto from = i.value()->senderOriginal(); if (!fromUsersMap.contains(from)) { fromUsersMap.insert(from, true); fromUsers.push_back(from); @@ -6444,7 +6444,7 @@ void HistoryWidget::checkForwardingInfo() { if (!_toForward.isEmpty()) { auto version = 0; for_const (auto item, _toForward) { - version += item->peerOriginal()->nameVersion; + version += item->senderOriginal()->nameVersion; } if (version != _toForwardNameVersion) { updateForwardingTexts(); diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 81444ffde..6469f0013 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1212,7 +1212,7 @@ void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) { _y = (height() - _h) / 2; _width = _w; if (_msgid && item) { - _from = item->peerOriginal(); + _from = item->senderOriginal(); } else { _from = _user; } @@ -1366,7 +1366,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty _x = (width() - _w) / 2; _y = (height() - _h) / 2; if (_msgid && item) { - _from = item->peerOriginal(); + _from = item->senderOriginal(); } else { _from = _user; }