Highlight timestamps in replies to media.
This commit is contained in:
		
							parent
							
								
									90c54b1f2a
								
							
						
					
					
						commit
						1ba052cc13
					
				
					 8 changed files with 88 additions and 21 deletions
				
			
		|  | @ -358,6 +358,13 @@ void HistoryMessageReply::paint( | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| DocumentData *HistoryMessageReply::replyToDocument() const { | ||||
| 	if (const auto media = replyToMsg ? replyToMsg->media() : nullptr) { | ||||
| 		return media->document(); | ||||
| 	} | ||||
| 	return nullptr; | ||||
| } | ||||
| 
 | ||||
| ReplyMarkupClickHandler::ReplyMarkupClickHandler( | ||||
| 	int row, | ||||
| 	int column, | ||||
|  |  | |||
|  | @ -130,18 +130,20 @@ struct HistoryMessageReply : public RuntimeComponent<HistoryMessageReply, Histor | |||
| 		int w, | ||||
| 		PaintFlags flags) const; | ||||
| 
 | ||||
| 	MsgId replyToId() const { | ||||
| 	[[nodiscard]] MsgId replyToId() const { | ||||
| 		return replyToMsgId; | ||||
| 	} | ||||
| 	int replyToWidth() const { | ||||
| 	[[nodiscard]] int replyToWidth() const { | ||||
| 		return maxReplyWidth; | ||||
| 	} | ||||
| 	ClickHandlerPtr replyToLink() const { | ||||
| 	[[nodiscard]] ClickHandlerPtr replyToLink() const { | ||||
| 		return replyToLnk; | ||||
| 	} | ||||
| 	void setReplyToLinkFrom( | ||||
| 		not_null<HistoryMessage*> holder); | ||||
| 
 | ||||
| 	[[nodiscard]] DocumentData *replyToDocument() const; | ||||
| 
 | ||||
| 	MsgId replyToMsgId = 0; | ||||
| 	HistoryItem *replyToMsg = nullptr; | ||||
| 	ClickHandlerPtr replyToLnk; | ||||
|  |  | |||
|  | @ -17,7 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "history/history_location_manager.h" | ||||
| #include "history/history_service.h" | ||||
| #include "history/view/history_view_service_message.h" | ||||
| #include "history/view/history_view_context_menu.h" // For CopyPostLink().
 | ||||
| #include "history/view/history_view_context_menu.h" // CopyPostLink.
 | ||||
| #include "history/view/media/history_view_media.h" // AddTimestampLinks.
 | ||||
| #include "chat_helpers/stickers_emoji_pack.h" | ||||
| #include "main/main_session.h" | ||||
| #include "boxes/share_box.h" | ||||
|  | @ -698,7 +699,13 @@ int HistoryMessage::viewsCount() const { | |||
| 
 | ||||
| bool HistoryMessage::updateDependencyItem() { | ||||
| 	if (const auto reply = Get<HistoryMessageReply>()) { | ||||
| 		return reply->updateData(this, true); | ||||
| 		const auto document = reply->replyToDocument(); | ||||
| 		const auto result = reply->updateData(this, true); | ||||
| 		if (document != reply->replyToDocument() | ||||
| 			&& generateLocalEntitiesByReply()) { | ||||
| 			reapplyText(); | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
| 	return true; | ||||
| } | ||||
|  | @ -1150,6 +1157,37 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const { | |||
| 	return result; | ||||
| } | ||||
| 
 | ||||
| bool HistoryMessage::generateLocalEntitiesByReply() const { | ||||
| 	return !_media || _media->webpage(); | ||||
| } | ||||
| 
 | ||||
| TextWithEntities HistoryMessage::withLocalEntities( | ||||
| 		const TextWithEntities &textWithEntities) const { | ||||
| 	if (!generateLocalEntitiesByReply()) { | ||||
| 		return textWithEntities; | ||||
| 	} | ||||
| 	if (const auto reply = Get<HistoryMessageReply>()) { | ||||
| 		if (const auto document = reply->replyToDocument()) { | ||||
| 			if (document->isVideoFile() || document->isSong()) { | ||||
| 				using namespace HistoryView; | ||||
| 				const auto duration = document->getDuration(); | ||||
| 				const auto base = (duration > 0) | ||||
| 					? DocumentTimestampLinkBase( | ||||
| 						document, | ||||
| 						reply->replyToMsg->fullId()) | ||||
| 					: QString(); | ||||
| 				if (!base.isEmpty()) { | ||||
| 					return AddTimestampLinks( | ||||
| 						textWithEntities, | ||||
| 						duration, | ||||
| 						base); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return textWithEntities; | ||||
| } | ||||
| 
 | ||||
| void HistoryMessage::setText(const TextWithEntities &textWithEntities) { | ||||
| 	for_const (auto &entity, textWithEntities.entities) { | ||||
| 		auto type = entity.type(); | ||||
|  | @ -1168,7 +1206,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { | |||
| 	clearIsolatedEmoji(); | ||||
| 	_text.setMarkedText( | ||||
| 		st::messageTextStyle, | ||||
| 		textWithEntities, | ||||
| 		withLocalEntities(textWithEntities), | ||||
| 		Ui::ItemTextOptions(this)); | ||||
| 	if (!textWithEntities.text.isEmpty() && _text.isEmpty()) { | ||||
| 		// If server has allowed some text that we've trim-ed entirely,
 | ||||
|  | @ -1184,6 +1222,11 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { | |||
| 	_textHeight = 0; | ||||
| } | ||||
| 
 | ||||
| void HistoryMessage::reapplyText() { | ||||
| 	setText(originalText()); | ||||
| 	history()->owner().requestItemResize(this); | ||||
| } | ||||
| 
 | ||||
| void HistoryMessage::setEmptyText() { | ||||
| 	clearIsolatedEmoji(); | ||||
| 	_text.setMarkedText( | ||||
|  | @ -1309,8 +1352,13 @@ void HistoryMessage::setRealId(MsgId newId) { | |||
| } | ||||
| 
 | ||||
| void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) { | ||||
| 	if (auto reply = Get<HistoryMessageReply>()) { | ||||
| 	if (const auto reply = Get<HistoryMessageReply>()) { | ||||
| 		const auto document = reply->replyToDocument(); | ||||
| 		reply->itemRemoved(this, dependency); | ||||
| 		if (document != reply->replyToDocument() | ||||
| 			&& generateLocalEntitiesByReply()) { | ||||
| 			reapplyText(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -198,6 +198,10 @@ private: | |||
| 		const MTPDmessageFwdHeader &data); | ||||
| 
 | ||||
| 	void refreshMessageBadge(); | ||||
| 	[[nodiscard]] bool generateLocalEntitiesByReply() const; | ||||
| 	[[nodiscard]] TextWithEntities withLocalEntities( | ||||
| 		const TextWithEntities &textWithEntities) const; | ||||
| 	void reapplyText(); | ||||
| 
 | ||||
| 	Ui::Text::String _messageBadge; | ||||
| 
 | ||||
|  |  | |||
|  | @ -423,7 +423,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms | |||
| 	if (radial | ||||
| 		|| (!streamingMode | ||||
| 			&& ((!_data->loaded() && !_data->loading()) || !autoplay))) { | ||||
| 		const auto radialOpacity = item->isSending() | ||||
| 		const auto radialOpacity = (item->isSending() || _data->uploading()) | ||||
| 			? 1. | ||||
| 			: streamed | ||||
| 			? streamed->waitingOpacity() | ||||
|  | @ -873,6 +873,7 @@ void Gif::drawGrouped( | |||
| 	if (displayLoading | ||||
| 		&& (!streamed | ||||
| 			|| item->isSending() | ||||
| 			|| _data->uploading() | ||||
| 			|| (cornerDownload && _data->loading()))) { | ||||
| 		ensureAnimation(); | ||||
| 		if (!_animation->radial.animating()) { | ||||
|  | @ -930,7 +931,7 @@ void Gif::drawGrouped( | |||
| 	if (radial | ||||
| 		|| (!streamingMode | ||||
| 			&& ((!_data->loaded() && !_data->loading()) || !autoplay))) { | ||||
| 		const auto radialOpacity = item->isSending() | ||||
| 		const auto radialOpacity = (item->isSending() || _data->uploading()) | ||||
| 			? 1. | ||||
| 			: streamed | ||||
| 			? streamed->waitingOpacity() | ||||
|  | @ -1423,6 +1424,7 @@ bool Gif::dataLoaded() const { | |||
| bool Gif::needInfoDisplay() const { | ||||
| 	return _data->isVideoFile() | ||||
| 		|| _parent->data()->isSending() | ||||
| 		|| _data->uploading() | ||||
| 		|| _parent->isUnderCursor(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -32,7 +32,17 @@ namespace { | |||
| 	return (ok1 && ok2 && ok3) ? result : -1; | ||||
| } | ||||
| 
 | ||||
| [[nodiscard]] TextWithEntities AddTimestampLinks( | ||||
| } // namespace
 | ||||
| 
 | ||||
| QString DocumentTimestampLinkBase( | ||||
| 		not_null<DocumentData*> document, | ||||
| 		FullMsgId context) { | ||||
| 	return QString( | ||||
| 		"doc%1_%2_%3" | ||||
| 	).arg(document->id).arg(context.channel).arg(context.msg); | ||||
| } | ||||
| 
 | ||||
| TextWithEntities AddTimestampLinks( | ||||
| 		TextWithEntities text, | ||||
| 		TimeId duration, | ||||
| 		const QString &base) { | ||||
|  | @ -92,16 +102,6 @@ namespace { | |||
| 	return text; | ||||
| } | ||||
| 
 | ||||
| } // namespace
 | ||||
| 
 | ||||
| QString DocumentTimestampLinkBase( | ||||
| 		not_null<DocumentData*> document, | ||||
| 		FullMsgId context) { | ||||
| 	return QString( | ||||
| 		"doc%1_%2_%3" | ||||
| 	).arg(document->id).arg(context.channel).arg(context.msg); | ||||
| } | ||||
| 
 | ||||
| Storage::SharedMediaTypesMask Media::sharedMediaTypes() const { | ||||
| 	return {}; | ||||
| } | ||||
|  |  | |||
|  | @ -43,6 +43,10 @@ enum class MediaInBubbleState { | |||
| [[nodiscard]] QString DocumentTimestampLinkBase( | ||||
| 	not_null<DocumentData*> document, | ||||
| 	FullMsgId context); | ||||
| [[nodiscard]] TextWithEntities AddTimestampLinks( | ||||
| 	TextWithEntities text, | ||||
| 	TimeId duration, | ||||
| 	const QString &base); | ||||
| 
 | ||||
| class Media : public Object { | ||||
| public: | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| Subproject commit 65eb03a6a78ffe09cd8f644edfe14560854b89eb | ||||
| Subproject commit 6b673d9154cd596b9c648b130f334c166af36875 | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston