diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 7ce86f253b..18f0bf8b96 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -4728,21 +4728,21 @@ void HistorySticker::initDimensions() { if (_pixh < 1) _pixh = 1; _maxw = qMax(_pixw, int16(st::minPhotoSize)); _minh = qMax(_pixh, int16(st::minPhotoSize)); + if (_parent->getMedia() == this) { + _maxw += additionalWidth(); + } _height = _minh; } int HistorySticker::resizeGetHeight(int width) { // return new height - int maxWidth = _maxw; - if (_parent->getMedia() == this) { - maxWidth += additionalWidth(); - } - _width = qMin(width, maxWidth); + _width = qMin(width, _maxw); if (_parent->getMedia() == this) { auto via = _parent->Get(); auto reply = _parent->Get(); if (via || reply) { - int availw = _width - _maxw - st::msgReplyPadding.left() - st::msgReplyPadding.left() - st::msgReplyPadding.left(); + int usew = _maxw - additionalWidth(via, reply); + int availw = _width - usew - st::msgReplyPadding.left() - st::msgReplyPadding.left() - st::msgReplyPadding.left(); if (via) { via->resize(availw); } @@ -4767,6 +4767,7 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, u auto via = childmedia ? nullptr : _parent->Get(); auto reply = childmedia ? nullptr : _parent->Get(); if (via || reply) { + usew -= additionalWidth(via, reply); if (isPost) { } else if (out) { usex = _width - usew; @@ -4836,6 +4837,7 @@ HistoryTextState HistorySticker::getState(int x, int y, HistoryStateRequest requ auto via = childmedia ? nullptr : _parent->Get(); auto reply = childmedia ? nullptr : _parent->Get(); if (via || reply) { + usew -= additionalWidth(via, reply); if (isPost) { } else if (out) { usex = _width - usew; @@ -6207,10 +6209,12 @@ void HistoryMessageReply::clearData(HistoryMessage *holder) { replyToMsgId = 0; } -void HistoryMessageReply::checkNameUpdate() const { +bool HistoryMessageReply::isNameUpdated() const { if (replyToMsg && replyToMsg->author()->nameVersion > replyToVersion) { updateName(); + return true; } + return false; } void HistoryMessageReply::updateName() const { @@ -6482,6 +6486,22 @@ void HistoryMessage::createComponentsHelper(MTPDmessage::Flags flags, MsgId repl createComponents(config); } +bool HistoryMessage::displayEditedBadge(bool hasViaBot) const { + if (!(_flags & MTPDmessage::Flag::f_edit_date)) { + return false; + } + if (auto fromUser = from()->asUser()) { + if (fromUser->botInfo) { + return false; + } + } + if (hasViaBot) { + return false; + } + return true; +} + + void HistoryMessage::createComponents(const CreateConfig &config) { uint64 mask = 0; if (config.replyTo) { @@ -6496,7 +6516,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (isPost() && _from->isUser()) { mask |= HistoryMessageSigned::Bit(); } - if (wasEdited()) { + if (displayEditedBadge(config.viaBotId != 0)) { mask |= HistoryMessageEdited::Bit(); } if (config.authorIdOriginal && config.fromIdOriginal) { @@ -6638,6 +6658,10 @@ int32 HistoryMessage::plainMaxWidth() const { } void HistoryMessage::initDimensions() { + auto reply = Get(); + if (reply) { + reply->updateName(); + } if (drawBubble()) { auto fwd = Get(); auto via = Get(); @@ -6696,15 +6720,12 @@ void HistoryMessage::initDimensions() { _maxw = _media->maxWidth(); _minh = _media->minHeight(); } - if (auto reply = Get()) { - reply->updateName(); - if (!_text.isEmpty()) { - int replyw = st::msgPadding.left() + reply->_maxReplyWidth - st::msgReplyPadding.left() - st::msgReplyPadding.right() + st::msgPadding.right(); - if (reply->_replyToVia) { - replyw += st::msgServiceFont->spacew + reply->_replyToVia->_maxWidth; - } - if (replyw > _maxw) _maxw = replyw; + if (reply && !_text.isEmpty()) { + int replyw = st::msgPadding.left() + reply->_maxReplyWidth - st::msgReplyPadding.left() - st::msgReplyPadding.right() + st::msgPadding.right(); + if (reply->_replyToVia) { + replyw += st::msgServiceFont->spacew + reply->_replyToVia->_maxWidth; } + if (replyw > _maxw) _maxw = replyw; } if (HistoryMessageReplyMarkup *markup = inlineReplyMarkup()) { if (!markup->inlineKeyboard) { @@ -6761,10 +6782,14 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) { if (message.has_edit_date()) { _flags |= MTPDmessage::Flag::f_edit_date; - if (!Has()) { - AddComponents(HistoryMessageEdited::Bit()); + if (displayEditedBadge(Has())) { + if (!Has()) { + AddComponents(HistoryMessageEdited::Bit()); + } + Get()->create(::date(message.vedit_date), date); + } else if (Has()) { + RemoveComponents(HistoryMessageEdited::Bit()); } - Get()->create(::date(message.vedit_date), date); initTime(); } @@ -7161,11 +7186,6 @@ void HistoryMessage::draw(Painter &p, const QRect &r, TextSelection selection, u p.translate(-left, -top); } - auto reply = Get(); - if (reply) { - reply->checkNameUpdate(); - } - if (bubble) { auto fwd = Get(); auto via = Get(); @@ -7225,6 +7245,11 @@ void HistoryMessage::draw(Painter &p, const QRect &r, TextSelection selection, u } textstyleRestore(); + + auto reply = Get(); + if (reply && reply->isNameUpdated()) { + const_cast(this)->setPendingInitDimensions(); + } } void HistoryMessage::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const { diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 0508473ad9..86e8bd22f6 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -823,7 +823,7 @@ struct HistoryMessageReply : public BaseComponent { bool updateData(HistoryMessage *holder, bool force = false); void clearData(HistoryMessage *holder); // must be called before destructor - void checkNameUpdate() const; + bool isNameUpdated() const; void updateName() const; void resize(int width) const; void itemRemoved(HistoryMessage *holder, HistoryItem *removed); @@ -1299,9 +1299,6 @@ public: } bool canEdit(const QDateTime &cur) const; - bool wasEdited() const { - return _flags & MTPDmessage::Flag::f_edit_date; - } bool suggestBanReportDeleteAll() const { ChannelData *channel = history()->peer->asChannel(); @@ -2598,6 +2595,7 @@ public: return (!emptyText() || !_media || !_media->isDisplayed() || Has() || Has() || viaBot() || !_media->hideFromName()); } + bool displayEditedBadge(bool hasViaBot) const; bool uploading() const { return _media && _media->uploading(); } diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index 6368d6421d..8da1a472ec 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -482,6 +482,9 @@ public: bool skip = false, isNewLine = multiline && chIsNewline(ch), isSpace = chIsSpace(ch), isDiac = chIsDiac(ch), isTilde = checkTilde && (ch == '~'); if (chIsBad(ch) || ch.isLowSurrogate()) { skip = true; + } else if (ch == 0xFE0F && (cPlatform() == dbipMac || cPlatform() == dbipMacOld)) { + // Some sequences like 0x0E53 0xFE0F crash OS X harfbuzz text processing :( + skip = true; } else if (isDiac) { if (lastSkipped || emoji || ++diacs > chMaxDiacAfterSymbol()) { skip = true;