Moved generating preview text from HistoryWidget to WebPageData.
This commit is contained in:
		
							parent
							
								
									69bc595e31
								
							
						
					
					
						commit
						42e0994581
					
				
					 4 changed files with 88 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -604,6 +604,8 @@ PRIVATE
 | 
			
		|||
    history/view/history_view_service_message.h
 | 
			
		||||
    history/view/history_view_top_bar_widget.cpp
 | 
			
		||||
    history/view/history_view_top_bar_widget.h
 | 
			
		||||
    history/view/history_view_webpage_preview.cpp
 | 
			
		||||
    history/view/history_view_webpage_preview.h
 | 
			
		||||
    history/history.cpp
 | 
			
		||||
    history/history.h
 | 
			
		||||
    history/history_drag_area.cpp
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,6 +59,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include "history/view/history_view_element.h"
 | 
			
		||||
#include "history/view/history_view_scheduled_section.h"
 | 
			
		||||
#include "history/view/history_view_schedule_box.h"
 | 
			
		||||
#include "history/view/history_view_webpage_preview.h"
 | 
			
		||||
#include "history/view/media/history_view_media.h"
 | 
			
		||||
#include "profile/profile_block_group_members.h"
 | 
			
		||||
#include "info/info_memento.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -5965,38 +5966,22 @@ void HistoryWidget::updatePreview() {
 | 
			
		|||
			const auto timeout = (_previewData->pendingTill - base::unixtime::now());
 | 
			
		||||
			_previewTimer.callOnce(std::max(timeout, 0) * crl::time(1000));
 | 
			
		||||
		} else {
 | 
			
		||||
			QString title, desc;
 | 
			
		||||
			if (_previewData->siteName.isEmpty()) {
 | 
			
		||||
				if (_previewData->title.isEmpty()) {
 | 
			
		||||
					if (_previewData->description.text.isEmpty()) {
 | 
			
		||||
						title = _previewData->author;
 | 
			
		||||
						desc = ((_previewData->document && !_previewData->document->filename().isEmpty()) ? _previewData->document->filename() : _previewData->url);
 | 
			
		||||
					} else {
 | 
			
		||||
						title = _previewData->description.text;
 | 
			
		||||
						desc = _previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ? _previewData->document->filename() : _previewData->url) : _previewData->author;
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					title = _previewData->title;
 | 
			
		||||
					desc = _previewData->description.text.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ? _previewData->document->filename() : _previewData->url) : _previewData->author) : _previewData->description.text;
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				title = _previewData->siteName;
 | 
			
		||||
				desc = _previewData->title.isEmpty() ? (_previewData->description.text.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->filename().isEmpty()) ? _previewData->document->filename() : _previewData->url) : _previewData->author) : _previewData->description.text) : _previewData->title;
 | 
			
		||||
			}
 | 
			
		||||
			if (title.isEmpty()) {
 | 
			
		||||
			auto preview =
 | 
			
		||||
				HistoryView::TitleAndDescriptionFromWebPage(_previewData);
 | 
			
		||||
			if (preview.title.isEmpty()) {
 | 
			
		||||
				if (_previewData->document) {
 | 
			
		||||
					title = tr::lng_attach_file(tr::now);
 | 
			
		||||
					preview.title = tr::lng_attach_file(tr::now);
 | 
			
		||||
				} else if (_previewData->photo) {
 | 
			
		||||
					title = tr::lng_attach_photo(tr::now);
 | 
			
		||||
					preview.title = tr::lng_attach_photo(tr::now);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			_previewTitle.setText(
 | 
			
		||||
				st::msgNameStyle,
 | 
			
		||||
				title,
 | 
			
		||||
				preview.title,
 | 
			
		||||
				Ui::NameTextOptions());
 | 
			
		||||
			_previewDescription.setText(
 | 
			
		||||
				st::messageTextStyle,
 | 
			
		||||
				TextUtilities::Clean(desc),
 | 
			
		||||
				TextUtilities::Clean(preview.description),
 | 
			
		||||
				Ui::DialogTextOptions());
 | 
			
		||||
		}
 | 
			
		||||
	} else if (!readyToForward() && !replyToId() && !_editMsgId) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,59 @@
 | 
			
		|||
/*
 | 
			
		||||
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_webpage_preview.h"
 | 
			
		||||
 | 
			
		||||
#include "data/data_web_page.h"
 | 
			
		||||
 | 
			
		||||
namespace HistoryView {
 | 
			
		||||
 | 
			
		||||
WebPageText TitleAndDescriptionFromWebPage(not_null<WebPageData*> d) {
 | 
			
		||||
	QString resultTitle, resultDescription;
 | 
			
		||||
	const auto document = d->document;
 | 
			
		||||
	const auto photo = d->photo;
 | 
			
		||||
	const auto author = d->author;
 | 
			
		||||
	const auto siteName = d->siteName;
 | 
			
		||||
	const auto title = d->title;
 | 
			
		||||
	const auto description = d->description;
 | 
			
		||||
	const auto filenameOrUrl = [&] {
 | 
			
		||||
		return ((document && !document->filename().isEmpty())
 | 
			
		||||
			? document->filename()
 | 
			
		||||
			: d->url);
 | 
			
		||||
	};
 | 
			
		||||
	const auto authorOrFilename = [&] {
 | 
			
		||||
		return (author.isEmpty()
 | 
			
		||||
			? filenameOrUrl()
 | 
			
		||||
			: author);
 | 
			
		||||
	};
 | 
			
		||||
	const auto descriptionOrAuthor = [&] {
 | 
			
		||||
		return (description.text.isEmpty()
 | 
			
		||||
			? authorOrFilename()
 | 
			
		||||
			: description.text);
 | 
			
		||||
	};
 | 
			
		||||
	if (siteName.isEmpty()) {
 | 
			
		||||
		if (title.isEmpty()) {
 | 
			
		||||
			if (description.text.isEmpty()) {
 | 
			
		||||
				resultTitle = author;
 | 
			
		||||
				resultDescription = filenameOrUrl();
 | 
			
		||||
			} else {
 | 
			
		||||
				resultTitle = description.text;
 | 
			
		||||
				resultDescription = authorOrFilename();
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			resultTitle = title;
 | 
			
		||||
			resultDescription = descriptionOrAuthor();
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		resultTitle = siteName;
 | 
			
		||||
		resultDescription = title.isEmpty()
 | 
			
		||||
			? descriptionOrAuthor()
 | 
			
		||||
			: title;
 | 
			
		||||
	}
 | 
			
		||||
	return { resultTitle, resultDescription };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace HistoryView
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
/*
 | 
			
		||||
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
 | 
			
		||||
*/
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
namespace HistoryView {
 | 
			
		||||
 | 
			
		||||
struct WebPageText {
 | 
			
		||||
	QString title;
 | 
			
		||||
	QString description;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
WebPageText TitleAndDescriptionFromWebPage(not_null<WebPageData*> d);
 | 
			
		||||
 | 
			
		||||
} // namespace HistoryView
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue