mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-29 05:37:45 +00:00
Rework service messages fix
This commit is contained in:
parent
a1ec233c79
commit
bf9760fe23
@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto kNotificationTextLimit = 255;
|
||||
constexpr auto kPinnedMessageTextLimit = 16;
|
||||
|
||||
QString GenerateServiceTime(TimeId date) {
|
||||
@ -807,6 +808,20 @@ bool HistoryService::needCheck() const {
|
||||
|| Has<HistoryServiceSelfDestruct>();
|
||||
}
|
||||
|
||||
QString HistoryService::notificationText() const {
|
||||
const auto result = [&] {
|
||||
if (_media) {
|
||||
return _media->notificationText();
|
||||
} else if (!emptyText()) {
|
||||
return _cleanText.toString();
|
||||
}
|
||||
return QString();
|
||||
}();
|
||||
return (result.size() <= kNotificationTextLimit)
|
||||
? result
|
||||
: result.mid(0, kNotificationTextLimit) + qsl("...");
|
||||
}
|
||||
|
||||
QString HistoryService::inDialogsText(DrawInDialog way) const {
|
||||
return textcmdLink(1, TextUtilities::Clean(notificationText()));
|
||||
}
|
||||
@ -836,17 +851,16 @@ ClickHandlerPtr HistoryService::fromLink() const {
|
||||
void HistoryService::setServiceText(const PreparedText &prepared) {
|
||||
_text.setText(
|
||||
st::serviceTextStyle,
|
||||
prepared.text,
|
||||
(needTime() && !prepared.text.isEmpty() ? prepared.text + GenerateServiceTime(date()) : prepared.text),
|
||||
Ui::ItemTextServiceOptions());
|
||||
_postfixedText.setText(
|
||||
_cleanText.setText(
|
||||
st::serviceTextStyle,
|
||||
(needTime() ? prepared.text + GenerateServiceTime(date()) : prepared.text),
|
||||
prepared.text,
|
||||
Ui::ItemTextServiceOptions());
|
||||
auto linkIndex = 0;
|
||||
for_const (auto &link, prepared.links) {
|
||||
// Link indices start with 1.
|
||||
_text.setLink(++linkIndex, link);
|
||||
_postfixedText.setLink(linkIndex, link);
|
||||
}
|
||||
_textWidth = -1;
|
||||
_textHeight = 0;
|
||||
|
@ -106,6 +106,9 @@ public:
|
||||
bool serviceMsg() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
QString notificationText() const override;
|
||||
|
||||
QString inDialogsText(DrawInDialog way) const override;
|
||||
QString inReplyText() const override;
|
||||
|
||||
@ -172,9 +175,8 @@ private:
|
||||
|
||||
friend class HistoryView::Service;
|
||||
|
||||
Ui::Text::String _postfixedText;
|
||||
Ui::Text::String _cleanText;
|
||||
bool _needTime = true;
|
||||
|
||||
};
|
||||
|
||||
not_null<HistoryService*> GenerateJoinedMessage(
|
||||
|
@ -355,7 +355,7 @@ QSize Service::performCountCurrentSize(int newWidth) {
|
||||
auto nwidth = qMax(contentWidth - st::msgServicePadding.left() - st::msgServicePadding.right(), 0);
|
||||
if (nwidth != item->_textWidth) {
|
||||
item->_textWidth = nwidth;
|
||||
item->_textHeight = item->_postfixedText.countHeight(nwidth);
|
||||
item->_textHeight = item->_text.countHeight(nwidth);
|
||||
}
|
||||
if (contentWidth >= maxWidth()) {
|
||||
newHeight += minHeight();
|
||||
@ -375,8 +375,8 @@ QSize Service::performCountOptimalSize() {
|
||||
const auto item = message();
|
||||
const auto media = this->media();
|
||||
|
||||
auto maxWidth = item->_postfixedText.maxWidth() + st::msgServicePadding.left() + st::msgServicePadding.right();
|
||||
auto minHeight = item->_postfixedText.minHeight();
|
||||
auto maxWidth = item->_text.maxWidth() + st::msgServicePadding.left() + st::msgServicePadding.right();
|
||||
auto minHeight = item->_text.minHeight();
|
||||
if (media) {
|
||||
media->initDimensions();
|
||||
}
|
||||
@ -449,12 +449,12 @@ void Service::draw(
|
||||
|
||||
auto trect = QRect(g.left(), st::msgServiceMargin.top(), g.width(), height).marginsAdded(-st::msgServicePadding);
|
||||
|
||||
ServiceMessagePainter::paintComplexBubble(p, g.left(), g.width(), item->_postfixedText, trect);
|
||||
ServiceMessagePainter::paintComplexBubble(p, g.left(), g.width(), item->_text, trect);
|
||||
|
||||
p.setBrush(Qt::NoBrush);
|
||||
p.setPen(st::msgServiceFg);
|
||||
p.setFont(st::msgServiceFont);
|
||||
item->_postfixedText.draw(p, trect.x(), trect.y(), trect.width(), Qt::AlignCenter, 0, -1, selection, false);
|
||||
item->_text.draw(p, trect.x(), trect.y(), trect.width(), Qt::AlignCenter, 0, -1, selection, false);
|
||||
|
||||
p.restoreTextPalette();
|
||||
|
||||
@ -512,7 +512,7 @@ TextState Service::textState(QPoint point, StateRequest request) const {
|
||||
if (trect.contains(point)) {
|
||||
auto textRequest = request.forText();
|
||||
textRequest.align = style::al_center;
|
||||
result = TextState(item, item->_postfixedText.getState(
|
||||
result = TextState(item, item->_text.getState(
|
||||
point - trect.topLeft(),
|
||||
trect.width(),
|
||||
textRequest));
|
||||
@ -539,13 +539,13 @@ void Service::updatePressed(QPoint point) {
|
||||
}
|
||||
|
||||
TextForMimeData Service::selectedText(TextSelection selection) const {
|
||||
return message()->_postfixedText.toTextForMimeData(selection);
|
||||
return message()->_text.toTextForMimeData(selection);
|
||||
}
|
||||
|
||||
TextSelection Service::adjustSelection(
|
||||
TextSelection selection,
|
||||
TextSelectType type) const {
|
||||
return message()->_postfixedText.adjustSelection(selection, type);
|
||||
return message()->_text.adjustSelection(selection, type);
|
||||
}
|
||||
|
||||
EmptyPainter::EmptyPainter(not_null<History*> history) : _history(history) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user