Use DocumentData::getDuration for all types.
This commit is contained in:
		
							parent
							
								
									41c60419f1
								
							
						
					
					
						commit
						01d763eed1
					
				
					 11 changed files with 27 additions and 41 deletions
				
			
		| 
						 | 
					@ -108,7 +108,7 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
 | 
				
			||||||
	const auto dimensions = document->dimensions;
 | 
						const auto dimensions = document->dimensions;
 | 
				
			||||||
	auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
 | 
						auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
 | 
				
			||||||
	if (dimensions.width() > 0 && dimensions.height() > 0) {
 | 
						if (dimensions.width() > 0 && dimensions.height() > 0) {
 | 
				
			||||||
		const auto duration = document->duration();
 | 
							const auto duration = document->getDuration();
 | 
				
			||||||
		if (duration >= 0) {
 | 
							if (duration >= 0) {
 | 
				
			||||||
			auto flags = MTPDdocumentAttributeVideo::Flags(0);
 | 
								auto flags = MTPDdocumentAttributeVideo::Flags(0);
 | 
				
			||||||
			if (document->isVideoMessage()) {
 | 
								if (document->isVideoMessage()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1397,8 +1397,15 @@ bool DocumentData::isVideoFile() const {
 | 
				
			||||||
	return (type == VideoDocument);
 | 
						return (type == VideoDocument);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int32 DocumentData::duration() const {
 | 
					TimeId DocumentData::getDuration() const {
 | 
				
			||||||
	return (isAnimation() || isVideoFile()) ? _duration : -1;
 | 
						if (const auto song = this->song()) {
 | 
				
			||||||
 | 
							return std::max(song->duration, 0);
 | 
				
			||||||
 | 
						} else if (const auto voice = this->voice()) {
 | 
				
			||||||
 | 
							return std::max(voice->duration, 0);
 | 
				
			||||||
 | 
						} else if (isAnimation() || isVideoFile()) {
 | 
				
			||||||
 | 
							return std::max(_duration, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool DocumentData::isImage() const {
 | 
					bool DocumentData::isImage() const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -163,7 +163,7 @@ public:
 | 
				
			||||||
	[[nodiscard]] bool isGifv() const;
 | 
						[[nodiscard]] bool isGifv() const;
 | 
				
			||||||
	[[nodiscard]] bool isTheme() const;
 | 
						[[nodiscard]] bool isTheme() const;
 | 
				
			||||||
	[[nodiscard]] bool isSharedMediaMusic() const;
 | 
						[[nodiscard]] bool isSharedMediaMusic() const;
 | 
				
			||||||
	[[nodiscard]] int32 duration() const;
 | 
						[[nodiscard]] TimeId getDuration() const;
 | 
				
			||||||
	[[nodiscard]] bool isImage() const;
 | 
						[[nodiscard]] bool isImage() const;
 | 
				
			||||||
	void recountIsImage();
 | 
						void recountIsImage();
 | 
				
			||||||
	[[nodiscard]] bool supportsStreaming() const;
 | 
						[[nodiscard]] bool supportsStreaming() const;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,14 +21,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int documentMaxStatusWidth(DocumentData *document) {
 | 
					int documentMaxStatusWidth(DocumentData *document) {
 | 
				
			||||||
	auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
 | 
						auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
 | 
				
			||||||
 | 
						const auto duration = document->getDuration();
 | 
				
			||||||
	if (const auto song = document->song()) {
 | 
						if (const auto song = document->song()) {
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatPlayedText(song->duration, song->duration)));
 | 
							accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(song->duration, document->size)));
 | 
							accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
 | 
				
			||||||
	} else if (const auto voice = document->voice()) {
 | 
						} else if (const auto voice = document->voice()) {
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatPlayedText(voice->duration, voice->duration)));
 | 
							accumulate_max(result, st::normalFont->width(formatPlayedText(duration, duration)));
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(voice->duration, document->size)));
 | 
							accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
 | 
				
			||||||
	} else if (document->isVideoFile()) {
 | 
						} else if (document->isVideoFile()) {
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(document->duration(), document->size)));
 | 
							accumulate_max(result, st::normalFont->width(formatDurationAndSizeText(duration, document->size)));
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		accumulate_max(result, st::normalFont->width(formatSizeText(document->size)));
 | 
							accumulate_max(result, st::normalFont->width(formatSizeText(document->size)));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -729,7 +729,7 @@ void HistoryGif::setStatusSize(int newSize) const {
 | 
				
			||||||
		if (newSize < 0) {
 | 
							if (newSize < 0) {
 | 
				
			||||||
			_statusText = formatDurationText(-newSize - 1);
 | 
								_statusText = formatDurationText(-newSize - 1);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			_statusText = formatDurationText(_data->duration());
 | 
								_statusText = formatDurationText(_data->getDuration());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		HistoryFileMedia::setStatusSize(newSize, _data->size, -2, 0);
 | 
							HistoryFileMedia::setStatusSize(newSize, _data->size, -2, 0);
 | 
				
			||||||
| 
						 | 
					@ -749,7 +749,7 @@ void HistoryGif::updateStatusText() const {
 | 
				
			||||||
	} else if (_data->loaded()) {
 | 
						} else if (_data->loaded()) {
 | 
				
			||||||
		statusSize = FileStatusSizeLoaded;
 | 
							statusSize = FileStatusSizeLoaded;
 | 
				
			||||||
		if (const auto video = activeRoundPlayer()) {
 | 
							if (const auto video = activeRoundPlayer()) {
 | 
				
			||||||
			statusSize = -1 - _data->duration();
 | 
								statusSize = -1 - _data->getDuration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			const auto type = AudioMsgId::Type::Voice;
 | 
								const auto type = AudioMsgId::Type::Voice;
 | 
				
			||||||
			const auto state = Media::Player::instance()->getState(type);
 | 
								const auto state = Media::Player::instance()->getState(type);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -518,7 +518,7 @@ void HistoryVideo::validateGroupedCache(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HistoryVideo::setStatusSize(int newSize) const {
 | 
					void HistoryVideo::setStatusSize(int newSize) const {
 | 
				
			||||||
	HistoryFileMedia::setStatusSize(newSize, _data->size, _data->duration(), 0);
 | 
						HistoryFileMedia::setStatusSize(newSize, _data->size, _data->getDuration(), 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TextWithEntities HistoryVideo::selectedText(TextSelection selection) const {
 | 
					TextWithEntities HistoryVideo::selectedText(TextSelection selection) const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,12 +73,8 @@ int FileBase::content_height() const {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int FileBase::content_duration() const {
 | 
					int FileBase::content_duration() const {
 | 
				
			||||||
	if (const auto document = getShownDocument()) {
 | 
						if (const auto document = getShownDocument()) {
 | 
				
			||||||
		if (document->duration() > 0) {
 | 
							if (document->getDuration() > 0) {
 | 
				
			||||||
			return document->duration();
 | 
								return document->getDuration();
 | 
				
			||||||
		} else if (const auto song = document->song()) {
 | 
					 | 
				
			||||||
			if (song->duration) {
 | 
					 | 
				
			||||||
				return song->duration;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return getResultDuration();
 | 
						return getResultDuration();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -670,13 +670,7 @@ Media::Player::TrackState Player::prepareLegacyState() const {
 | 
				
			||||||
	result.length = _totalDuration;
 | 
						result.length = _totalDuration;
 | 
				
			||||||
	if (result.length == kTimeUnknown) {
 | 
						if (result.length == kTimeUnknown) {
 | 
				
			||||||
		const auto document = _options.audioId.audio();
 | 
							const auto document = _options.audioId.audio();
 | 
				
			||||||
		const auto duration = !document
 | 
							const auto duration = document ? document->getDuration() : 0;
 | 
				
			||||||
			? crl::time(0)
 | 
					 | 
				
			||||||
			: document->song()
 | 
					 | 
				
			||||||
			? document->song()->duration
 | 
					 | 
				
			||||||
			: document->voice()
 | 
					 | 
				
			||||||
			? document->voice()->duration
 | 
					 | 
				
			||||||
			: document->duration();
 | 
					 | 
				
			||||||
		if (duration > 0) {
 | 
							if (duration > 0) {
 | 
				
			||||||
			result.length = duration * crl::time(1000);
 | 
								result.length = duration * crl::time(1000);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2292,17 +2292,7 @@ void OverlayWidget::updatePlaybackState() {
 | 
				
			||||||
	if (videoIsGifv()) {
 | 
						if (videoIsGifv()) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	auto state = _streamed->player.prepareLegacyState();
 | 
						const auto state = _streamed->player.prepareLegacyState();
 | 
				
			||||||
	if (state.length == kTimeUnknown) {
 | 
					 | 
				
			||||||
		const auto duration = _doc->song()
 | 
					 | 
				
			||||||
			? _doc->song()->duration
 | 
					 | 
				
			||||||
			: _doc->duration();
 | 
					 | 
				
			||||||
		if (duration > 0) {
 | 
					 | 
				
			||||||
			state.length = std::max(
 | 
					 | 
				
			||||||
				duration * crl::time(1000),
 | 
					 | 
				
			||||||
				crl::time(state.position));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (state.position != kTimeUnknown && state.length != kTimeUnknown) {
 | 
						if (state.position != kTimeUnknown && state.length != kTimeUnknown) {
 | 
				
			||||||
		_streamed->controls.updatePlayback(state);
 | 
							_streamed->controls.updatePlayback(state);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -400,7 +400,7 @@ Video::Video(
 | 
				
			||||||
	not_null<DocumentData*> video)
 | 
						not_null<DocumentData*> video)
 | 
				
			||||||
: RadialProgressItem(parent)
 | 
					: RadialProgressItem(parent)
 | 
				
			||||||
, _data(video)
 | 
					, _data(video)
 | 
				
			||||||
, _duration(formatDurationText(_data->duration())) {
 | 
					, _duration(formatDurationText(_data->getDuration())) {
 | 
				
			||||||
	setDocumentLinks(_data);
 | 
						setDocumentLinks(_data);
 | 
				
			||||||
	_data->loadThumbnail(parent->fullId());
 | 
						_data->loadThumbnail(parent->fullId());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -837,9 +837,7 @@ void Voice::updateName() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Voice::duration() const {
 | 
					int Voice::duration() const {
 | 
				
			||||||
	return _data->voice()
 | 
						return std::max(_data->getDuration(), 0);
 | 
				
			||||||
		? _data->voice()->duration
 | 
					 | 
				
			||||||
		: std::max(_data->duration(), 0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Voice::updateStatusText() {
 | 
					bool Voice::updateStatusText() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ void Document::writeToStream(QDataStream &stream, DocumentData *document) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		writeStorageImageLocation(stream, document->sticker()->loc);
 | 
							writeStorageImageLocation(stream, document->sticker()->loc);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		stream << qint32(document->duration());
 | 
							stream << qint32(document->getDuration());
 | 
				
			||||||
		if (const auto thumb = document->thumbnail()) {
 | 
							if (const auto thumb = document->thumbnail()) {
 | 
				
			||||||
			writeStorageImageLocation(stream, thumb->location());
 | 
								writeStorageImageLocation(stream, thumb->location());
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue