Display forwarded info in video messages.

This commit is contained in:
John Preston 2017-04-30 15:44:17 +03:00
parent 4659b664e7
commit eb240defa3
8 changed files with 136 additions and 80 deletions

View File

@ -2445,8 +2445,8 @@ QString HistoryInner::tooltipText() const {
} }
} else if (_dragCursorState == HistoryInForwardedCursorState && _dragAction == NoDrag) { } else if (_dragCursorState == HistoryInForwardedCursorState && _dragAction == NoDrag) {
if (App::hoveredItem()) { if (App::hoveredItem()) {
if (HistoryMessageForwarded *fwd = App::hoveredItem()->Get<HistoryMessageForwarded>()) { if (auto forwarded = App::hoveredItem()->Get<HistoryMessageForwarded>()) {
return fwd->_text.originalText(AllTextSelection, ExpandLinksNone); return forwarded->_text.originalText(AllTextSelection, ExpandLinksNone);
} }
} }
} else if (ClickHandlerPtr lnk = ClickHandler::getActive()) { } else if (ClickHandlerPtr lnk = ClickHandler::getActive()) {

View File

@ -779,20 +779,20 @@ public:
} }
PeerData *fromOriginal() const { PeerData *fromOriginal() const {
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
return fwd->_fromOriginal; return forwarded->_fromOriginal;
} }
return from(); return from();
} }
PeerData *authorOriginal() const { PeerData *authorOriginal() const {
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
return fwd->_authorOriginal; return forwarded->_authorOriginal;
} }
return author(); return author();
} }
MsgId idOriginal() const { MsgId idOriginal() const {
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
return fwd->_originalId; return forwarded->_originalId;
} }
return id; return id;
} }

View File

