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