Fix forwarded from for single message forward.

Closes #3699, closes #3701, closes #3700.
This commit is contained in:
John Preston 2017-07-26 09:05:06 +03:00
parent e1e286aa13
commit 24b3b2a658
5 changed files with 24 additions and 22 deletions

View File

@ -138,7 +138,7 @@ struct HistoryMessageForwarded : public RuntimeComponent<HistoryMessageForwarded
void create(const HistoryMessageVia *via) const;
QDateTime _originalDate;
PeerData *_originalPeer = nullptr;
PeerData *_originalSender = nullptr;
QString _originalAuthor;
MsgId _originalId = 0;
mutable Text _text = { 1 };
@ -802,15 +802,16 @@ public:
}
return date;
}
PeerData *peerOriginal() const {
PeerData *senderOriginal() const {
if (auto forwarded = Get<HistoryMessageForwarded>()) {
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<HistoryMessageForwarded>()) {
if (auto user = forwarded->_originalPeer->asUser()) {
if (auto user = forwarded->_originalSender->asUser()) {
return user;
}
}

View File

@ -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*> 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*> history, MsgId id, MTPDme
if (fwd->Has<HistoryMessageForwarded>() || !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<HistoryMessageForwarded>()) {
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;
}

View File

@ -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;

View File

@ -6414,7 +6414,7 @@ void HistoryWidget::updateForwardingTexts() {
QVector<PeerData*> 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();

View File

@ -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;
}