2018-01-10 13:13:33 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "history/view/history_view_message.h"
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
|
|
|
#include "history/history_item_components.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_message.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
|
|
|
#include "history/view/media/history_view_web_page.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-03-15 15:15:56 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-05-25 14:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "mainwidget.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "mainwindow.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "layout.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
2018-01-11 15:51:59 +00:00
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
namespace HistoryView {
|
2018-01-13 12:45:11 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class KeyboardStyle : public ReplyKeyboard::Style {
|
|
|
|
public:
|
|
|
|
using ReplyKeyboard::Style::Style;
|
|
|
|
|
|
|
|
int buttonRadius() const override;
|
|
|
|
|
|
|
|
void startPaint(Painter &p) const override;
|
|
|
|
const style::TextStyle &textStyle() const override;
|
|
|
|
void repaint(not_null<const HistoryItem*> item) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintButtonBg(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &rect,
|
|
|
|
float64 howMuchOver) const override;
|
|
|
|
void paintButtonIcon(Painter &p, const QRect &rect, int outerWidth, HistoryMessageMarkupButton::Type type) const override;
|
|
|
|
void paintButtonLoading(Painter &p, const QRect &rect) const override;
|
|
|
|
int minButtonWidth(HistoryMessageMarkupButton::Type type) const override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void KeyboardStyle::startPaint(Painter &p) const {
|
|
|
|
p.setPen(st::msgServiceFg);
|
|
|
|
}
|
|
|
|
|
|
|
|
const style::TextStyle &KeyboardStyle::textStyle() const {
|
|
|
|
return st::serviceTextStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardStyle::repaint(not_null<const HistoryItem*> item) const {
|
2019-01-03 12:36:01 +00:00
|
|
|
item->history()->owner().requestItemRepaint(item);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KeyboardStyle::buttonRadius() const {
|
|
|
|
return st::dateRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardStyle::paintButtonBg(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &rect,
|
|
|
|
float64 howMuchOver) const {
|
|
|
|
App::roundRect(p, rect, st::msgServiceBg, StickerCorners);
|
|
|
|
if (howMuchOver > 0) {
|
|
|
|
auto o = p.opacity();
|
|
|
|
p.setOpacity(o * howMuchOver);
|
|
|
|
App::roundRect(p, rect, st::msgBotKbOverBgAdd, BotKbOverCorners);
|
|
|
|
p.setOpacity(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardStyle::paintButtonIcon(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &rect,
|
|
|
|
int outerWidth,
|
|
|
|
HistoryMessageMarkupButton::Type type) const {
|
2019-05-22 14:29:02 +00:00
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
|
|
|
const auto getIcon = [](Type type) -> const style::icon* {
|
2018-01-13 12:45:11 +00:00
|
|
|
switch (type) {
|
2019-06-05 17:42:10 +00:00
|
|
|
case Type::Url:
|
|
|
|
case Type::Auth: return &st::msgBotKbUrlIcon;
|
2019-05-22 14:29:02 +00:00
|
|
|
case Type::SwitchInlineSame:
|
|
|
|
case Type::SwitchInline: return &st::msgBotKbSwitchPmIcon;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
2019-05-22 14:29:02 +00:00
|
|
|
if (const auto icon = getIcon(type)) {
|
2018-01-13 12:45:11 +00:00
|
|
|
icon->paint(p, rect.x() + rect.width() - icon->width() - st::msgBotKbIconPadding, rect.y() + st::msgBotKbIconPadding, outerWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardStyle::paintButtonLoading(Painter &p, const QRect &rect) const {
|
|
|
|
auto icon = &st::historySendingInvertedIcon;
|
|
|
|
icon->paint(p, rect.x() + rect.width() - icon->width() - st::msgBotKbIconPadding, rect.y() + rect.height() - icon->height() - st::msgBotKbIconPadding, rect.x() * 2 + rect.width());
|
|
|
|
}
|
|
|
|
|
|
|
|
int KeyboardStyle::minButtonWidth(
|
|
|
|
HistoryMessageMarkupButton::Type type) const {
|
2019-05-22 14:29:02 +00:00
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
2018-01-13 12:45:11 +00:00
|
|
|
int result = 2 * buttonPadding(), iconWidth = 0;
|
|
|
|
switch (type) {
|
2019-06-05 17:42:10 +00:00
|
|
|
case Type::Url:
|
|
|
|
case Type::Auth: iconWidth = st::msgBotKbUrlIcon.width(); break;
|
2019-05-22 14:29:02 +00:00
|
|
|
case Type::SwitchInlineSame:
|
|
|
|
case Type::SwitchInline: iconWidth = st::msgBotKbSwitchPmIcon.width(); break;
|
|
|
|
case Type::Callback:
|
2019-06-05 17:42:10 +00:00
|
|
|
case Type::Game: iconWidth = st::historySendingInvertedIcon.width(); break;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
if (iconWidth > 0) {
|
|
|
|
result = std::max(result, 2 * iconWidth + 4 * int(st::msgBotKbIconPadding));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FastReplyText() {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_fast_reply(tr::now);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaintBubble(Painter &p, QRect rect, int outerWidth, bool selected, bool outbg, RectPart tailSide) {
|
|
|
|
auto &bg = selected ? (outbg ? st::msgOutBgSelected : st::msgInBgSelected) : (outbg ? st::msgOutBg : st::msgInBg);
|
|
|
|
auto &sh = selected ? (outbg ? st::msgOutShadowSelected : st::msgInShadowSelected) : (outbg ? st::msgOutShadow : st::msgInShadow);
|
|
|
|
auto cors = selected ? (outbg ? MessageOutSelectedCorners : MessageInSelectedCorners) : (outbg ? MessageOutCorners : MessageInCorners);
|
|
|
|
auto parts = RectPart::FullTop | RectPart::NoTopBottom | RectPart::Bottom;
|
|
|
|
if (tailSide == RectPart::Right) {
|
|
|
|
parts |= RectPart::BottomLeft;
|
|
|
|
p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg);
|
|
|
|
auto &tail = selected ? st::historyBubbleTailOutRightSelected : st::historyBubbleTailOutRight;
|
|
|
|
tail.paint(p, rect.x() + rect.width(), rect.y() + rect.height() - tail.height(), outerWidth);
|
|
|
|
p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh);
|
|
|
|
} else if (tailSide == RectPart::Left) {
|
|
|
|
parts |= RectPart::BottomRight;
|
|
|
|
p.fillRect(rect.x(), rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg);
|
|
|
|
auto &tail = selected ? (outbg ? st::historyBubbleTailOutLeftSelected : st::historyBubbleTailInLeftSelected) : (outbg ? st::historyBubbleTailOutLeft : st::historyBubbleTailInLeft);
|
|
|
|
tail.paint(p, rect.x() - tail.width(), rect.y() + rect.height() - tail.height(), outerWidth);
|
|
|
|
p.fillRect(rect.x() - tail.width(), rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh);
|
|
|
|
} else {
|
|
|
|
parts |= RectPart::FullBottom;
|
|
|
|
}
|
|
|
|
App::roundRect(p, rect, bg, cors, &sh, parts);
|
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
style::color FromNameFg(PeerId peerId, bool selected) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (selected) {
|
|
|
|
const style::color colors[] = {
|
|
|
|
st::historyPeer1NameFgSelected,
|
|
|
|
st::historyPeer2NameFgSelected,
|
|
|
|
st::historyPeer3NameFgSelected,
|
|
|
|
st::historyPeer4NameFgSelected,
|
|
|
|
st::historyPeer5NameFgSelected,
|
|
|
|
st::historyPeer6NameFgSelected,
|
|
|
|
st::historyPeer7NameFgSelected,
|
|
|
|
st::historyPeer8NameFgSelected,
|
|
|
|
};
|
2019-03-15 15:15:56 +00:00
|
|
|
return colors[Data::PeerColorIndex(peerId)];
|
2018-01-13 12:45:11 +00:00
|
|
|
} else {
|
|
|
|
const style::color colors[] = {
|
|
|
|
st::historyPeer1NameFg,
|
|
|
|
st::historyPeer2NameFg,
|
|
|
|
st::historyPeer3NameFg,
|
|
|
|
st::historyPeer4NameFg,
|
|
|
|
st::historyPeer5NameFg,
|
|
|
|
st::historyPeer6NameFg,
|
|
|
|
st::historyPeer7NameFg,
|
|
|
|
st::historyPeer8NameFg,
|
|
|
|
};
|
2019-03-15 15:15:56 +00:00
|
|
|
return colors[Data::PeerColorIndex(peerId)];
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2018-01-10 13:13:33 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
LogEntryOriginal::LogEntryOriginal() = default;
|
|
|
|
|
|
|
|
LogEntryOriginal::LogEntryOriginal(LogEntryOriginal &&other)
|
|
|
|
: page(std::move(other.page)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
LogEntryOriginal &LogEntryOriginal::operator=(LogEntryOriginal &&other) {
|
|
|
|
page = std::move(other.page);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogEntryOriginal::~LogEntryOriginal() = default;
|
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
Message::Message(
|
|
|
|
not_null<ElementDelegate*> delegate,
|
|
|
|
not_null<HistoryMessage*> data)
|
|
|
|
: Element(delegate, data) {
|
2018-01-14 16:02:25 +00:00
|
|
|
initLogEntryOriginal();
|
2018-01-10 13:13:33 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<HistoryMessage*> Message::message() const {
|
|
|
|
return static_cast<HistoryMessage*>(data().get());
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
QSize Message::performCountOptimalSize() {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto maxWidth = 0;
|
|
|
|
auto minHeight = 0;
|
|
|
|
|
|
|
|
updateMediaInBubbleState();
|
2018-01-14 16:02:25 +00:00
|
|
|
refreshEditedBadge();
|
|
|
|
|
|
|
|
auto mediaOnBottom = (logEntryOriginal() != nullptr)
|
|
|
|
|| (media && media->isDisplayed() && media->isBubbleBottom());
|
|
|
|
if (mediaOnBottom) {
|
|
|
|
// remove skip
|
|
|
|
} else {
|
|
|
|
// add skip
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawBubble()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto forwarded = item->Get<HistoryMessageForwarded>();
|
|
|
|
auto reply = item->Get<HistoryMessageReply>();
|
|
|
|
auto via = item->Get<HistoryMessageVia>();
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entry = logEntryOriginal();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (forwarded) {
|
|
|
|
forwarded->create(via);
|
|
|
|
}
|
|
|
|
if (reply) {
|
|
|
|
reply->updateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto mediaDisplayed = false;
|
|
|
|
if (media) {
|
|
|
|
mediaDisplayed = media->isDisplayed();
|
|
|
|
media->initDimensions();
|
|
|
|
}
|
|
|
|
if (entry) {
|
2018-01-14 16:02:25 +00:00
|
|
|
entry->initDimensions();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry page is always a bubble bottom.
|
2018-01-14 16:02:25 +00:00
|
|
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
|
|
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
if (mediaOnBottom) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (item->_text.removeSkipBlock()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
item->_textWidth = -1;
|
|
|
|
item->_textHeight = 0;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (item->_text.updateSkipBlock(skipBlockWidth(), skipBlockHeight())) {
|
2018-01-13 12:45:11 +00:00
|
|
|
item->_textWidth = -1;
|
|
|
|
item->_textHeight = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-19 12:13:06 +00:00
|
|
|
maxWidth = plainMaxWidth();
|
2018-01-18 13:59:22 +00:00
|
|
|
minHeight = hasVisibleText() ? item->_text.minHeight() : 0;
|
2018-01-13 12:45:11 +00:00
|
|
|
if (!mediaOnBottom) {
|
|
|
|
minHeight += st::msgPadding.bottom();
|
|
|
|
if (mediaDisplayed) minHeight += st::mediaInBubbleSkip;
|
|
|
|
}
|
|
|
|
if (!mediaOnTop) {
|
|
|
|
minHeight += st::msgPadding.top();
|
|
|
|
if (mediaDisplayed) minHeight += st::mediaInBubbleSkip;
|
|
|
|
if (entry) minHeight += st::mediaInBubbleSkip;
|
|
|
|
}
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
// Parts don't participate in maxWidth() in case of media message.
|
2019-01-29 16:26:19 +00:00
|
|
|
if (media->enforceBubbleWidth()) {
|
|
|
|
maxWidth = media->maxWidth();
|
|
|
|
if (hasVisibleText() && maxWidth < plainMaxWidth()) {
|
|
|
|
minHeight -= item->_text.minHeight();
|
|
|
|
minHeight += item->_text.countHeight(maxWidth - st::msgPadding.left() - st::msgPadding.right());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
accumulate_max(maxWidth, media->maxWidth());
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
minHeight += media->minHeight();
|
|
|
|
} else {
|
|
|
|
// Count parts in maxWidth(), don't count them in minHeight().
|
|
|
|
// They will be added in resizeGetHeight() anyway.
|
|
|
|
if (displayFromName()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto from = item->displayFrom();
|
|
|
|
const auto &name = from
|
2019-06-12 10:45:06 +00:00
|
|
|
? from->nameText()
|
2019-03-15 15:15:56 +00:00
|
|
|
: item->hiddenForwardedInfo()->nameText;
|
2018-01-13 12:45:11 +00:00
|
|
|
auto namew = st::msgPadding.left()
|
2019-03-15 15:15:56 +00:00
|
|
|
+ name.maxWidth()
|
2018-01-13 12:45:11 +00:00
|
|
|
+ st::msgPadding.right();
|
2018-02-03 20:25:34 +00:00
|
|
|
if (via && !displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
namew += st::msgServiceFont->spacew + via->maxWidth;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto replyWidth = hasFastReply()
|
2018-01-13 12:45:11 +00:00
|
|
|
? st::msgFont->width(FastReplyText())
|
|
|
|
: 0;
|
2019-05-24 12:13:16 +00:00
|
|
|
if (item->hasMessageBadge()) {
|
2019-07-19 15:05:48 +00:00
|
|
|
const auto badgeWidth = item->messageBadge().maxWidth();
|
2018-01-13 12:45:11 +00:00
|
|
|
namew += st::msgPadding.right()
|
|
|
|
+ std::max(badgeWidth, replyWidth);
|
|
|
|
} else if (replyWidth) {
|
|
|
|
namew += st::msgPadding.right() + replyWidth;
|
|
|
|
}
|
|
|
|
accumulate_max(maxWidth, namew);
|
2018-02-03 20:25:34 +00:00
|
|
|
} else if (via && !displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
accumulate_max(maxWidth, st::msgPadding.left() + via->maxWidth + st::msgPadding.right());
|
|
|
|
}
|
2018-02-03 20:25:34 +00:00
|
|
|
if (displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto namew = st::msgPadding.left() + forwarded->text.maxWidth() + st::msgPadding.right();
|
|
|
|
if (via) {
|
|
|
|
namew += st::msgServiceFont->spacew + via->maxWidth;
|
|
|
|
}
|
|
|
|
accumulate_max(maxWidth, namew);
|
|
|
|
}
|
|
|
|
if (reply) {
|
|
|
|
auto 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;
|
|
|
|
}
|
|
|
|
accumulate_max(maxWidth, replyw);
|
|
|
|
}
|
|
|
|
if (entry) {
|
2018-01-14 16:02:25 +00:00
|
|
|
accumulate_max(maxWidth, entry->maxWidth());
|
|
|
|
minHeight += entry->minHeight();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (media) {
|
|
|
|
media->initDimensions();
|
|
|
|
maxWidth = media->maxWidth();
|
|
|
|
minHeight = media->isDisplayed() ? media->minHeight() : 0;
|
|
|
|
} else {
|
|
|
|
maxWidth = st::msgMinWidth;
|
|
|
|
minHeight = 0;
|
|
|
|
}
|
|
|
|
if (const auto markup = item->inlineReplyMarkup()) {
|
|
|
|
if (!markup->inlineKeyboard) {
|
|
|
|
markup->inlineKeyboard = std::make_unique<ReplyKeyboard>(
|
|
|
|
item,
|
|
|
|
std::make_unique<KeyboardStyle>(st::msgBotKbButton));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we have a text bubble we can resize it to fit the keyboard
|
|
|
|
// but if we have only media we don't do that
|
2018-01-18 13:59:22 +00:00
|
|
|
if (hasVisibleText()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
accumulate_max(maxWidth, markup->inlineKeyboard->naturalWidth());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QSize(maxWidth, minHeight);
|
|
|
|
}
|
|
|
|
|
2018-02-16 17:59:35 +00:00
|
|
|
int Message::marginTop() const {
|
|
|
|
auto result = 0;
|
|
|
|
if (!isHidden()) {
|
|
|
|
if (isAttachedToPrevious()) {
|
|
|
|
result += st::msgMarginTopAttached;
|
|
|
|
} else {
|
|
|
|
result += st::msgMargin.top();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result += displayedDateHeight();
|
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
result += bar->height();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Message::marginBottom() const {
|
|
|
|
return isHidden() ? 0 : st::msgMargin.bottom();
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void Message::draw(
|
|
|
|
Painter &p,
|
|
|
|
QRect clip,
|
|
|
|
TextSelection selection,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time ms) const {
|
2018-01-30 13:17:50 +00:00
|
|
|
auto g = countGeometry();
|
|
|
|
if (g.width() < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto outbg = hasOutLayout();
|
|
|
|
const auto bubble = drawBubble();
|
|
|
|
const auto selected = (selection == FullSelection);
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto dateh = 0;
|
2018-01-23 11:47:38 +00:00
|
|
|
if (const auto date = Get<DateBadge>()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
dateh = date->height();
|
|
|
|
}
|
2018-01-21 19:21:08 +00:00
|
|
|
if (const auto bar = Get<UnreadBar>()) {
|
|
|
|
auto unreadbarh = bar->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (clip.intersects(QRect(0, dateh, width(), unreadbarh))) {
|
|
|
|
p.translate(0, dateh);
|
2018-01-21 19:21:08 +00:00
|
|
|
bar->paint(p, 0, width());
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(0, -dateh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:17:50 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-16 17:59:35 +00:00
|
|
|
paintHighlight(p, g.height());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2020-01-24 09:50:20 +00:00
|
|
|
const auto roll = media ? media->bubbleRoll() : Media::BubbleRoll();
|
2020-01-24 08:49:12 +00:00
|
|
|
if (roll) {
|
|
|
|
p.save();
|
|
|
|
p.translate(g.center());
|
|
|
|
p.rotate(roll.rotate);
|
|
|
|
p.scale(roll.scale, roll.scale);
|
|
|
|
p.translate(-g.center());
|
|
|
|
}
|
|
|
|
|
2018-02-16 17:59:35 +00:00
|
|
|
p.setTextPalette(selected
|
|
|
|
? (outbg ? st::outTextPaletteSelected : st::inTextPaletteSelected)
|
|
|
|
: (outbg ? st::outTextPalette : st::inTextPalette));
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto keyboard = item->inlineReplyKeyboard();
|
|
|
|
if (keyboard) {
|
|
|
|
auto keyboardHeight = st::msgBotKbButton.margin + keyboard->naturalHeight();
|
|
|
|
g.setHeight(g.height() - keyboardHeight);
|
|
|
|
auto keyboardPosition = QPoint(g.left(), g.top() + g.height() + st::msgBotKbButton.margin);
|
|
|
|
p.translate(keyboardPosition);
|
2019-04-02 09:13:30 +00:00
|
|
|
keyboard->paint(p, g.width(), clip.translated(-keyboardPosition));
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(-keyboardPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bubble) {
|
2019-03-15 15:15:56 +00:00
|
|
|
if (displayFromName()
|
|
|
|
&& item->displayFrom()
|
|
|
|
&& item->displayFrom()->nameVersion > item->_fromNameVersion) {
|
2018-01-13 12:45:11 +00:00
|
|
|
fromNameUpdated(g.width());
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entry = logEntryOriginal();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto mediaDisplayed = media && media->isDisplayed();
|
|
|
|
|
|
|
|
auto skipTail = isAttachedToNext()
|
|
|
|
|| (media && media->skipBubbleTail())
|
|
|
|
|| (keyboard != nullptr);
|
|
|
|
auto displayTail = skipTail ? RectPart::None : (outbg && !Adaptive::ChatWide()) ? RectPart::Right : RectPart::Left;
|
|
|
|
PaintBubble(p, g, width(), selected, outbg, displayTail);
|
|
|
|
|
|
|
|
// Entry page is always a bubble bottom.
|
2018-01-14 16:02:25 +00:00
|
|
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
|
|
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto trect = g.marginsRemoved(st::msgPadding);
|
|
|
|
if (mediaOnBottom) {
|
|
|
|
trect.setHeight(trect.height() + st::msgPadding.bottom());
|
|
|
|
}
|
|
|
|
if (mediaOnTop) {
|
|
|
|
trect.setY(trect.y() - st::msgPadding.top());
|
|
|
|
} else {
|
|
|
|
paintFromName(p, trect, selected);
|
|
|
|
paintForwardedInfo(p, trect, selected);
|
|
|
|
paintReplyInfo(p, trect, selected);
|
|
|
|
paintViaBotIdInfo(p, trect, selected);
|
|
|
|
}
|
|
|
|
if (entry) {
|
2018-01-14 16:02:25 +00:00
|
|
|
trect.setHeight(trect.height() - entry->height());
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
paintText(p, trect, selection);
|
2018-01-13 12:45:11 +00:00
|
|
|
if (mediaDisplayed) {
|
|
|
|
auto mediaHeight = media->height();
|
|
|
|
auto mediaLeft = g.left();
|
2018-01-27 13:59:24 +00:00
|
|
|
auto mediaTop = (trect.y() + trect.height() - mediaHeight);
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(mediaLeft, mediaTop);
|
2018-01-14 16:02:25 +00:00
|
|
|
media->draw(p, clip.translated(-mediaLeft, -mediaTop), skipTextSelection(selection), ms);
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(-mediaLeft, -mediaTop);
|
|
|
|
}
|
|
|
|
if (entry) {
|
|
|
|
auto entryLeft = g.left();
|
|
|
|
auto entryTop = trect.y() + trect.height();
|
|
|
|
p.translate(entryLeft, entryTop);
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entrySelection = skipTextSelection(selection);
|
2018-01-13 12:45:11 +00:00
|
|
|
if (mediaDisplayed) {
|
|
|
|
entrySelection = media->skipSelection(entrySelection);
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
entry->draw(p, clip.translated(-entryLeft, -entryTop), entrySelection, ms);
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(-entryLeft, -entryTop);
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
const auto needDrawInfo = entry
|
|
|
|
? !entry->customInfoLayout()
|
|
|
|
: (mediaDisplayed
|
|
|
|
? !media->customInfoLayout()
|
|
|
|
: true);
|
2018-01-13 12:45:11 +00:00
|
|
|
if (needDrawInfo) {
|
2018-01-27 13:59:24 +00:00
|
|
|
drawInfo(p, g.left() + g.width(), g.top() + g.height(), 2 * g.left() + g.width(), selected, InfoDisplayType::Default);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayRightAction()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto fastShareSkip = snap(
|
|
|
|
(g.height() - st::historyFastShareSize) / 2,
|
|
|
|
0,
|
|
|
|
st::historyFastShareBottom);
|
|
|
|
const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
|
|
|
|
const auto fastShareTop = g.top() + g.height() - fastShareSkip - st::historyFastShareSize;
|
2018-01-14 16:02:25 +00:00
|
|
|
drawRightAction(p, fastShareLeft, fastShareTop, width());
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2020-01-24 12:47:45 +00:00
|
|
|
|
|
|
|
if (media) {
|
|
|
|
media->paintBubbleFireworks(p, g, ms);
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
} else if (media && media->isDisplayed()) {
|
|
|
|
p.translate(g.topLeft());
|
2018-01-14 16:02:25 +00:00
|
|
|
media->draw(p, clip.translated(-g.topLeft()), skipTextSelection(selection), ms);
|
2018-01-13 12:45:11 +00:00
|
|
|
p.translate(-g.topLeft());
|
|
|
|
}
|
|
|
|
|
|
|
|
p.restoreTextPalette();
|
|
|
|
|
2020-01-24 08:49:12 +00:00
|
|
|
if (roll) {
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto reply = item->Get<HistoryMessageReply>();
|
|
|
|
if (reply && reply->isNameUpdated()) {
|
|
|
|
const_cast<Message*>(this)->setPendingResize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::paintFromName(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
bool selected) const {
|
|
|
|
const auto item = message();
|
|
|
|
if (displayFromName()) {
|
|
|
|
const auto badgeWidth = [&] {
|
2019-05-24 12:13:16 +00:00
|
|
|
if (item->hasMessageBadge()) {
|
2019-07-19 15:05:48 +00:00
|
|
|
return item->messageBadge().maxWidth();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}();
|
|
|
|
const auto replyWidth = [&] {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (isUnderCursor() && displayFastReply()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
return st::msgFont->width(FastReplyText());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}();
|
|
|
|
const auto rightWidth = replyWidth ? replyWidth : badgeWidth;
|
|
|
|
auto availableLeft = trect.left();
|
|
|
|
auto availableWidth = trect.width();
|
|
|
|
if (rightWidth) {
|
|
|
|
availableWidth -= st::msgPadding.right() + rightWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setFont(st::msgNameFont);
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto nameText = [&]() -> const Ui::Text::String * {
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto from = item->displayFrom();
|
|
|
|
if (item->isPost()) {
|
|
|
|
p.setPen(selected ? st::msgInServiceFgSelected : st::msgInServiceFg);
|
2019-06-12 10:45:06 +00:00
|
|
|
return &from->nameText();
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (from) {
|
|
|
|
p.setPen(FromNameFg(from->id, selected));
|
2019-06-12 10:45:06 +00:00
|
|
|
return &from->nameText();
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (const auto info = item->hiddenForwardedInfo()) {
|
|
|
|
p.setPen(FromNameFg(info->colorPeerId, selected));
|
|
|
|
return &info->nameText;
|
|
|
|
} else {
|
|
|
|
Unexpected("Corrupt forwarded information in message.");
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
nameText->drawElided(p, availableLeft, trect.top(), availableWidth);
|
|
|
|
const auto skipWidth = nameText->maxWidth() + st::msgServiceFont->spacew;
|
2018-01-13 12:45:11 +00:00
|
|
|
availableLeft += skipWidth;
|
|
|
|
availableWidth -= skipWidth;
|
|
|
|
|
|
|
|
auto via = item->Get<HistoryMessageVia>();
|
2018-02-03 20:25:34 +00:00
|
|
|
if (via && !displayForwardedFrom() && availableWidth > 0) {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto outbg = hasOutLayout();
|
2018-01-13 12:45:11 +00:00
|
|
|
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
|
|
|
|
p.drawText(availableLeft, trect.top() + st::msgServiceFont->ascent, via->text);
|
|
|
|
auto skipWidth = via->width + st::msgServiceFont->spacew;
|
|
|
|
availableLeft += skipWidth;
|
|
|
|
availableWidth -= skipWidth;
|
|
|
|
}
|
|
|
|
if (rightWidth) {
|
|
|
|
p.setPen(selected ? st::msgInDateFgSelected : st::msgInDateFg);
|
2018-01-14 16:02:25 +00:00
|
|
|
p.setFont(ClickHandler::showAsActive(_fastReplyLink)
|
2018-01-13 12:45:11 +00:00
|
|
|
? st::msgFont->underline()
|
|
|
|
: st::msgFont);
|
2019-07-19 15:05:48 +00:00
|
|
|
if (replyWidth) {
|
|
|
|
p.drawText(
|
|
|
|
trect.left() + trect.width() - rightWidth,
|
|
|
|
trect.top() + st::msgFont->ascent,
|
|
|
|
FastReplyText());
|
|
|
|
} else {
|
|
|
|
item->messageBadge().draw(
|
|
|
|
p,
|
|
|
|
trect.left() + trect.width() - rightWidth,
|
|
|
|
trect.top(),
|
|
|
|
rightWidth);
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
trect.setY(trect.y() + st::msgNameFont->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayForwardedFrom()) {
|
2019-03-19 13:50:36 +00:00
|
|
|
const auto &serviceFont = st::msgServiceFont;
|
|
|
|
const auto &serviceName = st::msgServiceNameFont;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto item = message();
|
|
|
|
const auto outbg = hasOutLayout();
|
2018-01-13 12:45:11 +00:00
|
|
|
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
|
|
|
|
p.setFont(serviceFont);
|
|
|
|
|
|
|
|
auto forwarded = item->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));
|
|
|
|
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() + (((forwarded->text.maxWidth() > trect.width()) ? 2 : 1) * serviceFont->height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::paintReplyInfo(Painter &p, QRect &trect, bool selected) const {
|
|
|
|
const auto item = message();
|
|
|
|
if (auto reply = item->Get<HistoryMessageReply>()) {
|
|
|
|
int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
|
|
|
|
|
|
|
auto flags = HistoryMessageReply::PaintFlag::InBubble | 0;
|
|
|
|
if (selected) {
|
|
|
|
flags |= HistoryMessageReply::PaintFlag::Selected;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
reply->paint(p, this, trect.x(), trect.y(), trect.width(), flags);
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
trect.setY(trect.y() + h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::paintViaBotIdInfo(Painter &p, QRect &trect, bool selected) const {
|
|
|
|
const auto item = message();
|
2018-02-03 20:25:34 +00:00
|
|
|
if (!displayFromName() && !displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (auto via = item->Get<HistoryMessageVia>()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto outbg = hasOutLayout();
|
2018-01-13 12:45:11 +00:00
|
|
|
p.setFont(st::msgServiceNameFont);
|
2018-01-14 16:02:25 +00:00
|
|
|
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
|
2018-01-13 12:45:11 +00:00
|
|
|
p.drawTextLeft(trect.left(), trect.top(), width(), via->text);
|
|
|
|
trect.setY(trect.y() + st::msgServiceNameFont->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::paintText(Painter &p, QRect &trect, TextSelection selection) const {
|
2018-01-19 12:13:06 +00:00
|
|
|
if (!hasVisibleText()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto outbg = hasOutLayout();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto selected = (selection == FullSelection);
|
|
|
|
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
|
|
|
|
p.setFont(st::msgFont);
|
|
|
|
item->_text.draw(p, trect.x(), trect.y(), trect.width(), style::al_left, 0, -1, selection);
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
PointState Message::pointState(QPoint point) const {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto g = countGeometry();
|
2018-01-30 13:17:50 +00:00
|
|
|
if (g.width() < 1 || isHidden()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
return PointState::Outside;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (drawBubble()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
if (!g.contains(point)) {
|
|
|
|
return PointState::Outside;
|
|
|
|
}
|
|
|
|
if (const auto mediaDisplayed = media && media->isDisplayed()) {
|
|
|
|
// Hack for grouped media point state.
|
|
|
|
auto entry = logEntryOriginal();
|
|
|
|
|
|
|
|
// Entry page is always a bubble bottom.
|
|
|
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
|
|
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
|
|
|
|
|
|
|
auto trect = g.marginsRemoved(st::msgPadding);
|
|
|
|
if (mediaOnBottom) {
|
|
|
|
trect.setHeight(trect.height() + st::msgPadding.bottom());
|
|
|
|
}
|
|
|
|
//if (mediaOnTop) {
|
|
|
|
// trect.setY(trect.y() - st::msgPadding.top());
|
|
|
|
//} else {
|
|
|
|
// if (getStateFromName(point, trect, &result)) return result;
|
|
|
|
// if (getStateForwardedInfo(point, trect, &result, request)) return result;
|
|
|
|
// if (getStateReplyInfo(point, trect, &result)) return result;
|
|
|
|
// if (getStateViaBotIdInfo(point, trect, &result)) return result;
|
|
|
|
//}
|
|
|
|
if (entry) {
|
|
|
|
auto entryHeight = entry->height();
|
|
|
|
trect.setHeight(trect.height() - entryHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto mediaHeight = media->height();
|
|
|
|
auto mediaLeft = trect.x() - st::msgPadding.left();
|
|
|
|
auto mediaTop = (trect.y() + trect.height() - mediaHeight);
|
|
|
|
|
|
|
|
if (point.y() >= mediaTop && point.y() < mediaTop + mediaHeight) {
|
|
|
|
return media->pointState(point - QPoint(mediaLeft, mediaTop));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PointState::Inside;
|
|
|
|
} else if (media) {
|
|
|
|
return media->pointState(point - g.topLeft());
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
return PointState::Outside;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayFromPhoto() const {
|
|
|
|
return hasFromPhoto() && !isAttachedToNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::hasFromPhoto() const {
|
2018-01-30 13:17:50 +00:00
|
|
|
if (isHidden()) {
|
2018-01-19 17:10:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
switch (context()) {
|
|
|
|
case Context::AdminLog:
|
2019-04-15 11:54:03 +00:00
|
|
|
//case Context::Feed: // #feed
|
2018-01-13 12:45:11 +00:00
|
|
|
return true;
|
|
|
|
case Context::History: {
|
|
|
|
const auto item = message();
|
|
|
|
if (item->isPost() || item->isEmpty()) {
|
|
|
|
return false;
|
|
|
|
} else if (Adaptive::ChatWide()) {
|
|
|
|
return true;
|
|
|
|
} else if (item->history()->peer->isSelf()) {
|
|
|
|
return item->Has<HistoryMessageForwarded>();
|
|
|
|
}
|
|
|
|
return !item->out() && !item->history()->peer->isUser();
|
|
|
|
} break;
|
2018-10-05 16:02:33 +00:00
|
|
|
case Context::ContactPreview:
|
|
|
|
return false;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
Unexpected("Context in Message::hasFromPhoto.");
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Message::textState(
|
2018-01-13 12:45:11 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
auto result = TextState(item);
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto g = countGeometry();
|
2018-01-30 13:17:50 +00:00
|
|
|
if (g.width() < 1 || isHidden()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto keyboard = item->inlineReplyKeyboard();
|
|
|
|
auto keyboardHeight = 0;
|
|
|
|
if (keyboard) {
|
|
|
|
keyboardHeight = keyboard->naturalHeight();
|
|
|
|
g.setHeight(g.height() - st::msgBotKbButton.margin - keyboardHeight);
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
if (drawBubble()) {
|
2018-02-18 13:22:58 +00:00
|
|
|
const auto inBubble = g.contains(point);
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entry = logEntryOriginal();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto mediaDisplayed = media && media->isDisplayed();
|
|
|
|
|
|
|
|
// Entry page is always a bubble bottom.
|
2018-01-14 16:02:25 +00:00
|
|
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
|
|
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto trect = g.marginsRemoved(st::msgPadding);
|
|
|
|
if (mediaOnBottom) {
|
|
|
|
trect.setHeight(trect.height() + st::msgPadding.bottom());
|
|
|
|
}
|
|
|
|
if (mediaOnTop) {
|
|
|
|
trect.setY(trect.y() - st::msgPadding.top());
|
2018-02-18 13:22:58 +00:00
|
|
|
} else if (inBubble) {
|
2018-02-03 20:25:34 +00:00
|
|
|
if (getStateFromName(point, trect, &result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (getStateForwardedInfo(point, trect, &result, request)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (getStateReplyInfo(point, trect, &result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (getStateViaBotIdInfo(point, trect, &result)) {
|
|
|
|
return result;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
if (entry) {
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entryHeight = entry->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
trect.setHeight(trect.height() - entryHeight);
|
|
|
|
auto entryLeft = g.left();
|
|
|
|
auto entryTop = trect.y() + trect.height();
|
|
|
|
if (point.y() >= entryTop && point.y() < entryTop + entryHeight) {
|
2018-01-27 13:59:24 +00:00
|
|
|
result = entry->textState(
|
2018-01-13 12:45:11 +00:00
|
|
|
point - QPoint(entryLeft, entryTop),
|
|
|
|
request);
|
|
|
|
result.symbol += item->_text.length() + (mediaDisplayed ? media->fullSelectionLength() : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 17:51:16 +00:00
|
|
|
auto checkForPointInTime = [&] {
|
|
|
|
if (mediaOnBottom && (entry || media->customInfoLayout())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto inDate = pointInTime(
|
|
|
|
g.left() + g.width(),
|
|
|
|
g.top() + g.height(),
|
|
|
|
point,
|
|
|
|
InfoDisplayType::Default);
|
|
|
|
if (inDate) {
|
|
|
|
result.cursor = CursorState::Date;
|
|
|
|
}
|
|
|
|
};
|
2018-02-18 13:22:58 +00:00
|
|
|
if (inBubble) {
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
auto mediaHeight = media->height();
|
|
|
|
auto mediaLeft = trect.x() - st::msgPadding.left();
|
|
|
|
auto mediaTop = (trect.y() + trect.height() - mediaHeight);
|
|
|
|
|
|
|
|
if (point.y() >= mediaTop && point.y() < mediaTop + mediaHeight) {
|
|
|
|
result = media->textState(point - QPoint(mediaLeft, mediaTop), request);
|
|
|
|
result.symbol += item->_text.length();
|
|
|
|
} else if (getStateText(point, trect, &result, request)) {
|
|
|
|
checkForPointInTime();
|
|
|
|
return result;
|
|
|
|
} else if (point.y() >= trect.y() + trect.height()) {
|
|
|
|
result.symbol = item->_text.length();
|
|
|
|
}
|
2018-01-27 17:51:16 +00:00
|
|
|
} else if (getStateText(point, trect, &result, request)) {
|
|
|
|
checkForPointInTime();
|
|
|
|
return result;
|
|
|
|
} else if (point.y() >= trect.y() + trect.height()) {
|
|
|
|
result.symbol = item->_text.length();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-27 17:51:16 +00:00
|
|
|
checkForPointInTime();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayRightAction()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto fastShareSkip = snap(
|
|
|
|
(g.height() - st::historyFastShareSize) / 2,
|
|
|
|
0,
|
|
|
|
st::historyFastShareBottom);
|
|
|
|
const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
|
|
|
|
const auto fastShareTop = g.top() + g.height() - fastShareSkip - st::historyFastShareSize;
|
|
|
|
if (QRect(
|
|
|
|
fastShareLeft,
|
|
|
|
fastShareTop,
|
|
|
|
st::historyFastShareSize,
|
|
|
|
st::historyFastShareSize
|
|
|
|
).contains(point)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result.link = rightActionLink();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (media && media->isDisplayed()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
result = media->textState(point - g.topLeft(), request);
|
2018-01-13 12:45:11 +00:00
|
|
|
result.symbol += item->_text.length();
|
|
|
|
}
|
|
|
|
|
2019-08-08 14:13:26 +00:00
|
|
|
if (keyboard && item->isHistoryEntry()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto keyboardTop = g.top() + g.height() + st::msgBotKbButton.margin;
|
|
|
|
if (QRect(g.left(), keyboardTop, g.width(), keyboardHeight).contains(point)) {
|
2018-01-27 13:59:24 +00:00
|
|
|
result.link = keyboard->getLink(point - QPoint(g.left(), keyboardTop));
|
2018-01-13 12:45:11 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::getStateFromName(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
|
|
|
if (displayFromName()) {
|
|
|
|
const auto replyWidth = [&] {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (isUnderCursor() && displayFastReply()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
return st::msgFont->width(FastReplyText());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}();
|
|
|
|
if (replyWidth
|
|
|
|
&& point.x() >= trect.left() + trect.width() - replyWidth
|
|
|
|
&& point.x() < trect.left() + trect.width() + st::msgPadding.right()
|
|
|
|
&& point.y() >= trect.top() - st::msgPadding.top()
|
|
|
|
&& point.y() < trect.top() + st::msgServiceFont->height) {
|
2018-01-14 16:02:25 +00:00
|
|
|
outResult->link = fastReplyLink();
|
2018-01-13 12:45:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (point.y() >= trect.top() && point.y() < trect.top() + st::msgNameFont->height) {
|
|
|
|
auto availableLeft = trect.left();
|
|
|
|
auto availableWidth = trect.width();
|
|
|
|
if (replyWidth) {
|
|
|
|
availableWidth -= st::msgPadding.right() + replyWidth;
|
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto from = item->displayFrom();
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto nameText = [&]() -> const Ui::Text::String * {
|
2019-03-15 15:15:56 +00:00
|
|
|
if (from) {
|
2019-06-12 10:45:06 +00:00
|
|
|
return &from->nameText();
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (const auto info = item->hiddenForwardedInfo()) {
|
|
|
|
return &info->nameText;
|
|
|
|
} else {
|
|
|
|
Unexpected("Corrupt forwarded information in message.");
|
|
|
|
}
|
|
|
|
}();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (point.x() >= availableLeft
|
|
|
|
&& point.x() < availableLeft + availableWidth
|
2019-03-15 15:15:56 +00:00
|
|
|
&& point.x() < availableLeft + nameText->maxWidth()) {
|
|
|
|
static const auto hidden = std::make_shared<LambdaClickHandler>([] {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_forwarded_hidden(tr::now));
|
2019-03-15 15:15:56 +00:00
|
|
|
});
|
|
|
|
outResult->link = from ? from->openLink() : hidden;
|
2018-01-13 12:45:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto via = item->Get<HistoryMessageVia>();
|
|
|
|
if (via
|
2018-02-03 20:25:34 +00:00
|
|
|
&& !displayForwardedFrom()
|
2019-03-15 15:15:56 +00:00
|
|
|
&& point.x() >= availableLeft + nameText->maxWidth() + st::msgServiceFont->spacew
|
2018-01-13 12:45:11 +00:00
|
|
|
&& point.x() < availableLeft + availableWidth
|
2019-03-15 15:15:56 +00:00
|
|
|
&& point.x() < availableLeft + nameText->maxWidth() + st::msgServiceFont->spacew + via->width) {
|
2018-01-13 12:45:11 +00:00
|
|
|
outResult->link = via->link;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trect.setTop(trect.top() + st::msgNameFont->height);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::getStateForwardedInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult,
|
|
|
|
StateRequest request) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayForwardedFrom()) {
|
|
|
|
const auto item = message();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto forwarded = item->Get<HistoryMessageForwarded>();
|
|
|
|
auto fwdheight = ((forwarded->text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
|
|
|
|
if (point.y() >= trect.top() && point.y() < trect.top() + fwdheight) {
|
|
|
|
auto breakEverywhere = (forwarded->text.countHeight(trect.width()) > 2 * st::semiboldFont->height);
|
|
|
|
auto textRequest = request.forText();
|
|
|
|
if (breakEverywhere) {
|
2019-06-12 13:26:04 +00:00
|
|
|
textRequest.flags |= Ui::Text::StateRequest::Flag::BreakEverywhere;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
*outResult = TextState(item, forwarded->text.getState(
|
2018-01-13 12:45:11 +00:00
|
|
|
point - trect.topLeft(),
|
|
|
|
trect.width(),
|
|
|
|
textRequest));
|
|
|
|
outResult->symbol = 0;
|
|
|
|
outResult->afterSymbol = false;
|
|
|
|
if (breakEverywhere) {
|
2018-01-27 13:59:24 +00:00
|
|
|
outResult->cursor = CursorState::Forwarded;
|
2018-01-13 12:45:11 +00:00
|
|
|
} else {
|
2018-01-27 13:59:24 +00:00
|
|
|
outResult->cursor = CursorState::None;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
trect.setTop(trect.top() + fwdheight);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::getStateReplyInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
|
|
|
if (auto reply = item->Get<HistoryMessageReply>()) {
|
|
|
|
int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
|
|
|
if (point.y() >= trect.top() && point.y() < trect.top() + h) {
|
|
|
|
if (reply->replyToMsg && QRect(trect.x(), trect.y() + st::msgReplyPadding.top(), trect.width(), st::msgReplyBarSize.height()).contains(point)) {
|
|
|
|
outResult->link = reply->replyToLink();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
trect.setTop(trect.top() + h);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::getStateViaBotIdInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const {
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
2018-02-03 20:25:34 +00:00
|
|
|
if (const auto via = item->Get<HistoryMessageVia>()) {
|
|
|
|
if (!displayFromName() && !displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (QRect(trect.x(), trect.y(), via->width, st::msgNameFont->height).contains(point)) {
|
|
|
|
outResult->link = via->link;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
trect.setTop(trect.top() + st::msgNameFont->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::getStateText(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult,
|
|
|
|
StateRequest request) const {
|
2018-01-19 12:13:06 +00:00
|
|
|
if (!hasVisibleText()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto item = message();
|
2018-01-27 17:51:16 +00:00
|
|
|
if (base::in_range(point.y(), trect.y(), trect.y() + trect.height())) {
|
2018-01-27 13:59:24 +00:00
|
|
|
*outResult = TextState(item, item->_text.getState(
|
2018-01-13 12:45:11 +00:00
|
|
|
point - trect.topLeft(),
|
|
|
|
trect.width(),
|
|
|
|
request.forText()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward to media.
|
|
|
|
void Message::updatePressed(QPoint point) {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (!media) return;
|
|
|
|
|
|
|
|
auto g = countGeometry();
|
|
|
|
auto keyboard = item->inlineReplyKeyboard();
|
|
|
|
if (keyboard) {
|
|
|
|
auto keyboardHeight = st::msgBotKbButton.margin + keyboard->naturalHeight();
|
|
|
|
g.setHeight(g.height() - keyboardHeight);
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
if (drawBubble()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto mediaDisplayed = media && media->isDisplayed();
|
|
|
|
auto top = marginTop();
|
|
|
|
auto trect = g.marginsAdded(-st::msgPadding);
|
|
|
|
if (mediaDisplayed && media->isBubbleTop()) {
|
|
|
|
trect.setY(trect.y() - st::msgPadding.top());
|
|
|
|
} else {
|
2018-02-03 20:25:34 +00:00
|
|
|
if (displayFromName()) {
|
|
|
|
trect.setTop(trect.top() + st::msgNameFont->height);
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto forwarded = item->Get<HistoryMessageForwarded>();
|
|
|
|
auto fwdheight = ((forwarded->text.maxWidth() > trect.width()) ? 2 : 1) * st::semiboldFont->height;
|
|
|
|
trect.setTop(trect.top() + fwdheight);
|
|
|
|
}
|
|
|
|
if (item->Get<HistoryMessageReply>()) {
|
|
|
|
auto h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
|
|
|
trect.setTop(trect.top() + h);
|
|
|
|
}
|
2018-02-03 20:25:34 +00:00
|
|
|
if (const auto via = item->Get<HistoryMessageVia>()) {
|
|
|
|
if (!displayFromName() && !displayForwardedFrom()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
trect.setTop(trect.top() + st::msgNameFont->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mediaDisplayed && media->isBubbleBottom()) {
|
|
|
|
trect.setHeight(trect.height() + st::msgPadding.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto needDateCheck = true;
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
auto mediaHeight = media->height();
|
|
|
|
auto mediaLeft = trect.x() - st::msgPadding.left();
|
2018-01-27 13:59:24 +00:00
|
|
|
auto mediaTop = (trect.y() + trect.height() - mediaHeight);
|
2018-01-13 12:45:11 +00:00
|
|
|
media->updatePressed(point - QPoint(mediaLeft, mediaTop));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
media->updatePressed(point - g.topLeft());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData Message::selectedText(TextSelection selection) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto item = message();
|
|
|
|
const auto media = this->media();
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
auto logEntryOriginalResult = TextForMimeData();
|
|
|
|
auto textResult = item->_text.toTextForMimeData(selection);
|
2018-01-14 16:02:25 +00:00
|
|
|
auto skipped = skipTextSelection(selection);
|
|
|
|
auto mediaDisplayed = (media && media->isDisplayed());
|
|
|
|
auto mediaResult = (mediaDisplayed || isHiddenByGroup())
|
|
|
|
? media->selectedText(skipped)
|
2019-04-08 15:10:06 +00:00
|
|
|
: TextForMimeData();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (auto entry = logEntryOriginal()) {
|
|
|
|
const auto originalSelection = mediaDisplayed
|
|
|
|
? media->skipSelection(skipped)
|
|
|
|
: skipped;
|
|
|
|
logEntryOriginalResult = entry->selectedText(originalSelection);
|
|
|
|
}
|
|
|
|
auto result = textResult;
|
2019-04-08 15:10:06 +00:00
|
|
|
if (result.empty()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result = std::move(mediaResult);
|
2019-04-08 15:10:06 +00:00
|
|
|
} else if (!mediaResult.empty()) {
|
|
|
|
result.append(qstr("\n\n")).append(std::move(mediaResult));
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2019-04-08 15:10:06 +00:00
|
|
|
if (result.empty()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result = std::move(logEntryOriginalResult);
|
2019-04-08 15:10:06 +00:00
|
|
|
} else if (!logEntryOriginalResult.empty()) {
|
|
|
|
result.append(qstr("\n\n")).append(std::move(logEntryOriginalResult));
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection Message::adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const {
|
|
|
|
const auto item = message();
|
|
|
|
const auto media = this->media();
|
|
|
|
|
|
|
|
auto result = item->_text.adjustSelection(selection, type);
|
|
|
|
auto beforeMediaLength = item->_text.length();
|
|
|
|
if (selection.to <= beforeMediaLength) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
auto mediaDisplayed = media && media->isDisplayed();
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
auto mediaSelection = unskipTextSelection(
|
|
|
|
media->adjustSelection(skipTextSelection(selection), type));
|
|
|
|
if (selection.from >= beforeMediaLength) {
|
|
|
|
result = mediaSelection;
|
|
|
|
} else {
|
|
|
|
result.to = mediaSelection.to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto beforeEntryLength = beforeMediaLength
|
|
|
|
+ (mediaDisplayed ? media->fullSelectionLength() : 0);
|
|
|
|
if (selection.to <= beforeEntryLength) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (const auto entry = logEntryOriginal()) {
|
|
|
|
auto entrySelection = mediaDisplayed
|
|
|
|
? media->skipSelection(skipTextSelection(selection))
|
|
|
|
: skipTextSelection(selection);
|
|
|
|
auto logEntryOriginalSelection = entry->adjustSelection(entrySelection, type);
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
logEntryOriginalSelection = media->unskipSelection(logEntryOriginalSelection);
|
|
|
|
}
|
|
|
|
logEntryOriginalSelection = unskipTextSelection(logEntryOriginalSelection);
|
|
|
|
if (selection.from >= beforeEntryLength) {
|
|
|
|
result = logEntryOriginalSelection;
|
|
|
|
} else {
|
|
|
|
result.to = logEntryOriginalSelection.to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::drawInfo(
|
|
|
|
Painter &p,
|
|
|
|
int right,
|
|
|
|
int bottom,
|
|
|
|
int width,
|
|
|
|
bool selected,
|
|
|
|
InfoDisplayType type) const {
|
|
|
|
p.setFont(st::msgDateFont);
|
|
|
|
|
|
|
|
bool outbg = hasOutLayout();
|
2018-01-27 13:59:24 +00:00
|
|
|
bool invertedsprites = (type == InfoDisplayType::Image)
|
|
|
|
|| (type == InfoDisplayType::Background);
|
2018-01-14 16:02:25 +00:00
|
|
|
int32 infoRight = right, infoBottom = bottom;
|
|
|
|
switch (type) {
|
2018-01-27 13:59:24 +00:00
|
|
|
case InfoDisplayType::Default:
|
2018-01-14 16:02:25 +00:00
|
|
|
infoRight -= st::msgPadding.right() - st::msgDateDelta.x();
|
|
|
|
infoBottom -= st::msgPadding.bottom() - st::msgDateDelta.y();
|
|
|
|
p.setPen(selected
|
|
|
|
? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected)
|
|
|
|
: (outbg ? st::msgOutDateFg : st::msgInDateFg));
|
|
|
|
break;
|
2018-01-27 13:59:24 +00:00
|
|
|
case InfoDisplayType::Image:
|
2018-01-14 16:02:25 +00:00
|
|
|
infoRight -= st::msgDateImgDelta + st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgDelta + st::msgDateImgPadding.y();
|
|
|
|
p.setPen(st::msgDateImgFg);
|
|
|
|
break;
|
2018-01-27 13:59:24 +00:00
|
|
|
case InfoDisplayType::Background:
|
2019-08-06 09:59:02 +00:00
|
|
|
infoRight -= st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgPadding.y();
|
2018-01-14 16:02:25 +00:00
|
|
|
p.setPen(st::msgServiceFg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto item = message();
|
|
|
|
auto infoW = infoWidth();
|
|
|
|
if (rtl()) infoRight = width - infoRight + infoW;
|
|
|
|
|
|
|
|
auto dateX = infoRight - infoW;
|
|
|
|
auto dateY = infoBottom - st::msgDateFont->height;
|
2018-01-27 13:59:24 +00:00
|
|
|
if (type == InfoDisplayType::Image) {
|
2018-01-14 16:02:25 +00:00
|
|
|
auto dateW = infoW + 2 * st::msgDateImgPadding.x(), dateH = st::msgDateFont->height + 2 * st::msgDateImgPadding.y();
|
|
|
|
App::roundRect(p, dateX - st::msgDateImgPadding.x(), dateY - st::msgDateImgPadding.y(), dateW, dateH, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners);
|
2018-01-27 13:59:24 +00:00
|
|
|
} else if (type == InfoDisplayType::Background) {
|
2018-01-14 16:02:25 +00:00
|
|
|
auto dateW = infoW + 2 * st::msgDateImgPadding.x(), dateH = st::msgDateFont->height + 2 * st::msgDateImgPadding.y();
|
|
|
|
App::roundRect(p, dateX - st::msgDateImgPadding.x(), dateY - st::msgDateImgPadding.y(), dateW, dateH, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
|
|
|
|
}
|
|
|
|
dateX += timeLeft();
|
|
|
|
|
|
|
|
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
|
|
|
|
msgsigned->signature.drawElided(p, dateX, dateY, item->_timeWidth);
|
|
|
|
} else if (const auto edited = displayedEditBadge()) {
|
|
|
|
edited->text.drawElided(p, dateX, dateY, item->_timeWidth);
|
|
|
|
} else {
|
|
|
|
p.drawText(dateX, dateY + st::msgDateFont->ascent, item->_timeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto views = item->Get<HistoryMessageViews>()) {
|
|
|
|
auto icon = [&] {
|
|
|
|
if (item->id > 0) {
|
|
|
|
if (outbg) {
|
|
|
|
return &(invertedsprites ? st::historyViewsInvertedIcon : (selected ? st::historyViewsOutSelectedIcon : st::historyViewsOutIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historyViewsInvertedIcon : (selected ? st::historyViewsInSelectedIcon : st::historyViewsInIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historyViewsSendingInvertedIcon : st::historyViewsSendingIcon);
|
|
|
|
}();
|
|
|
|
if (item->id > 0) {
|
|
|
|
icon->paint(p, infoRight - infoW, infoBottom + st::historyViewsTop, width);
|
|
|
|
p.drawText(infoRight - infoW + st::historyViewsWidth, infoBottom - st::msgDateFont->descent, views->_viewsText);
|
|
|
|
} else if (!outbg) { // sending outbg icon will be painted below
|
|
|
|
auto iconSkip = st::historyViewsSpace + views->_viewsWidth;
|
|
|
|
icon->paint(p, infoRight - infoW + iconSkip, infoBottom + st::historyViewsTop, width);
|
|
|
|
}
|
|
|
|
} else if (item->id < 0 && item->history()->peer->isSelf() && !outbg) {
|
|
|
|
auto icon = &(invertedsprites ? st::historyViewsSendingInvertedIcon : st::historyViewsSendingIcon);
|
|
|
|
icon->paint(p, infoRight - infoW, infoBottom + st::historyViewsTop, width);
|
|
|
|
}
|
|
|
|
if (outbg) {
|
|
|
|
auto icon = [&] {
|
|
|
|
if (item->id > 0) {
|
|
|
|
if (item->unread()) {
|
|
|
|
return &(invertedsprites ? st::historySentInvertedIcon : (selected ? st::historySentSelectedIcon : st::historySentIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historyReceivedInvertedIcon : (selected ? st::historyReceivedSelectedIcon : st::historyReceivedIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historySendingInvertedIcon : st::historySendingIcon);
|
|
|
|
}();
|
|
|
|
icon->paint(p, QPoint(infoRight, infoBottom) + st::historySendStatePosition, width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::pointInTime(
|
|
|
|
int right,
|
|
|
|
int bottom,
|
|
|
|
QPoint point,
|
|
|
|
InfoDisplayType type) const {
|
|
|
|
auto infoRight = right;
|
|
|
|
auto infoBottom = bottom;
|
|
|
|
switch (type) {
|
2018-01-27 13:59:24 +00:00
|
|
|
case InfoDisplayType::Default:
|
2018-01-14 16:02:25 +00:00
|
|
|
infoRight -= st::msgPadding.right() - st::msgDateDelta.x();
|
|
|
|
infoBottom -= st::msgPadding.bottom() - st::msgDateDelta.y();
|
|
|
|
break;
|
2018-01-27 13:59:24 +00:00
|
|
|
case InfoDisplayType::Image:
|
2018-01-14 16:02:25 +00:00
|
|
|
infoRight -= st::msgDateImgDelta + st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgDelta + st::msgDateImgPadding.y();
|
|
|
|
break;
|
2019-08-06 09:59:02 +00:00
|
|
|
case InfoDisplayType::Background:
|
|
|
|
infoRight -= st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgPadding.y();
|
|
|
|
break;
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
const auto item = message();
|
|
|
|
auto dateX = infoRight - infoWidth() + timeLeft();
|
|
|
|
auto dateY = infoBottom - st::msgDateFont->height;
|
|
|
|
return QRect(
|
|
|
|
dateX,
|
|
|
|
dateY,
|
|
|
|
item->_timeWidth,
|
|
|
|
st::msgDateFont->height).contains(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Message::infoWidth() const {
|
|
|
|
const auto item = message();
|
|
|
|
auto result = item->_timeWidth;
|
|
|
|
if (auto views = item->Get<HistoryMessageViews>()) {
|
|
|
|
result += st::historyViewsSpace
|
|
|
|
+ views->_viewsWidth
|
|
|
|
+ st::historyViewsWidth;
|
|
|
|
} else if (item->id < 0 && item->history()->peer->isSelf()) {
|
|
|
|
if (!hasOutLayout()) {
|
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
|
|
|
}
|
2020-01-14 22:23:16 +00:00
|
|
|
|
|
|
|
// When message is scheduled until online, time is not displayed,
|
|
|
|
// so message should have less space.
|
|
|
|
if (!item->_timeWidth) {
|
|
|
|
result += st::historyScheduledUntilOnlineStateSpace;
|
|
|
|
} else if (hasOutLayout()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-01-24 09:50:20 +00:00
|
|
|
auto Message::verticalRepaintRange() const -> VerticalRepaintRange {
|
|
|
|
const auto media = this->media();
|
|
|
|
const auto add = media ? media->bubbleRollRepaintMargins() : QMargins();
|
|
|
|
return {
|
|
|
|
.top = -add.top(),
|
|
|
|
.height = height() + add.top() + add.bottom()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-28 15:20:05 +00:00
|
|
|
void Message::refreshDataIdHook() {
|
|
|
|
if (base::take(_rightActionLink)) {
|
|
|
|
_rightActionLink = rightActionLink();
|
|
|
|
}
|
|
|
|
if (base::take(_fastReplyLink)) {
|
|
|
|
_fastReplyLink = fastReplyLink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
int Message::timeLeft() const {
|
|
|
|
const auto item = message();
|
|
|
|
auto result = 0;
|
|
|
|
if (auto views = item->Get<HistoryMessageViews>()) {
|
|
|
|
result += st::historyViewsSpace + views->_viewsWidth + st::historyViewsWidth;
|
|
|
|
} else if (item->id < 0 && item->history()->peer->isSelf()) {
|
|
|
|
if (!hasOutLayout()) {
|
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-19 12:13:06 +00:00
|
|
|
int Message::plainMaxWidth() const {
|
|
|
|
return st::msgPadding.left()
|
|
|
|
+ (hasVisibleText() ? message()->_text.maxWidth() : 0)
|
|
|
|
+ st::msgPadding.right();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void Message::initLogEntryOriginal() {
|
|
|
|
if (const auto log = message()->Get<HistoryMessageLogEntryOriginal>()) {
|
|
|
|
AddComponents(LogEntryOriginal::Bit());
|
|
|
|
const auto entry = Get<LogEntryOriginal>();
|
2019-08-02 13:21:09 +00:00
|
|
|
entry->page = std::make_unique<WebPage>(this, log->page);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
WebPage *Message::logEntryOriginal() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto entry = Get<LogEntryOriginal>()) {
|
|
|
|
return entry->page.get();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
bool Message::hasFromName() const {
|
|
|
|
switch (context()) {
|
|
|
|
case Context::AdminLog:
|
2019-04-15 11:54:03 +00:00
|
|
|
//case Context::Feed: // #feed
|
2018-01-13 12:45:11 +00:00
|
|
|
return true;
|
|
|
|
case Context::History: {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
return !hasOutLayout()
|
2018-01-13 12:45:11 +00:00
|
|
|
&& (!item->history()->peer->isUser()
|
|
|
|
|| item->history()->peer->isSelf());
|
|
|
|
} break;
|
2018-10-05 16:02:33 +00:00
|
|
|
case Context::ContactPreview:
|
|
|
|
return false;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
Unexpected("Context in Message::hasFromPhoto.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayFromName() const {
|
|
|
|
if (!hasFromName()) return false;
|
|
|
|
if (isAttachedToPrevious()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool Message::displayForwardedFrom() const {
|
|
|
|
const auto item = message();
|
2019-05-25 14:09:48 +00:00
|
|
|
if (item->history()->peer->isSelf()) {
|
2019-05-24 07:55:16 +00:00
|
|
|
return false;
|
2019-05-25 14:09:48 +00:00
|
|
|
}
|
|
|
|
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
|
|
|
if (const auto sender = item->discussionPostOriginalSender()) {
|
|
|
|
if (sender == forwarded->originalSender) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
|
|
|
return item->Has<HistoryMessageVia>()
|
|
|
|
|| !media
|
|
|
|
|| !media->isDisplayed()
|
|
|
|
|| !media->hideForwardedFrom()
|
2019-03-15 15:15:56 +00:00
|
|
|
|| (forwarded->originalSender
|
|
|
|
&& forwarded->originalSender->isChannel());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::hasOutLayout() const {
|
|
|
|
const auto item = message();
|
|
|
|
if (item->history()->peer->isSelf()) {
|
|
|
|
return !item->Has<HistoryMessageForwarded>();
|
|
|
|
}
|
|
|
|
return item->out() && !item->isPost();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::drawBubble() const {
|
|
|
|
const auto item = message();
|
2018-01-30 13:17:50 +00:00
|
|
|
if (isHidden()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return false;
|
|
|
|
} else if (logEntryOriginal()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto media = this->media();
|
|
|
|
return media
|
2018-01-18 13:59:22 +00:00
|
|
|
? (hasVisibleText() || media->needsBubble())
|
2018-01-14 16:02:25 +00:00
|
|
|
: !item->isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::hasBubble() const {
|
|
|
|
return drawBubble();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::hasFastReply() const {
|
2018-01-22 16:42:25 +00:00
|
|
|
if (context() != Context::History) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto peer = data()->history()->peer;
|
|
|
|
return !hasOutLayout() && (peer->isChat() || peer->isMegagroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayFastReply() const {
|
2018-03-08 21:21:27 +00:00
|
|
|
return hasFastReply()
|
2018-06-28 15:20:05 +00:00
|
|
|
&& IsServerMsgId(data()->id)
|
2018-03-08 21:21:27 +00:00
|
|
|
&& data()->history()->peer->canWrite()
|
|
|
|
&& !delegate()->elementInSelectionMode();
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayRightAction() const {
|
|
|
|
return displayFastShare() || displayGoToOriginal();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayFastShare() const {
|
|
|
|
const auto item = message();
|
|
|
|
const auto peer = item->history()->peer;
|
2018-06-28 15:20:05 +00:00
|
|
|
if (!IsServerMsgId(item->id)) {
|
|
|
|
return false;
|
|
|
|
} else if (peer->isChannel()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return !peer->isMegagroup();
|
|
|
|
} else if (const auto user = peer->asUser()) {
|
2018-05-29 22:18:10 +00:00
|
|
|
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
|
|
|
return !peer->isSelf()
|
2019-03-07 09:02:55 +00:00
|
|
|
&& !item->out()
|
2019-03-15 15:15:56 +00:00
|
|
|
&& forwarded->originalSender
|
2018-05-29 22:18:10 +00:00
|
|
|
&& forwarded->originalSender->isChannel()
|
|
|
|
&& !forwarded->originalSender->isMegagroup();
|
2019-07-18 08:51:11 +00:00
|
|
|
} else if (user->isBot() && !item->out()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = this->media()) {
|
|
|
|
return media->allowsFastShare();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayGoToOriginal() const {
|
|
|
|
const auto item = message();
|
2019-05-24 07:55:16 +00:00
|
|
|
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->savedFromPeer && forwarded->savedFromMsgId;
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::drawRightAction(
|
|
|
|
Painter &p,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int outerWidth) const {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::msgServiceBg);
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2019-09-13 12:22:54 +00:00
|
|
|
p.drawEllipse(style::rtlrect(
|
2018-01-14 16:02:25 +00:00
|
|
|
left,
|
|
|
|
top,
|
|
|
|
st::historyFastShareSize,
|
|
|
|
st::historyFastShareSize,
|
|
|
|
outerWidth));
|
|
|
|
}
|
|
|
|
if (displayFastShare()) {
|
|
|
|
st::historyFastShareIcon.paint(p, left, top, outerWidth);
|
|
|
|
} else {
|
|
|
|
st::historyGoToOriginalIcon.paint(p, left, top, outerWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickHandlerPtr Message::rightActionLink() const {
|
|
|
|
if (!_rightActionLink) {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &data()->history()->owner();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto itemId = data()->fullId();
|
|
|
|
const auto forwarded = data()->Get<HistoryMessageForwarded>();
|
|
|
|
const auto savedFromPeer = forwarded ? forwarded->savedFromPeer : nullptr;
|
|
|
|
const auto savedFromMsgId = forwarded ? forwarded->savedFromMsgId : 0;
|
|
|
|
_rightActionLink = std::make_shared<LambdaClickHandler>([=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (savedFromPeer && savedFromMsgId) {
|
2019-06-06 10:21:40 +00:00
|
|
|
App::wnd()->sessionController()->showPeerHistory(
|
2018-01-14 16:02:25 +00:00
|
|
|
savedFromPeer,
|
|
|
|
Window::SectionShow::Way::Forward,
|
|
|
|
savedFromMsgId);
|
|
|
|
} else {
|
|
|
|
FastShareMessage(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return _rightActionLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickHandlerPtr Message::fastReplyLink() const {
|
|
|
|
if (!_fastReplyLink) {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &data()->history()->owner();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto itemId = data()->fullId();
|
|
|
|
_fastReplyLink = std::make_shared<LambdaClickHandler>([=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto main = App::main()) {
|
|
|
|
main->replyToItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return _fastReplyLink;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void Message::updateMediaInBubbleState() {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto media = this->media();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
auto mediaHasSomethingBelow = false;
|
|
|
|
auto mediaHasSomethingAbove = false;
|
|
|
|
auto getMediaHasSomethingAbove = [&] {
|
|
|
|
return displayFromName()
|
2018-01-14 16:02:25 +00:00
|
|
|
|| displayForwardedFrom()
|
2018-01-13 12:45:11 +00:00
|
|
|
|| item->Has<HistoryMessageReply>()
|
|
|
|
|| item->Has<HistoryMessageVia>();
|
|
|
|
};
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entry = logEntryOriginal();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (entry) {
|
|
|
|
mediaHasSomethingBelow = true;
|
|
|
|
mediaHasSomethingAbove = getMediaHasSomethingAbove();
|
|
|
|
auto entryState = (mediaHasSomethingAbove
|
2018-01-18 13:59:22 +00:00
|
|
|
|| hasVisibleText()
|
2018-01-13 12:45:11 +00:00
|
|
|
|| (media && media->isDisplayed()))
|
|
|
|
? MediaInBubbleState::Bottom
|
|
|
|
: MediaInBubbleState::None;
|
2018-01-14 16:02:25 +00:00
|
|
|
entry->setInBubbleState(entryState);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
if (!media) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
media->updateNeedBubbleState();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (!drawBubble()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
media->setInBubbleState(MediaInBubbleState::None);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry) {
|
|
|
|
mediaHasSomethingAbove = getMediaHasSomethingAbove();
|
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
if (hasVisibleText()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
mediaHasSomethingAbove = true;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
const auto state = [&] {
|
|
|
|
if (mediaHasSomethingAbove) {
|
|
|
|
if (mediaHasSomethingBelow) {
|
|
|
|
return MediaInBubbleState::Middle;
|
|
|
|
}
|
|
|
|
return MediaInBubbleState::Bottom;
|
|
|
|
} else if (mediaHasSomethingBelow) {
|
|
|
|
return MediaInBubbleState::Top;
|
|
|
|
}
|
|
|
|
return MediaInBubbleState::None;
|
|
|
|
}();
|
|
|
|
media->setInBubbleState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::fromNameUpdated(int width) const {
|
|
|
|
const auto item = message();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto replyWidth = hasFastReply()
|
2018-01-13 12:45:11 +00:00
|
|
|
? st::msgFont->width(FastReplyText())
|
|
|
|
: 0;
|
2019-05-24 12:13:16 +00:00
|
|
|
if (item->hasMessageBadge()) {
|
2019-07-19 15:05:48 +00:00
|
|
|
const auto badgeWidth = item->messageBadge().maxWidth();
|
2018-01-13 12:45:11 +00:00
|
|
|
width -= st::msgPadding.right() + std::max(badgeWidth, replyWidth);
|
|
|
|
} else if (replyWidth) {
|
|
|
|
width -= st::msgPadding.right() + replyWidth;
|
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto from = item->displayFrom();
|
|
|
|
item->_fromNameVersion = from ? from->nameVersion : 1;
|
2018-02-03 20:25:34 +00:00
|
|
|
if (const auto via = item->Get<HistoryMessageVia>()) {
|
|
|
|
if (!displayForwardedFrom()) {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto nameText = [&]() -> const Ui::Text::String * {
|
2019-03-15 15:15:56 +00:00
|
|
|
if (from) {
|
2019-06-12 10:45:06 +00:00
|
|
|
return &from->nameText();
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (const auto info = item->hiddenForwardedInfo()) {
|
|
|
|
return &info->nameText;
|
|
|
|
} else {
|
|
|
|
Unexpected("Corrupted forwarded information in message.");
|
|
|
|
}
|
|
|
|
}();
|
2018-01-13 12:45:11 +00:00
|
|
|
via->resize(width
|
|
|
|
- st::msgPadding.left()
|
|
|
|
- st::msgPadding.right()
|
2019-03-15 15:15:56 +00:00
|
|
|
- nameText->maxWidth()
|
2018-01-13 12:45:11 +00:00
|
|
|
- st::msgServiceFont->spacew);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
TextSelection Message::skipTextSelection(TextSelection selection) const {
|
|
|
|
return HistoryView::UnshiftItemSelection(selection, message()->_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection Message::unskipTextSelection(TextSelection selection) const {
|
|
|
|
return HistoryView::ShiftItemSelection(selection, message()->_text);
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
QRect Message::countGeometry() const {
|
|
|
|
const auto item = message();
|
2018-01-22 16:42:25 +00:00
|
|
|
const auto media = this->media();
|
2018-03-09 13:10:22 +00:00
|
|
|
const auto mediaWidth = (media && media->isDisplayed())
|
|
|
|
? media->width()
|
|
|
|
: width();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto outbg = hasOutLayout();
|
2018-01-22 16:42:25 +00:00
|
|
|
const auto availableWidth = width()
|
|
|
|
- st::msgMargin.left()
|
|
|
|
- st::msgMargin.right();
|
2018-01-14 16:02:25 +00:00
|
|
|
auto contentLeft = (outbg && !Adaptive::ChatWide())
|
2018-01-13 12:45:11 +00:00
|
|
|
? st::msgMargin.right()
|
|
|
|
: st::msgMargin.left();
|
2018-01-22 16:42:25 +00:00
|
|
|
auto contentWidth = availableWidth;
|
2018-01-13 12:45:11 +00:00
|
|
|
if (hasFromPhoto()) {
|
|
|
|
contentLeft += st::msgPhotoSkip;
|
2018-01-22 16:42:25 +00:00
|
|
|
if (displayRightAction()) {
|
|
|
|
contentWidth -= st::msgPhotoSkip;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
//} else if (!Adaptive::Wide() && !out() && !fromChannel() && st::msgPhotoSkip - (hmaxwidth - hwidth) > 0) {
|
|
|
|
// contentLeft += st::msgPhotoSkip - (hmaxwidth - hwidth);
|
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
accumulate_min(contentWidth, maxWidth());
|
|
|
|
accumulate_min(contentWidth, st::msgMaxWidth);
|
|
|
|
if (mediaWidth < contentWidth) {
|
|
|
|
const auto textualWidth = plainMaxWidth();
|
2019-01-29 16:26:19 +00:00
|
|
|
if (mediaWidth < textualWidth
|
|
|
|
&& (!media || !media->enforceBubbleWidth())) {
|
2018-01-19 17:10:58 +00:00
|
|
|
accumulate_min(contentWidth, textualWidth);
|
|
|
|
} else {
|
|
|
|
contentWidth = mediaWidth;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
}
|
|
|
|
if (contentWidth < availableWidth && outbg && !Adaptive::ChatWide()) {
|
|
|
|
contentLeft += availableWidth - contentWidth;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto contentTop = marginTop();
|
|
|
|
return QRect(
|
|
|
|
contentLeft,
|
|
|
|
contentTop,
|
|
|
|
contentWidth,
|
|
|
|
height() - contentTop - marginBottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
int Message::resizeContentGetHeight(int newWidth) {
|
2018-01-30 13:17:50 +00:00
|
|
|
if (isHidden()) {
|
2018-01-29 18:06:58 +00:00
|
|
|
return marginTop() + marginBottom();
|
2018-01-19 17:10:58 +00:00
|
|
|
} else if (newWidth < st::msgMinWidth) {
|
2018-01-13 12:45:11 +00:00
|
|
|
return height();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newHeight = minHeight();
|
2018-01-19 17:10:58 +00:00
|
|
|
|
|
|
|
const auto item = message();
|
|
|
|
const auto media = this->media();
|
|
|
|
const auto mediaDisplayed = media ? media->isDisplayed() : false;
|
|
|
|
const auto bubble = drawBubble();
|
|
|
|
|
|
|
|
// This code duplicates countGeometry() but also resizes media.
|
2018-01-13 12:45:11 +00:00
|
|
|
auto contentWidth = newWidth - (st::msgMargin.left() + st::msgMargin.right());
|
2018-01-22 16:42:25 +00:00
|
|
|
if (hasFromPhoto() && displayRightAction()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
contentWidth -= st::msgPhotoSkip;
|
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
accumulate_min(contentWidth, maxWidth());
|
|
|
|
accumulate_min(contentWidth, st::msgMaxWidth);
|
|
|
|
if (mediaDisplayed) {
|
2018-01-21 09:05:30 +00:00
|
|
|
media->resizeGetHeight(contentWidth);
|
2018-01-19 17:10:58 +00:00
|
|
|
if (media->width() < contentWidth) {
|
|
|
|
const auto textualWidth = plainMaxWidth();
|
2019-01-29 16:26:19 +00:00
|
|
|
if (media->width() < textualWidth
|
|
|
|
&& !media->enforceBubbleWidth()) {
|
2018-01-19 17:10:58 +00:00
|
|
|
accumulate_min(contentWidth, textualWidth);
|
|
|
|
} else {
|
|
|
|
contentWidth = media->width();
|
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
2018-01-19 17:10:58 +00:00
|
|
|
|
|
|
|
if (bubble) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto reply = item->Get<HistoryMessageReply>();
|
|
|
|
auto via = item->Get<HistoryMessageVia>();
|
2018-01-14 16:02:25 +00:00
|
|
|
auto entry = logEntryOriginal();
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
// Entry page is always a bubble bottom.
|
2018-01-14 16:02:25 +00:00
|
|
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
|
|
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-19 17:10:58 +00:00
|
|
|
if (contentWidth == maxWidth()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (mediaDisplayed) {
|
|
|
|
if (entry) {
|
2018-01-19 17:10:58 +00:00
|
|
|
newHeight += entry->resizeGetHeight(contentWidth);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
} else if (entry) {
|
|
|
|
// In case of text-only message it is counted in minHeight already.
|
2018-01-19 17:10:58 +00:00
|
|
|
entry->resizeGetHeight(contentWidth);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-18 13:59:22 +00:00
|
|
|
if (hasVisibleText()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto textWidth = qMax(contentWidth - st::msgPadding.left() - st::msgPadding.right(), 1);
|
|
|
|
if (textWidth != item->_textWidth) {
|
|
|
|
item->_textWidth = textWidth;
|
|
|
|
item->_textHeight = item->_text.countHeight(textWidth);
|
|
|
|
}
|
|
|
|
newHeight = item->_textHeight;
|
2018-01-18 13:59:22 +00:00
|
|
|
} else {
|
|
|
|
newHeight = 0;
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
if (!mediaOnBottom) {
|
|
|
|
newHeight += st::msgPadding.bottom();
|
|
|
|
if (mediaDisplayed) newHeight += st::mediaInBubbleSkip;
|
|
|
|
}
|
|
|
|
if (!mediaOnTop) {
|
|
|
|
newHeight += st::msgPadding.top();
|
|
|
|
if (mediaDisplayed) newHeight += st::mediaInBubbleSkip;
|
|
|
|
if (entry) newHeight += st::mediaInBubbleSkip;
|
|
|
|
}
|
|
|
|
if (mediaDisplayed) {
|
2018-01-21 09:05:30 +00:00
|
|
|
newHeight += media->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
if (entry) {
|
2018-01-19 17:10:58 +00:00
|
|
|
newHeight += entry->resizeGetHeight(contentWidth);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
} else if (entry) {
|
2018-01-14 16:02:25 +00:00
|
|
|
newHeight += entry->resizeGetHeight(contentWidth);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayFromName()) {
|
2018-01-19 17:10:58 +00:00
|
|
|
fromNameUpdated(contentWidth);
|
2018-01-13 12:45:11 +00:00
|
|
|
newHeight += st::msgNameFont->height;
|
2018-02-03 20:25:34 +00:00
|
|
|
} else if (via && !displayForwardedFrom()) {
|
2018-01-19 17:10:58 +00:00
|
|
|
via->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
|
2018-01-13 12:45:11 +00:00
|
|
|
newHeight += st::msgNameFont->height;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
if (displayForwardedFrom()) {
|
2018-02-03 20:25:34 +00:00
|
|
|
auto forwarded = item->Get<HistoryMessageForwarded>();
|
2018-01-19 17:10:58 +00:00
|
|
|
auto fwdheight = ((forwarded->text.maxWidth() > (contentWidth - st::msgPadding.left() - st::msgPadding.right())) ? 2 : 1) * st::semiboldFont->height;
|
2018-01-13 12:45:11 +00:00
|
|
|
newHeight += fwdheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply) {
|
2018-01-19 17:10:58 +00:00
|
|
|
reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
|
2018-01-13 12:45:11 +00:00
|
|
|
newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
|
|
|
|
}
|
2018-01-21 09:05:30 +00:00
|
|
|
} else if (mediaDisplayed) {
|
|
|
|
newHeight = media->height();
|
2018-01-13 12:45:11 +00:00
|
|
|
} else {
|
|
|
|
newHeight = 0;
|
|
|
|
}
|
|
|
|
if (const auto keyboard = item->inlineReplyKeyboard()) {
|
|
|
|
const auto keyboardHeight = st::msgBotKbButton.margin + keyboard->naturalHeight();
|
|
|
|
newHeight += keyboardHeight;
|
2018-01-19 17:10:58 +00:00
|
|
|
keyboard->resize(contentWidth, keyboardHeight - st::msgBotKbButton.margin);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newHeight += marginTop() + marginBottom();
|
|
|
|
return newHeight;
|
|
|
|
}
|
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
bool Message::hasVisibleText() const {
|
|
|
|
if (message()->emptyText()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto media = this->media();
|
|
|
|
return !media || !media->hideMessageText();
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
QSize Message::performCountCurrentSize(int newWidth) {
|
|
|
|
const auto item = message();
|
|
|
|
const auto newHeight = resizeContentGetHeight(newWidth);
|
|
|
|
|
|
|
|
const auto keyboard = item->inlineReplyKeyboard();
|
|
|
|
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
const auto oldTop = markup->oldTop;
|
|
|
|
if (oldTop >= 0) {
|
|
|
|
markup->oldTop = -1;
|
|
|
|
if (keyboard) {
|
|
|
|
const auto height = st::msgBotKbButton.margin + keyboard->naturalHeight();
|
|
|
|
const auto keyboardTop = newHeight - height + st::msgBotKbButton.margin - marginBottom();
|
|
|
|
if (keyboardTop != oldTop) {
|
|
|
|
Notify::inlineKeyboardMoved(item, oldTop, keyboardTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { newWidth, newHeight };
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void Message::refreshEditedBadge() {
|
|
|
|
const auto item = message();
|
|
|
|
const auto edited = displayedEditBadge();
|
|
|
|
const auto editDate = displayedEditDate();
|
2018-02-03 19:52:35 +00:00
|
|
|
const auto dateText = dateTime().toString(cTimeFormat());
|
2018-01-14 16:02:25 +00:00
|
|
|
if (edited) {
|
2018-02-03 19:52:35 +00:00
|
|
|
edited->refresh(dateText, editDate != 0);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
|
2018-02-03 19:52:35 +00:00
|
|
|
const auto text = (!edited || !editDate)
|
2018-01-14 16:02:25 +00:00
|
|
|
? dateText
|
2019-04-08 11:53:08 +00:00
|
|
|
: edited->text.toString();
|
2018-01-14 16:02:25 +00:00
|
|
|
msgsigned->refresh(text);
|
|
|
|
}
|
|
|
|
initTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::initTime() {
|
|
|
|
const auto item = message();
|
|
|
|
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
|
|
|
|
item->_timeWidth = msgsigned->maxWidth();
|
|
|
|
} else if (const auto edited = displayedEditBadge()) {
|
|
|
|
item->_timeWidth = edited->maxWidth();
|
|
|
|
} else {
|
2018-02-03 19:52:35 +00:00
|
|
|
item->_timeText = dateTime().toString(cTimeFormat());
|
2018-01-14 16:02:25 +00:00
|
|
|
item->_timeWidth = st::msgDateFont->width(item->_timeText);
|
|
|
|
}
|
|
|
|
if (const auto views = item->Get<HistoryMessageViews>()) {
|
2019-05-03 14:59:42 +00:00
|
|
|
views->_viewsText = (views->_views > 0)
|
2019-05-20 12:06:34 +00:00
|
|
|
? Lang::FormatCountToShort(views->_views).string
|
2019-06-19 14:52:18 +00:00
|
|
|
: QString("1");
|
2018-01-14 16:02:25 +00:00
|
|
|
views->_viewsWidth = views->_viewsText.isEmpty()
|
|
|
|
? 0
|
|
|
|
: st::msgDateFont->width(views->_viewsText);
|
|
|
|
}
|
|
|
|
if (item->_text.hasSkipBlock()) {
|
|
|
|
if (item->_text.updateSkipBlock(skipBlockWidth(), skipBlockHeight())) {
|
|
|
|
item->_textWidth = -1;
|
|
|
|
item->_textHeight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Message::displayEditedBadge() const {
|
2018-02-03 19:52:35 +00:00
|
|
|
return (displayedEditDate() != TimeId(0));
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId Message::displayedEditDate() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto item = message();
|
2019-08-30 15:00:32 +00:00
|
|
|
if (item->hideEditedBadge()) {
|
2018-02-03 19:52:35 +00:00
|
|
|
return TimeId(0);
|
2019-08-30 15:00:32 +00:00
|
|
|
} else if (const auto edited = displayedEditBadge()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return edited->date;
|
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
return TimeId(0);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessageEdited *Message::displayedEditBadge() {
|
|
|
|
if (const auto media = this->media()) {
|
|
|
|
if (media->overrideEditedDate()) {
|
|
|
|
return media->displayedEditBadge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return message()->Get<HistoryMessageEdited>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const HistoryMessageEdited *Message::displayedEditBadge() const {
|
|
|
|
if (const auto media = this->media()) {
|
|
|
|
if (media->overrideEditedDate()) {
|
|
|
|
return media->displayedEditBadge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return message()->Get<HistoryMessageEdited>();
|
|
|
|
}
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
} // namespace HistoryView
|