From eb240defa34580926f32e37cae5bcb3ddf9ec374 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sun, 30 Apr 2017 15:44:17 +0300
Subject: [PATCH] Display forwarded info in video messages.

---
 .../history/history_inner_widget.cpp          |   4 +-
 Telegram/SourceFiles/history/history_item.h   |  12 +--
 .../history/history_media_types.cpp           | 100 +++++++++++++-----
 .../SourceFiles/history/history_media_types.h |   4 +-
 .../SourceFiles/history/history_message.cpp   |  62 +++++------
 .../SourceFiles/history/history_message.h     |   8 +-
 .../SourceFiles/overview/overview_layout.cpp  |   4 +-
 .../window/notifications_manager.cpp          |  22 ++--
 8 files changed, 136 insertions(+), 80 deletions(-)

diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 1ffd6b747..6f9d2a17f 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -2445,8 +2445,8 @@ QString HistoryInner::tooltipText() const {
 		}
 	} else if (_dragCursorState == HistoryInForwardedCursorState && _dragAction == NoDrag) {
 		if (App::hoveredItem()) {
-			if (HistoryMessageForwarded *fwd = App::hoveredItem()->Get<HistoryMessageForwarded>()) {
-				return fwd->_text.originalText(AllTextSelection, ExpandLinksNone);
+			if (auto forwarded = App::hoveredItem()->Get<HistoryMessageForwarded>()) {
+				return forwarded->_text.originalText(AllTextSelection, ExpandLinksNone);
 			}
 		}
 	} else if (ClickHandlerPtr lnk = ClickHandler::getActive()) {
diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h
index fde9d6564..5b9f129f8 100644
--- a/Telegram/SourceFiles/history/history_item.h
+++ b/Telegram/SourceFiles/history/history_item.h
@@ -779,20 +779,20 @@ public:
 	}
 
 	PeerData *fromOriginal() const {
-		if (auto fwd = Get<HistoryMessageForwarded>()) {
-			return fwd->_fromOriginal;
+		if (auto forwarded = Get<HistoryMessageForwarded>()) {
+			return forwarded->_fromOriginal;
 		}
 		return from();
 	}
 	PeerData *authorOriginal() const {
-		if (auto fwd = Get<HistoryMessageForwarded>()) {
-			return fwd->_authorOriginal;
+		if (auto forwarded = Get<HistoryMessageForwarded>()) {
+			return forwarded->_authorOriginal;
 		}
 		return author();
 	}
 	MsgId idOriginal() const {
-		if (auto fwd = Get<HistoryMessageForwarded>()) {
-			return fwd->_originalId;
+		if (auto forwarded = Get<HistoryMessageForwarded>()) {
+			return forwarded->_originalId;
 		}
 		return id;
 	}
diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp
index c290e5f9a..23287334a 100644
--- a/Telegram/SourceFiles/history/history_media_types.cpp
+++ b/Telegram/SourceFiles/history/history_media_types.cpp
@@ -36,6 +36,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 
 namespace {
 
+constexpr auto kMaxGifForwardedBarLines = 4;
+
 TextParseOptions _webpageTitleOptions = {
 	TextParseMultiline | TextParseRichText, // flags
 	0, // maxw
@@ -1724,7 +1726,13 @@ void HistoryGif::initDimensions() {
 			}
 		}
 	} else if (isSeparateRoundVideo()) {
-		_maxw += additionalWidth();
+		auto via = _parent->Get<HistoryMessageVia>();
+		auto reply = _parent->Get<HistoryMessageReply>();
+		auto forwarded = _parent->Get<HistoryMessageForwarded>();
+		if (forwarded) {
+			forwarded->create(via);
+		}
+		_maxw += additionalWidth(via, reply, forwarded);
 	}
 }
 
@@ -1795,12 +1803,14 @@ int HistoryGif::resizeGetHeight(int width) {
 	} else if (isSeparateRoundVideo()) {
 		auto via = _parent->Get<HistoryMessageVia>();
 		auto reply = _parent->Get<HistoryMessageReply>();
-		if (via || reply) {
-			_width += additionalWidth(via, reply);
+		auto forwarded = _parent->Get<HistoryMessageForwarded>();
+		if (via || reply || forwarded) {
+			auto additional = additionalWidth(via, reply, forwarded);
+			_width += additional;
 			accumulate_min(_width, width);
-			auto usew = _maxw - additionalWidth(via, reply);
+			auto usew = _maxw - additional;
 			auto availw = _width - usew - st::msgReplyPadding.left() - st::msgReplyPadding.left() - st::msgReplyPadding.left();
-			if (via) {
+			if (!forwarded && via) {
 				via->resize(availw);
 			}
 			if (reply) {
@@ -1868,8 +1878,9 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
 	auto usex = 0, usew = width;
 	auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>();
 	auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>();
-	if (via || reply) {
-		usew = _maxw - additionalWidth(via, reply);
+	auto forwarded = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageForwarded>();
+	if (via || reply || forwarded) {
+		usew = _maxw - additionalWidth(via, reply, forwarded);
 		if (isPost) {
 		} else if (out) {
 			usex = _width - usew;
@@ -1982,10 +1993,15 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
 				p.drawEllipse(rtlrect(statusX - st::msgDateImgPadding.x() + statusW - st::msgDateImgPadding.x() - st::mediaUnreadSize, statusY + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, _width));
 			}
 		}
-		if (!isChildMedia && (via || reply)) {
-			int rectw = _width - usew - st::msgReplyPadding.left();
-			int recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom();
-			if (via) {
+		if (!isChildMedia && (via || reply || forwarded)) {
+			auto rectw = _width - usew - st::msgReplyPadding.left();
+			auto innerw = rectw - (st::msgReplyPadding.left() + st::msgReplyPadding.right());
+			auto recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom();
+			auto forwardedHeightReal = forwarded ? forwarded->_text.countHeight(innerw) : 0;
+			auto forwardedHeight = qMin(forwardedHeightReal, kMaxGifForwardedBarLines * st::msgServiceNameFont->height);
+			if (forwarded) {
+				recth += forwardedHeight;
+			} else if (via) {
 				recth += st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
 			}
 			if (reply) {
@@ -1996,9 +2012,16 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
 			if (rtl()) rectx = _width - rectx - rectw;
 
 			App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
+			p.setPen(st::msgServiceFg);
 			rectx += st::msgReplyPadding.left();
-			rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right();
-			if (via) {
+			rectw = innerw;
+			if (forwarded) {
+				p.setTextPalette(st::serviceTextPalette);
+				auto breakEverywhere = (forwardedHeightReal > forwardedHeight);
+				forwarded->_text.drawElided(p, rectx, recty + st::msgReplyPadding.top(), rectw, kMaxGifForwardedBarLines, style::al_left, 0, -1, 0, breakEverywhere);
+				p.restoreTextPalette();
+			} else if (via) {
+				p.setFont(st::msgDateFont);
 				p.drawTextLeft(rectx, recty + st::msgReplyPadding.top(), 2 * rectx + rectw, via->_text);
 				int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
 				recty += skip;
@@ -2070,8 +2093,9 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request)
 	auto usew = width, usex = 0;
 	auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>();
 	auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>();
-	if (via || reply) {
-		usew = _maxw - additionalWidth(via, reply);
+	auto forwarded = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageForwarded>();
+	if (via || reply || forwarded) {
+		usew = _maxw - additionalWidth(via, reply, forwarded);
 		if (isPost) {
 		} else if (out) {
 			usex = _width - usew;
@@ -2079,20 +2103,44 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request)
 	}
 	if (rtl()) usex = _width - usex - usew;
 
-	if (via || reply) {
-		int rectw = width - usew - st::msgReplyPadding.left();
-		int recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom();
-		if (via) {
+	if (via || reply || forwarded) {
+		auto rectw = width - usew - st::msgReplyPadding.left();
+		auto innerw = rectw - (st::msgReplyPadding.left() + st::msgReplyPadding.right());
+		auto recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom();
+		auto forwardedHeightReal = forwarded ? forwarded->_text.countHeight(innerw) : 0;
+		auto forwardedHeight = qMin(forwardedHeightReal, kMaxGifForwardedBarLines * st::msgServiceNameFont->height);
+		if (forwarded) {
+			recth += forwardedHeight;
+		} else if (via) {
 			recth += st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
 		}
 		if (reply) {
 			recth += st::msgReplyBarSize.height();
 		}
-		int rectx = isPost ? (usew + st::msgReplyPadding.left()) : (out ? 0 : (usew + st::msgReplyPadding.left()));
-		int recty = skipy;
+		auto rectx = isPost ? (usew + st::msgReplyPadding.left()) : (out ? 0 : (usew + st::msgReplyPadding.left()));
+		auto recty = skipy;
 		if (rtl()) rectx = _width - rectx - rectw;
 
-		if (via) {
+		if (forwarded) {
+			if (x >= rectx && y >= recty && x < rectx + rectw && y < recty + st::msgReplyPadding.top() + forwardedHeight) {
+				auto breakEverywhere = (forwardedHeightReal > forwardedHeight);
+				auto textRequest = request.forText();
+				if (breakEverywhere) {
+					textRequest.flags |= Text::StateRequest::Flag::BreakEverywhere;
+				}
+				result = forwarded->_text.getState(x - rectx - st::msgReplyPadding.left(), y - recty - st::msgReplyPadding.top(), innerw, textRequest);
+				result.symbol = 0;
+				result.afterSymbol = false;
+				if (breakEverywhere) {
+					result.cursor = HistoryInForwardedCursorState;
+				} else {
+					result.cursor = HistoryDefaultCursorState;
+				}
+				return result;
+			}
+			recty += forwardedHeight;
+			recth -= forwardedHeight;
+		} else if (via) {
 			int viah = st::msgReplyPadding.top() + st::msgServiceNameFont->height + (reply ? 0 : st::msgReplyPadding.bottom());
 			if (x >= rectx && y >= recty && x < rectx + rectw && y < recty + viah) {
 				result.link = via->_lnk;
@@ -2201,9 +2249,11 @@ ImagePtr HistoryGif::replyPreview() {
 	return _data->makeReplyPreview();
 }
 
-int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const {
+int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const {
 	int result = 0;
-	if (via) {
+	if (forwarded) {
+		accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + forwarded->_text.maxWidth() + st::msgReplyPadding.right());
+	} else if (via) {
 		accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + via->_maxWidth + st::msgReplyPadding.left());
 	}
 	if (reply) {
@@ -2400,9 +2450,11 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, T
 			recty -= st::msgDateImgDelta;
 
 			App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
+			p.setPen(st::msgServiceFg);
 			rectx += st::msgReplyPadding.left();
 			rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right();
 			if (via) {
+				p.setFont(st::msgDateFont);
 				p.drawTextLeft(rectx, recty + st::msgReplyPadding.top(), 2 * rectx + rectw, via->_text);
 				int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
 				recty += skip;
diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h
index d2ad77d43..e80e9d431 100644
--- a/Telegram/SourceFiles/history/history_media_types.h
+++ b/Telegram/SourceFiles/history/history_media_types.h
@@ -555,9 +555,9 @@ protected:
 	}
 
 private:
-	int additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply) const;
+	int additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const;
 	int additionalWidth() const {
-		return additionalWidth(_parent->Get<HistoryMessageVia>(), _parent->Get<HistoryMessageReply>());
+		return additionalWidth(_parent->Get<HistoryMessageVia>(), _parent->Get<HistoryMessageReply>(), _parent->Get<HistoryMessageForwarded>());
 	}
 	QString mediaTypeString() const;
 	bool isSeparateRoundVideo() const {
diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp
index ae56ba7d3..f4cc4604a 100644
--- a/Telegram/SourceFiles/history/history_message.cpp
+++ b/Telegram/SourceFiles/history/history_message.cpp
@@ -631,10 +631,10 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
 	if (auto edited = Get<HistoryMessageEdited>()) {
 		edited->create(config.editDate, date);
 	}
-	if (auto fwd = Get<HistoryMessageForwarded>()) {
-		fwd->_authorOriginal = App::peer(config.authorIdOriginal);
-		fwd->_fromOriginal = App::peer(config.fromIdOriginal);
-		fwd->_originalId = config.originalId;
+	if (auto forwarded = Get<HistoryMessageForwarded>()) {
+		forwarded->_authorOriginal = App::peer(config.authorIdOriginal);
+		forwarded->_fromOriginal = App::peer(config.fromIdOriginal);
+		forwarded->_originalId = config.originalId;
 	}
 	if (auto markup = Get<HistoryMessageReplyMarkup>()) {
 		if (config.mtpMarkup) {
@@ -777,10 +777,10 @@ void HistoryMessage::initDimensions() {
 
 	updateMediaInBubbleState();
 	if (drawBubble()) {
-		auto fwd = Get<HistoryMessageForwarded>();
+		auto forwarded = Get<HistoryMessageForwarded>();
 		auto via = Get<HistoryMessageVia>();
-		if (fwd) {
-			fwd->create(via);
+		if (forwarded) {
+			forwarded->create(via);
 		}
 
 		auto mediaDisplayed = false;
@@ -816,17 +816,17 @@ void HistoryMessage::initDimensions() {
 			_minh += st::msgPadding.top() + st::msgPadding.bottom();
 			if (displayFromName()) {
 				auto namew = st::msgPadding.left() + author()->nameText.maxWidth() + st::msgPadding.right();
-				if (via && !fwd) {
+				if (via && !forwarded) {
 					namew += st::msgServiceFont->spacew + via->_maxWidth;
 				}
 				if (namew > _maxw) _maxw = namew;
-			} else if (via && !fwd) {
+			} else if (via && !forwarded) {
 				if (st::msgPadding.left() + via->_maxWidth + st::msgPadding.right() > _maxw) {
 					_maxw = st::msgPadding.left() + via->_maxWidth + st::msgPadding.right();
 				}
 			}
-			if (fwd) {
-				auto _namew = st::msgPadding.left() + fwd->_text.maxWidth() + st::msgPadding.right();
+			if (forwarded) {
+				auto _namew = st::msgPadding.left() + forwarded->_text.maxWidth() + st::msgPadding.right();
 				if (via) {
 					_namew += st::msgServiceFont->spacew + via->_maxWidth;
 				}
@@ -1015,10 +1015,10 @@ TextWithEntities HistoryMessage::selectedText(TextSelection selection) const {
 		result.entities = textResult.entities;
 		appendTextWithEntities(result, std::move(mediaResult));
 	}
-	if (auto fwd = Get<HistoryMessageForwarded>()) {
+	if (auto forwarded = Get<HistoryMessageForwarded>()) {
 		if (selection == FullSelection) {
-			auto fwdinfo = fwd->_text.originalTextWithEntities(AllTextSelection, ExpandLinksAll);
-			TextWithEntities wrapped;
+			auto fwdinfo = forwarded->_text.originalTextWithEntities(AllTextSelection, ExpandLinksAll);
+			auto wrapped = TextWithEntities();
 			wrapped.text.reserve(fwdinfo.text.size() + 4 + result.text.size());
 			wrapped.entities.reserve(fwdinfo.entities.size() + result.entities.size());
 			wrapped.text.append('[');
@@ -1414,9 +1414,9 @@ void HistoryMessage::paintFromName(Painter &p, QRect &trect, bool selected) cons
 		}
 		author()->nameText.drawElided(p, trect.left(), trect.top(), trect.width());
 
-		auto fwd = Get<HistoryMessageForwarded>();
+		auto forwarded = Get<HistoryMessageForwarded>();
 		auto via = Get<HistoryMessageVia>();
-		if (via && !fwd && trect.width() > author()->nameText.maxWidth() + st::msgServiceFont->spacew) {
+		if (via && !forwarded && trect.width() > author()->nameText.maxWidth() + st::msgServiceFont->spacew) {
 			bool outbg = out() && !isPost();
 			p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
 			p.drawText(trect.left() + author()->nameText.maxWidth() + st::msgServiceFont->spacew, trect.top() + st::msgServiceFont->ascent, via->_text);
@@ -1433,13 +1433,13 @@ void HistoryMessage::paintForwardedInfo(Painter &p, QRect &trect, bool selected)
 		p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
 		p.setFont(serviceFont);
 
-		auto fwd = Get<HistoryMessageForwarded>();
-		bool breakEverywhere = (fwd->_text.countHeight(trect.width()) > 2 * serviceFont->height);
+		auto forwarded = Get<HistoryMessageForwarded>();
+		auto breakEverywhere = (forwarded->_text.countHeight(trect.width()) > 2 * serviceFont->height);
 		p.setTextPalette(selected ? (outbg ? st::outFwdTextPaletteSelected : st::inFwdTextPaletteSelected) : (outbg ? st::outFwdTextPalette : st::inFwdTextPalette));
-		fwd->_text.drawElided(p, trect.x(), trect.y(), trect.width(), 2, style::al_left, 0, -1, 0, breakEverywhere);
+		forwarded->_text.drawElided(p, trect.x(), trect.y(), trect.width(), 2, style::al_left, 0, -1, 0, breakEverywhere);
 		p.setTextPalette(selected ? (outbg ? st::outTextPaletteSelected : st::inTextPaletteSelected) : (outbg ? st::outTextPalette : st::inTextPalette));
 
-		trect.setY(trect.y() + (((fwd->_text.maxWidth() > trect.width()) ? 2 : 1) * serviceFont->height));
+		trect.setY(trect.y() + (((forwarded->_text.maxWidth() > trect.width()) ? 2 : 1) * serviceFont->height));
 	}
 }
 
@@ -1513,7 +1513,7 @@ int HistoryMessage::performResizeGetHeight(int width) {
 		width = st::msgMaxWidth;
 	}
 	if (drawBubble()) {
-		auto fwd = Get<HistoryMessageForwarded>();
+		auto forwarded = Get<HistoryMessageForwarded>();
 		auto reply = Get<HistoryMessageReply>();
 		auto via = Get<HistoryMessageVia>();
 
@@ -1555,7 +1555,7 @@ int HistoryMessage::performResizeGetHeight(int width) {
 			countPositionAndSize(l, w);
 			fromNameUpdated(w);
 			_height += st::msgNameFont->height;
-		} else if (via && !fwd) {
+		} else if (via && !forwarded) {
 			int32 l = 0, w = 0;
 			countPositionAndSize(l, w);
 			via->resize(w - st::msgPadding.left() - st::msgPadding.right());
@@ -1565,7 +1565,7 @@ int HistoryMessage::performResizeGetHeight(int width) {
 		if (displayForwardedFrom()) {
 			int32 l = 0, w = 0;
 			countPositionAndSize(l, w);
-			int32 fwdheight = ((fwd->_text.maxWidth() > (w - st::msgPadding.left() - st::msgPadding.right())) ? 2 : 1) * st::semiboldFont->height;
+			int32 fwdheight = ((forwarded->_text.maxWidth() > (w - st::msgPadding.left() - st::msgPadding.right())) ? 2 : 1) * st::semiboldFont->height;
 			_height += fwdheight;
 		}
 
@@ -1722,8 +1722,8 @@ void HistoryMessage::updatePressed(int x, int y) {
 		} else {
 			if (displayFromName()) trect.setTop(trect.top() + st::msgNameFont->height);
 			if (displayForwardedFrom()) {
-				auto fwd = Get<HistoryMessageForwarded>();
-				auto fwdheight = ((fwd->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
+				auto forwarded = Get<HistoryMessageForwarded>();
+				auto fwdheight = ((forwarded->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
 				trect.setTop(trect.top() + fwdheight);
 			}
 			if (Get<HistoryMessageReply>()) {
@@ -1760,9 +1760,9 @@ bool HistoryMessage::getStateFromName(int x, int y, QRect &trect, HistoryTextSta
 				outResult->link = author()->openLink();
 				return true;
 			}
-			auto fwd = Get<HistoryMessageForwarded>();
+			auto forwarded = Get<HistoryMessageForwarded>();
 			auto via = Get<HistoryMessageVia>();
-			if (via && !fwd && x >= trect.left() + author()->nameText.maxWidth() + st::msgServiceFont->spacew && x < trect.left() + author()->nameText.maxWidth() + st::msgServiceFont->spacew + via->_width) {
+			if (via && !forwarded && x >= trect.left() + author()->nameText.maxWidth() + st::msgServiceFont->spacew && x < trect.left() + author()->nameText.maxWidth() + st::msgServiceFont->spacew + via->_width) {
 				outResult->link = via->_lnk;
 				return true;
 			}
@@ -1774,15 +1774,15 @@ bool HistoryMessage::getStateFromName(int x, int y, QRect &trect, HistoryTextSta
 
 bool HistoryMessage::getStateForwardedInfo(int x, int y, QRect &trect, HistoryTextState *outResult, const HistoryStateRequest &request) const {
 	if (displayForwardedFrom()) {
-		auto fwd = Get<HistoryMessageForwarded>();
-		int32 fwdheight = ((fwd->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
+		auto forwarded = Get<HistoryMessageForwarded>();
+		auto fwdheight = ((forwarded->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
 		if (y >= trect.top() && y < trect.top() + fwdheight) {
-			bool breakEverywhere = (fwd->_text.countHeight(trect.width()) > 2 * st::semiboldFont->height);
+			auto breakEverywhere = (forwarded->_text.countHeight(trect.width()) > 2 * st::semiboldFont->height);
 			auto textRequest = request.forText();
 			if (breakEverywhere) {
 				textRequest.flags |= Text::StateRequest::Flag::BreakEverywhere;
 			}
-			*outResult = fwd->_text.getState(x - trect.left(), y - trect.top(), trect.width(), textRequest);
+			*outResult = forwarded->_text.getState(x - trect.left(), y - trect.top(), trect.width(), textRequest);
 			outResult->symbol = 0;
 			outResult->afterSymbol = false;
 			if (breakEverywhere) {
diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h
index ab1cf03b4..0fec75c0a 100644
--- a/Telegram/SourceFiles/history/history_message.h
+++ b/Telegram/SourceFiles/history/history_message.h
@@ -166,8 +166,12 @@ private:
 	void applyEditionToEmpty();
 
 	bool displayForwardedFrom() const {
-		if (auto fwd = Get<HistoryMessageForwarded>()) {
-			return Has<HistoryMessageVia>() || !_media || !_media->isDisplayed() || fwd->_authorOriginal->isChannel() || !_media->hideForwardedFrom();
+		if (auto forwarded = Get<HistoryMessageForwarded>()) {
+			return Has<HistoryMessageVia>()
+				|| !_media
+				|| !_media->isDisplayed()
+				|| !_media->hideForwardedFrom()
+				|| forwarded->_authorOriginal->isChannel();
 		}
 		return false;
 	}
diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp
index d92e362f9..555fd33aa 100644
--- a/Telegram/SourceFiles/overview/overview_layout.cpp
+++ b/Telegram/SourceFiles/overview/overview_layout.cpp
@@ -643,8 +643,8 @@ void Voice::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, i
 }
 
 void Voice::updateName() {
-	int32 version = 0;
-	if (const HistoryMessageForwarded *fwd = _parent->Get<HistoryMessageForwarded>()) {
+	auto version = 0;
+	if (auto forwarded = _parent->Get<HistoryMessageForwarded>()) {
 		if (_parent->fromOriginal()->isChannel()) {
 			_name.setText(st::semiboldTextStyle, lng_forwarded_channel(lt_channel, App::peerName(_parent->fromOriginal())), _textNameOptions);
 		} else {
diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp
index ebbce19dd..44c559869 100644
--- a/Telegram/SourceFiles/window/notifications_manager.cpp
+++ b/Telegram/SourceFiles/window/notifications_manager.cpp
@@ -290,23 +290,23 @@ void System::showNext() {
 				_waitTimer.start(next - ms);
 				break;
 			} else {
-				HistoryItem *fwd = notifyItem->Has<HistoryMessageForwarded>() ? notifyItem : nullptr; // forwarded notify grouping
-				int32 fwdCount = 1;
+				auto forwardedItem = notifyItem->Has<HistoryMessageForwarded>() ? notifyItem : nullptr; // forwarded notify grouping
+				auto forwardedCount = 1;
 
 				auto ms = getms(true);
-				History *history = notifyItem->history();
+				auto history = notifyItem->history();
 				auto j = _whenMaps.find(history);
 				if (j == _whenMaps.cend()) {
 					history->clearNotifications();
 				} else {
-					HistoryItem *nextNotify = 0;
+					auto nextNotify = (HistoryItem*)nullptr;
 					do {
 						history->skipNotification();
 						if (!history->hasNotification()) {
 							break;
 						}
 
-						j.value().remove((fwd ? fwd : notifyItem)->id);
+						j.value().remove((forwardedItem ? forwardedItem : notifyItem)->id);
 						do {
 							auto k = j.value().constFind(history->currentNotification()->id);
 							if (k != j.value().cend()) {
@@ -317,11 +317,11 @@ void System::showNext() {
 							history->skipNotification();
 						} while (history->hasNotification());
 						if (nextNotify) {
-							if (fwd) {
-								HistoryItem *nextFwd = nextNotify->Has<HistoryMessageForwarded>() ? nextNotify : nullptr;
-								if (nextFwd && fwd->author() == nextFwd->author() && qAbs(int64(nextFwd->date.toTime_t()) - int64(fwd->date.toTime_t())) < 2) {
-									fwd = nextFwd;
-									++fwdCount;
+							if (forwardedItem) {
+								auto nextForwarded = nextNotify->Has<HistoryMessageForwarded>() ? nextNotify : nullptr;
+								if (nextForwarded && forwardedItem->author() == nextForwarded->author() && qAbs(int64(nextForwarded->date.toTime_t()) - int64(forwardedItem->date.toTime_t())) < 2) {
+									forwardedItem = nextForwarded;
+									++forwardedCount;
 								} else {
 									nextNotify = nullptr;
 								}
@@ -332,7 +332,7 @@ void System::showNext() {
 					} while (nextNotify);
 				}
 
-				_manager->showNotification(notifyItem, fwdCount);
+				_manager->showNotification(notifyItem, forwardedCount);
 
 				if (!history->hasNotification()) {
 					_waiters.remove(history);