@ -36,6 +36,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace { namespace {
constexpr auto kMaxGifForwardedBarLines = 4;
TextParseOptions _webpageTitleOptions = { TextParseOptions _webpageTitleOptions = {
TextParseMultiline | TextParseRichText, // flags TextParseMultiline | TextParseRichText, // flags
0, // maxw 0, // maxw
@ -1724,7 +1726,13 @@ void HistoryGif::initDimensions() {
} }
} }
} else if (isSeparateRoundVideo()) { } 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()) { } else if (isSeparateRoundVideo()) {
auto via = _parent->Get<HistoryMessageVia>(); auto via = _parent->Get<HistoryMessageVia>();
auto reply = _parent->Get<HistoryMessageReply>(); auto reply = _parent->Get<HistoryMessageReply>();
if (via || reply) { auto forwarded = _parent->Get<HistoryMessageForwarded>();
_width += additionalWidth(via, reply); if (via || reply || forwarded) {
auto additional = additionalWidth(via, reply, forwarded);
_width += additional;
accumulate_min(_width, width); 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(); auto availw = _width - usew - st::msgReplyPadding.left() - st::msgReplyPadding.left() - st::msgReplyPadding.left();
if (via) { if (!forwarded && via) {
via->resize(availw); via->resize(availw);
} }
if (reply) { if (reply) {
@ -1868,8 +1878,9 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
auto usex = 0, usew = width; auto usex = 0, usew = width;
auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>(); auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>();
auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>(); auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>();
if (via || reply) { auto forwarded = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageForwarded>();
usew = _maxw - additionalWidth(via, reply); if (via || reply || forwarded) {
usew = _maxw - additionalWidth(via, reply, forwarded);
if (isPost) { if (isPost) {
} else if (out) { } else if (out) {
usex = _width - usew; 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)); 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)) { if (!isChildMedia && (via || reply || forwarded)) {
int rectw = _width - usew - st::msgReplyPadding.left(); auto rectw = _width - usew - st::msgReplyPadding.left();
int recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom(); auto innerw = rectw - (st::msgReplyPadding.left() + st::msgReplyPadding.right());
if (via) { 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); recth += st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
} }
if (reply) { if (reply) {
@ -1996,9 +2012,16 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
if (rtl()) rectx = _width - rectx - rectw; if (rtl()) rectx = _width - rectx - rectw;
App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners); App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
p.setPen(st::msgServiceFg);
rectx += st::msgReplyPadding.left(); rectx += st::msgReplyPadding.left();
rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right(); rectw = innerw;
if (via) { 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); p.drawTextLeft(rectx, recty + st::msgReplyPadding.top(), 2 * rectx + rectw, via->_text);
int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0); int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
recty += skip; recty += skip;
@ -2070,8 +2093,9 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request)
auto usew = width, usex = 0; auto usew = width, usex = 0;
auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>(); auto via = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageVia>();
auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>(); auto reply = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageReply>();
if (via || reply) { auto forwarded = (!isRound || isChildMedia) ? nullptr : _parent->Get<HistoryMessageForwarded>();
usew = _maxw - additionalWidth(via, reply); if (via || reply || forwarded) {
usew = _maxw - additionalWidth(via, reply, forwarded);
if (isPost) { if (isPost) {
} else if (out) { } else if (out) {
usex = _width - usew; usex = _width - usew;
@ -2079,20 +2103,44 @@ HistoryTextState HistoryGif::getState(int x, int y, HistoryStateRequest request)
} }
if (rtl()) usex = _width - usex - usew; if (rtl()) usex = _width - usex - usew;
if (via || reply) { if (via || reply || forwarded) {
int rectw = width - usew - st::msgReplyPadding.left(); auto rectw = width - usew - st::msgReplyPadding.left();
int recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom(); auto innerw = rectw - (st::msgReplyPadding.left() + st::msgReplyPadding.right());
if (via) { 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); recth += st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
} }
if (reply) { if (reply) {
recth += st::msgReplyBarSize.height(); recth += st::msgReplyBarSize.height();
} }
int rectx = isPost ? (usew + st::msgReplyPadding.left()) : (out ? 0 : (usew + st::msgReplyPadding.left())); auto rectx = isPost ? (usew + st::msgReplyPadding.left()) : (out ? 0 : (usew + st::msgReplyPadding.left()));
int recty = skipy; auto recty = skipy;
if (rtl()) rectx = _width - rectx - rectw; 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()); int viah = st::msgReplyPadding.top() + st::msgServiceNameFont->height + (reply ? 0 : st::msgReplyPadding.bottom());
if (x >= rectx && y >= recty && x < rectx + rectw && y < recty + viah) { if (x >= rectx && y >= recty && x < rectx + rectw && y < recty + viah) {
result.link = via->_lnk; result.link = via->_lnk;
@ -2201,9 +2249,11 @@ ImagePtr HistoryGif::replyPreview() {
return _data->makeReplyPreview(); 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; 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()); accumulate_max(result, st::msgReplyPadding.left() + st::msgReplyPadding.left() + via->_maxWidth + st::msgReplyPadding.left());
} }
if (reply) { if (reply) {
@ -2400,9 +2450,11 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, T
recty -= st::msgDateImgDelta; recty -= st::msgDateImgDelta;
App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners); App::roundRect(p, rectx, recty, rectw, recth, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
p.setPen(st::msgServiceFg);
rectx += st::msgReplyPadding.left(); rectx += st::msgReplyPadding.left();
rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right(); rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right();
if (via) { if (via) {
p.setFont(st::msgDateFont);
p.drawTextLeft(rectx, recty + st::msgReplyPadding.top(), 2 * rectx + rectw, via->_text); p.drawTextLeft(rectx, recty + st::msgReplyPadding.top(), 2 * rectx + rectw, via->_text);
int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0); int skip = st::msgServiceNameFont->height + (reply ? st::msgReplyPadding.top() : 0);
recty += skip; recty += skip;

View File

@ -555,9 +555,9 @@ protected:
} }
private: 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 { 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; QString mediaTypeString() const;
bool isSeparateRoundVideo() const { bool isSeparateRoundVideo() const {

View File

@ -631,10 +631,10 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
if (auto edited = Get<HistoryMessageEdited>()) { if (auto edited = Get<HistoryMessageEdited>()) {
edited->create(config.editDate, date); edited->create(config.editDate, date);
} }
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
fwd->_authorOriginal = App::peer(config.authorIdOriginal); forwarded->_authorOriginal = App::peer(config.authorIdOriginal);
fwd->_fromOriginal = App::peer(config.fromIdOriginal); forwarded->_fromOriginal = App::peer(config.fromIdOriginal);
fwd->_originalId = config.originalId; forwarded->_originalId = config.originalId;
} }
if (auto markup = Get<HistoryMessageReplyMarkup>()) { if (auto markup = Get<HistoryMessageReplyMarkup>()) {
if (config.mtpMarkup) { if (config.mtpMarkup) {
@ -777,10 +777,10 @@ void HistoryMessage::initDimensions() {
updateMediaInBubbleState(); updateMediaInBubbleState();
if (drawBubble()) { if (drawBubble()) {
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
auto via = Get<HistoryMessageVia>(); auto via = Get<HistoryMessageVia>();
if (fwd) { if (forwarded) {
fwd->create(via); forwarded->create(via);
} }
auto mediaDisplayed = false; auto mediaDisplayed = false;
@ -816,17 +816,17 @@ void HistoryMessage::initDimensions() {
_minh += st::msgPadding.top() + st::msgPadding.bottom(); _minh += st::msgPadding.top() + st::msgPadding.bottom();
if (displayFromName()) { if (displayFromName()) {
auto namew = st::msgPadding.left() + author()->nameText.maxWidth() + st::msgPadding.right(); auto namew = st::msgPadding.left() + author()->nameText.maxWidth() + st::msgPadding.right();
if (via && !fwd) { if (via && !forwarded) {
namew += st::msgServiceFont->spacew + via->_maxWidth; namew += st::msgServiceFont->spacew + via->_maxWidth;
} }
if (namew > _maxw) _maxw = namew; if (namew > _maxw) _maxw = namew;
} else if (via && !fwd) { } else if (via && !forwarded) {
if (st::msgPadding.left() + via->_maxWidth + st::msgPadding.right() > _maxw) { if (st::msgPadding.left() + via->_maxWidth + st::msgPadding.right() > _maxw) {
_maxw = st::msgPadding.left() + via->_maxWidth + st::msgPadding.right(); _maxw = st::msgPadding.left() + via->_maxWidth + st::msgPadding.right();
} }
} }
if (fwd) { if (forwarded) {
auto _namew = st::msgPadding.left() + fwd->_text.maxWidth() + st::msgPadding.right(); auto _namew = st::msgPadding.left() + forwarded->_text.maxWidth() + st::msgPadding.right();
if (via) { if (via) {
_namew += st::msgServiceFont->spacew + via->_maxWidth; _namew += st::msgServiceFont->spacew + via->_maxWidth;
} }
@ -1015,10 +1015,10 @@ TextWithEntities HistoryMessage::selectedText(TextSelection selection) const {
result.entities = textResult.entities; result.entities = textResult.entities;
appendTextWithEntities(result, std::move(mediaResult)); appendTextWithEntities(result, std::move(mediaResult));
} }
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
if (selection == FullSelection) { if (selection == FullSelection) {
auto fwdinfo = fwd->_text.originalTextWithEntities(AllTextSelection, ExpandLinksAll); auto fwdinfo = forwarded->_text.originalTextWithEntities(AllTextSelection, ExpandLinksAll);
TextWithEntities wrapped; auto wrapped = TextWithEntities();
wrapped.text.reserve(fwdinfo.text.size() + 4 + result.text.size()); wrapped.text.reserve(fwdinfo.text.size() + 4 + result.text.size());
wrapped.entities.reserve(fwdinfo.entities.size() + result.entities.size()); wrapped.entities.reserve(fwdinfo.entities.size() + result.entities.size());
wrapped.text.append('['); 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()); author()->nameText.drawElided(p, trect.left(), trect.top(), trect.width());
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
auto via = Get<HistoryMessageVia>(); 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(); bool outbg = out() && !isPost();
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); 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); 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.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
p.setFont(serviceFont); p.setFont(serviceFont);
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
bool breakEverywhere = (fwd->_text.countHeight(trect.width()) > 2 * serviceFont->height); auto breakEverywhere = (forwarded->_text.countHeight(trect.width()) > 2 * serviceFont->height);
p.setTextPalette(selected ? (outbg ? st::outFwdTextPaletteSelected : st::inFwdTextPaletteSelected) : (outbg ? st::outFwdTextPalette : st::inFwdTextPalette)); 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)); 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; width = st::msgMaxWidth;
} }
if (drawBubble()) { if (drawBubble()) {
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
auto reply = Get<HistoryMessageReply>(); auto reply = Get<HistoryMessageReply>();
auto via = Get<HistoryMessageVia>(); auto via = Get<HistoryMessageVia>();
@ -1555,7 +1555,7 @@ int HistoryMessage::performResizeGetHeight(int width) {
countPositionAndSize(l, w); countPositionAndSize(l, w);
fromNameUpdated(w); fromNameUpdated(w);
_height += st::msgNameFont->height; _height += st::msgNameFont->height;
} else if (via && !fwd) { } else if (via && !forwarded) {
int32 l = 0, w = 0; int32 l = 0, w = 0;
countPositionAndSize(l, w); countPositionAndSize(l, w);
via->resize(w - st::msgPadding.left() - st::msgPadding.right()); via->resize(w - st::msgPadding.left() - st::msgPadding.right());
@ -1565,7 +1565,7 @@ int HistoryMessage::performResizeGetHeight(int width) {
if (displayForwardedFrom()) { if (displayForwardedFrom()) {
int32 l = 0, w = 0; int32 l = 0, w = 0;
countPositionAndSize(l, w); 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; _height += fwdheight;
} }
@ -1722,8 +1722,8 @@ void HistoryMessage::updatePressed(int x, int y) {
} else { } else {
if (displayFromName()) trect.setTop(trect.top() + st::msgNameFont->height); if (displayFromName()) trect.setTop(trect.top() + st::msgNameFont->height);
if (displayForwardedFrom()) { if (displayForwardedFrom()) {
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
auto fwdheight = ((fwd->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height; auto fwdheight = ((forwarded->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
trect.setTop(trect.top() + fwdheight); trect.setTop(trect.top() + fwdheight);
} }
if (Get<HistoryMessageReply>()) { if (Get<HistoryMessageReply>()) {
@ -1760,9 +1760,9 @@ bool HistoryMessage::getStateFromName(int x, int y, QRect &trect, HistoryTextSta
outResult->link = author()->openLink(); outResult->link = author()->openLink();
return true; return true;
} }
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
auto via = Get<HistoryMessageVia>(); 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; outResult->link = via->_lnk;
return true; 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 { bool HistoryMessage::getStateForwardedInfo(int x, int y, QRect &trect, HistoryTextState *outResult, const HistoryStateRequest &request) const {
if (displayForwardedFrom()) { if (displayForwardedFrom()) {
auto fwd = Get<HistoryMessageForwarded>(); auto forwarded = Get<HistoryMessageForwarded>();
int32 fwdheight = ((fwd->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height; auto fwdheight = ((forwarded->_text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
if (y >= trect.top() && y < trect.top() + fwdheight) { 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(); auto textRequest = request.forText();
if (breakEverywhere) { if (breakEverywhere) {
textRequest.flags |= Text::StateRequest::Flag::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->symbol = 0;
outResult->afterSymbol = false; outResult->afterSymbol = false;
if (breakEverywhere) { if (breakEverywhere) {

View File

@ -166,8 +166,12 @@ private:
void applyEditionToEmpty(); void applyEditionToEmpty();
bool displayForwardedFrom() const { bool displayForwardedFrom() const {
if (auto fwd = Get<HistoryMessageForwarded>()) { if (auto forwarded = Get<HistoryMessageForwarded>()) {
return Has<HistoryMessageVia>() || !_media || !_media->isDisplayed() || fwd->_authorOriginal->isChannel() || !_media->hideForwardedFrom(); return Has<HistoryMessageVia>()
|| !_media
|| !_media->isDisplayed()
|| !_media->hideForwardedFrom()
|| forwarded->_authorOriginal->isChannel();
} }
return false; return false;
} }

View File

@ -643,8 +643,8 @@ void Voice::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, i
} }
void Voice::updateName() { void Voice::updateName() {
int32 version = 0; auto version = 0;
if (const HistoryMessageForwarded *fwd = _parent->Get<HistoryMessageForwarded>()) { if (auto forwarded = _parent->Get<HistoryMessageForwarded>()) {
if (_parent->fromOriginal()->isChannel()) { if (_parent->fromOriginal()->isChannel()) {
_name.setText(st::semiboldTextStyle, lng_forwarded_channel(lt_channel, App::peerName(_parent->fromOriginal())), _textNameOptions); _name.setText(st::semiboldTextStyle, lng_forwarded_channel(lt_channel, App::peerName(_parent->fromOriginal())), _textNameOptions);
} else { } else {

View File

@ -290,23 +290,23 @@ void System::showNext() {
_waitTimer.start(next - ms); _waitTimer.start(next - ms);
break; break;
} else { } else {
HistoryItem *fwd = notifyItem->Has<HistoryMessageForwarded>() ? notifyItem : nullptr; // forwarded notify grouping auto forwardedItem = notifyItem->Has<HistoryMessageForwarded>() ? notifyItem : nullptr; // forwarded notify grouping
int32 fwdCount = 1; auto forwardedCount = 1;
auto ms = getms(true); auto ms = getms(true);
History *history = notifyItem->history(); auto history = notifyItem->history();
auto j = _whenMaps.find(history); auto j = _whenMaps.find(history);
if (j == _whenMaps.cend()) { if (j == _whenMaps.cend()) {
history->clearNotifications(); history->clearNotifications();
} else { } else {
HistoryItem *nextNotify = 0; auto nextNotify = (HistoryItem*)nullptr;
do { do {
history->skipNotification(); history->skipNotification();
if (!history->hasNotification()) { if (!history->hasNotification()) {
break; break;
} }
j.value().remove((fwd ? fwd : notifyItem)->id); j.value().remove((forwardedItem ? forwardedItem : notifyItem)->id);
do { do {
auto k = j.value().constFind(history->currentNotification()->id); auto k = j.value().constFind(history->currentNotification()->id);
if (k != j.value().cend()) { if (k != j.value().cend()) {
@ -317,11 +317,11 @@ void System::showNext() {
history->skipNotification(); history->skipNotification();
} while (history->hasNotification()); } while (history->hasNotification());
if (nextNotify) { if (nextNotify) {
if (fwd) { if (forwardedItem) {
HistoryItem *nextFwd = nextNotify->Has<HistoryMessageForwarded>() ? nextNotify : nullptr; auto nextForwarded = nextNotify->Has<HistoryMessageForwarded>() ? nextNotify : nullptr;
if (nextFwd && fwd->author() == nextFwd->author() && qAbs(int64(nextFwd->date.toTime_t()) - int64(fwd->date.toTime_t())) < 2) { if (nextForwarded && forwardedItem->author() == nextForwarded->author() && qAbs(int64(nextForwarded->date.toTime_t()) - int64(forwardedItem->date.toTime_t())) < 2) {
fwd = nextFwd; forwardedItem = nextForwarded;
++fwdCount; ++forwardedCount;
} else { } else {
nextNotify = nullptr; nextNotify = nullptr;
} }
@ -332,7 +332,7 @@ void System::showNext() {
} while (nextNotify); } while (nextNotify);
} }
_manager->showNotification(notifyItem, fwdCount); _manager->showNotification(notifyItem, forwardedCount);
if (!history->hasNotification()) { if (!history->hasNotification()) {
_waiters.remove(history); _waiters.remove(history);