mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 08:51:12 +00:00
Highlight timestamps in song captions.
This commit is contained in:
parent
3e3e1d628c
commit
90c54b1f2a
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "main/main_session.h"
|
||||
@ -385,10 +386,12 @@ bool OpenMediaTimestamp(
|
||||
session->settings().setMediaLastPlaybackPosition(
|
||||
documentId,
|
||||
time * crl::time(1000));
|
||||
if (!document->isNull()) {
|
||||
if (document->isVideoFile()) {
|
||||
Core::App().showDocument(
|
||||
document,
|
||||
session->data().message(itemId));
|
||||
} else if (document->isSong()) {
|
||||
Media::Player::instance()->play({ document, itemId });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -259,15 +259,24 @@ Full Full::FullDisabled() {
|
||||
|
||||
bool Should(
|
||||
const Full &data,
|
||||
not_null<PeerData*> peer,
|
||||
Source source,
|
||||
not_null<DocumentData*> document) {
|
||||
if (document->sticker()) {
|
||||
return true;
|
||||
} else if (document->isVoiceMessage()
|
||||
|| document->isVideoMessage()
|
||||
|| document->isSong()
|
||||
|| document->isVideoFile()) {
|
||||
return false;
|
||||
}
|
||||
return data.shouldDownload(
|
||||
SourceFromPeer(peer),
|
||||
Type::File,
|
||||
document->size);
|
||||
return data.shouldDownload(source, Type::File, document->size);
|
||||
}
|
||||
|
||||
bool Should(
|
||||
const Full &data,
|
||||
not_null<PeerData*> peer,
|
||||
not_null<DocumentData*> document) {
|
||||
return Should(data, SourceFromPeer(peer), document);
|
||||
}
|
||||
|
||||
bool Should(
|
||||
@ -277,9 +286,9 @@ bool Should(
|
||||
return true;
|
||||
}
|
||||
const auto size = document->size;
|
||||
return data.shouldDownload(Source::User, Type::File, size)
|
||||
|| data.shouldDownload(Source::Group, Type::File, size)
|
||||
|| data.shouldDownload(Source::Channel, Type::File, size);
|
||||
return Should(data, Source::User, document)
|
||||
|| Should(data, Source::Group, document)
|
||||
|| Should(data, Source::Channel, document);
|
||||
}
|
||||
|
||||
bool Should(
|
||||
|
@ -38,10 +38,10 @@ Document::Document(
|
||||
: File(parent, parent->data())
|
||||
, _data(document) {
|
||||
const auto item = parent->data();
|
||||
auto caption = createCaption(item);
|
||||
auto caption = createCaption();
|
||||
|
||||
createComponents(!caption.isEmpty());
|
||||
if (auto named = Get<HistoryDocumentNamed>()) {
|
||||
if (const auto named = Get<HistoryDocumentNamed>()) {
|
||||
fillNamedFromData(named);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ Document::Document(
|
||||
|
||||
setStatusSize(FileStatusSizeReady);
|
||||
|
||||
if (auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
if (const auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
captioned->_caption = std::move(caption);
|
||||
}
|
||||
}
|
||||
@ -830,7 +830,7 @@ void Document::refreshParentId(not_null<HistoryItem*> realParent) {
|
||||
|
||||
void Document::parentTextUpdated() {
|
||||
auto caption = (_parent->media() == this)
|
||||
? createCaption(_parent->data())
|
||||
? createCaption()
|
||||
: Ui::Text::String();
|
||||
if (!caption.isEmpty()) {
|
||||
AddComponents(HistoryDocumentCaptioned::Bit());
|
||||
@ -849,4 +849,17 @@ TextWithEntities Document::getCaption() const {
|
||||
return TextWithEntities();
|
||||
}
|
||||
|
||||
Ui::Text::String Document::createCaption() {
|
||||
const auto timestampLinksDuration = _data->isSong()
|
||||
? _data->getDuration()
|
||||
: 0;
|
||||
const auto timestampLinkBase = timestampLinksDuration
|
||||
? DocumentTimestampLinkBase(_data, _realParent->fullId())
|
||||
: QString();
|
||||
return File::createCaption(
|
||||
_parent->data(),
|
||||
timestampLinksDuration,
|
||||
timestampLinkBase);
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
@ -12,6 +12,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
struct HistoryDocumentNamed;
|
||||
|
||||
namespace Ui {
|
||||
namespace Text {
|
||||
class String;
|
||||
} // namespace Text
|
||||
} // namespace Ui
|
||||
|
||||
namespace HistoryView {
|
||||
|
||||
class Document
|
||||
@ -69,6 +75,8 @@ private:
|
||||
int realDuration = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] Ui::Text::String createCaption();
|
||||
|
||||
QSize countOptimalSize() override;
|
||||
QSize countCurrentSize(int newWidth) override;
|
||||
|
||||
|
@ -422,7 +422,15 @@ Streaming::PlaybackOptions Instance::streamingOptions(
|
||||
? kVoicePlaybackSpeedMultiplier
|
||||
: 1.;
|
||||
result.audioId = audioId;
|
||||
if (position >= 0) {
|
||||
result.position = position;
|
||||
} else if (document) {
|
||||
auto &settings = document->session().settings();
|
||||
result.position = settings.mediaLastPlaybackPosition(document->id);
|
||||
settings.setMediaLastPlaybackPosition(document->id, 0);
|
||||
} else {
|
||||
result.position = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ private:
|
||||
std::shared_ptr<Streaming::Document> shared);
|
||||
Streaming::PlaybackOptions streamingOptions(
|
||||
const AudioMsgId &audioId,
|
||||
crl::time position = 0);
|
||||
crl::time position = -1);
|
||||
|
||||
// Observed notifications.
|
||||
void handleSongUpdate(const AudioMsgId &audioId);
|
||||
|
@ -146,6 +146,10 @@ Stream File::Context::initStream(
|
||||
|
||||
result.codec = FFmpeg::MakeCodecPointer(info);
|
||||
if (!result.codec) {
|
||||
if (info->codecpar->codec_id == AV_CODEC_ID_MJPEG) {
|
||||
// mp3 files contain such "video stream", just ignore it.
|
||||
return Stream();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,12 @@ void PlaybackProgress::updateState(
|
||||
const auto animatedPosition = position + (state.frequency * kPlaybackAnimationDurationMs / 1000);
|
||||
const auto animatedProgress = length ? qMax(float64(animatedPosition) / length, 0.) : 0.;
|
||||
if (length != _length || position != _position || wasInLoadingState) {
|
||||
if (auto animated = (length && _length && animatedProgress > value())) {
|
||||
const auto animated = length
|
||||
&& _length
|
||||
&& (animatedProgress > value())
|
||||
&& (position > _position)
|
||||
&& (position < _position + state.frequency);
|
||||
if (animated) {
|
||||
setValue(animatedProgress, animated);
|
||||
} else {
|
||||
setValue(progress, animated);
|
||||
|
Loading…
Reference in New Issue
Block a user