mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 00:08:02 +00:00
Rename some methods in DocumentData.
Also fix voice message mark as read when autoplaying after previous. Also show play icon and don't show playlist for audio files that do not have shared music files attributes but have audio file mime type.
This commit is contained in:
parent
4ef3de5287
commit
8b69e6ab99
Telegram/SourceFiles
app.cpp
boxes
data
history
history_admin_log_inner.cpphistory_inner_widget.cpphistory_item.cpphistory_media_types.cpphistory_media_types.hhistory_message.cpphistory_service.cpphistory_widget.cpp
info/media
inline_bots
mainwidget.cppmedia/player
media_player_cover.cppmedia_player_float.cppmedia_player_instance.cppmedia_player_panel.cppmedia_player_widget.cpp
mediaview.cppmessenger.cppoverview
storage
window
@ -1615,7 +1615,7 @@ namespace {
|
||||
|
||||
MediaKey newKey = convert->mediaKey();
|
||||
if (idChanged) {
|
||||
if (convert->voice()) {
|
||||
if (convert->isVoiceMessage()) {
|
||||
Local::copyAudio(oldKey, newKey);
|
||||
} else if (convert->sticker() || convert->isAnimation()) {
|
||||
Local::copyStickerImage(oldKey, newKey);
|
||||
|
@ -325,7 +325,7 @@ void AutoDownloadBox::onSave() {
|
||||
cSetAutoDownloadAudio(autoDownloadAudio);
|
||||
if (enabledPrivate || enabledGroups) {
|
||||
for (auto document : App::documentsData()) {
|
||||
if (document->voice()) {
|
||||
if (document->isVoiceMessage()) {
|
||||
document->automaticLoadSettingsChanged();
|
||||
}
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ EditCaptionBox::EditCaptionBox(QWidget*, HistoryMedia *media, FullMsgId msgId) :
|
||||
}
|
||||
|
||||
if (doc) {
|
||||
auto nameString = doc->voice()
|
||||
auto nameString = doc->isVoiceMessage()
|
||||
? lang(lng_media_audio)
|
||||
: doc->composeNameString();
|
||||
_name.setText(
|
||||
@ -529,7 +529,7 @@ EditCaptionBox::EditCaptionBox(QWidget*, HistoryMedia *media, FullMsgId msgId) :
|
||||
_name.maxWidth(),
|
||||
st::normalFont->width(_status));
|
||||
_isImage = doc->isImage();
|
||||
_isAudio = (doc->voice() || doc->song());
|
||||
_isAudio = (doc->isVoiceMessage() || doc->isAudioFile());
|
||||
}
|
||||
} else {
|
||||
int32 maxW = 0, maxH = 0;
|
||||
|
@ -31,22 +31,48 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "auth_session.h"
|
||||
#include "messenger.h"
|
||||
|
||||
QString joinList(const QStringList &list, const QString &sep) {
|
||||
QString result;
|
||||
if (list.isEmpty()) return result;
|
||||
namespace {
|
||||
|
||||
int32 l = list.size(), s = sep.size() * (l - 1);
|
||||
for (int32 i = 0; i < l; ++i) {
|
||||
s += list.at(i).size();
|
||||
QString JoinStringList(const QStringList &list, const QString &separator) {
|
||||
const auto count = list.size();
|
||||
if (!count) {
|
||||
return QString();
|
||||
}
|
||||
result.reserve(s);
|
||||
result.append(list.at(0));
|
||||
for (int32 i = 1; i < l; ++i) {
|
||||
result.append(sep).append(list.at(i));
|
||||
|
||||
auto result = QString();
|
||||
auto fullsize = separator.size() * (count - 1);
|
||||
for (const auto &string : list) {
|
||||
fullsize += string.size();
|
||||
}
|
||||
result.reserve(fullsize);
|
||||
result.append(list[0]);
|
||||
for (auto i = 1; i != count; ++i) {
|
||||
result.append(separator).append(list[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool fileIsImage(const QString &name, const QString &mime) {
|
||||
QString lowermime = mime.toLower(), namelower = name.toLower();
|
||||
if (lowermime.startsWith(qstr("image/"))) {
|
||||
return true;
|
||||
} else if (namelower.endsWith(qstr(".bmp"))
|
||||
|| namelower.endsWith(qstr(".jpg"))
|
||||
|| namelower.endsWith(qstr(".jpeg"))
|
||||
|| namelower.endsWith(qstr(".gif"))
|
||||
|| namelower.endsWith(qstr(".webp"))
|
||||
|| namelower.endsWith(qstr(".tga"))
|
||||
|| namelower.endsWith(qstr(".tiff"))
|
||||
|| namelower.endsWith(qstr(".tif"))
|
||||
|| namelower.endsWith(qstr(".psd"))
|
||||
|| namelower.endsWith(qstr(".png"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs, const QDir &dir) {
|
||||
#ifdef Q_OS_WIN
|
||||
name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_"));
|
||||
@ -81,9 +107,9 @@ QString saveFileName(const QString &title, const QString &filter, const QString
|
||||
QRegularExpressionMatch m = QRegularExpression(qsl(" \\*\\.") + ext + qsl("[\\)\\s]"), QRegularExpression::CaseInsensitiveOption).match(first);
|
||||
if (m.hasMatch() && m.capturedStart() > start + 3) {
|
||||
int32 oldpos = m.capturedStart(), oldend = m.capturedEnd();
|
||||
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3, oldpos - start - 3) + first.mid(oldend - 1) + sep + joinList(filters.mid(1), sep);
|
||||
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3, oldpos - start - 3) + first.mid(oldend - 1) + sep + JoinStringList(filters.mid(1), sep);
|
||||
} else {
|
||||
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3) + sep + joinList(filters.mid(1), sep);
|
||||
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3) + sep + JoinStringList(filters.mid(1), sep);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -162,14 +188,14 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||
MimeType mimeType = mimeTypeForName(data->mimeString());
|
||||
QStringList p = mimeType.globPatterns();
|
||||
QString pattern = p.isEmpty() ? QString() : p.front();
|
||||
if (data->voice()) {
|
||||
if (data->isVoiceMessage()) {
|
||||
auto mp3 = data->hasMimeType(qstr("audio/mp3"));
|
||||
name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : already;
|
||||
filter = mp3 ? qsl("MP3 Audio (*.mp3);;") : qsl("OGG Opus Audio (*.ogg);;");
|
||||
filter += FileDialog::AllFilesFilter();
|
||||
caption = lang(lng_save_audio);
|
||||
prefix = qsl("audio");
|
||||
} else if (data->isVideo()) {
|
||||
} else if (data->isVideoFile()) {
|
||||
name = already.isEmpty() ? data->filename() : already;
|
||||
if (name.isEmpty()) {
|
||||
name = pattern.isEmpty() ? qsl(".mov") : pattern.replace('*', QString());
|
||||
@ -191,7 +217,7 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals
|
||||
} else {
|
||||
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
|
||||
}
|
||||
caption = lang(data->song() ? lng_save_audio_file : lng_save_file);
|
||||
caption = lang(data->isAudioFile() ? lng_save_audio_file : lng_save_file);
|
||||
prefix = qsl("doc");
|
||||
}
|
||||
|
||||
@ -202,12 +228,12 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
|
||||
if (!data->date) return;
|
||||
|
||||
auto msgId = context ? context->fullId() : FullMsgId();
|
||||
bool playVoice = data->voice();
|
||||
bool playMusic = data->tryPlaySong();
|
||||
bool playVideo = data->isVideo();
|
||||
bool playVoice = data->isVoiceMessage();
|
||||
bool playMusic = data->isAudioFile();
|
||||
bool playVideo = data->isVideoFile();
|
||||
bool playAnimation = data->isAnimation();
|
||||
auto &location = data->location(true);
|
||||
if (auto applyTheme = data->isTheme()) {
|
||||
if (data->isTheme()) {
|
||||
if (!location.isEmpty() && location.accessEnable()) {
|
||||
Messenger::Instance().showDocument(data, context);
|
||||
location.accessDisable();
|
||||
@ -258,7 +284,7 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
|
||||
}
|
||||
}
|
||||
if (App::main()) App::main()->mediaMarkRead(data);
|
||||
} else if (data->voice() || data->song() || data->isVideo()) {
|
||||
} else if (data->isVoiceMessage() || data->isAudioFile() || data->isVideoFile()) {
|
||||
auto filepath = location.name();
|
||||
if (documentIsValidMediaFile(filepath)) {
|
||||
File::Launch(filepath);
|
||||
@ -303,12 +329,19 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context,
|
||||
}
|
||||
|
||||
void DocumentOpenClickHandler::onClickImpl() const {
|
||||
auto item = App::hoveredLinkItem() ? App::hoveredLinkItem() : (App::contextItem() ? App::contextItem() : nullptr);
|
||||
doOpen(document(), item, document()->voice() ? ActionOnLoadNone : ActionOnLoadOpen);
|
||||
const auto item = App::hoveredLinkItem()
|
||||
? App::hoveredLinkItem()
|
||||
: (App::contextItem() ? App::contextItem() : nullptr);
|
||||
const auto action = document()->isVoiceMessage()
|
||||
? ActionOnLoadNone
|
||||
: ActionOnLoadOpen;
|
||||
doOpen(document(), item, action);
|
||||
}
|
||||
|
||||
void GifOpenClickHandler::onClickImpl() const {
|
||||
auto item = App::hoveredLinkItem() ? App::hoveredLinkItem() : (App::contextItem() ? App::contextItem() : nullptr);
|
||||
const auto item = App::hoveredLinkItem()
|
||||
? App::hoveredLinkItem()
|
||||
: (App::contextItem() ? App::contextItem() : nullptr);
|
||||
doOpen(document(), item, ActionOnLoadPlayInline);
|
||||
}
|
||||
|
||||
@ -428,20 +461,20 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
|
||||
_additional = std::make_unique<SongData>();
|
||||
}
|
||||
}
|
||||
if (voice()) {
|
||||
voice()->duration = d.vduration.v;
|
||||
if (const auto voiceData = voice()) {
|
||||
voiceData->duration = d.vduration.v;
|
||||
VoiceWaveform waveform = documentWaveformDecode(qba(d.vwaveform));
|
||||
uchar wavemax = 0;
|
||||
for (int32 i = 0, l = waveform.size(); i < l; ++i) {
|
||||
uchar waveat = waveform.at(i);
|
||||
if (wavemax < waveat) wavemax = waveat;
|
||||
}
|
||||
voice()->waveform = waveform;
|
||||
voice()->wavemax = wavemax;
|
||||
} else if (song()) {
|
||||
song()->duration = d.vduration.v;
|
||||
song()->title = qs(d.vtitle);
|
||||
song()->performer = qs(d.vperformer);
|
||||
voiceData->waveform = waveform;
|
||||
voiceData->wavemax = wavemax;
|
||||
} else if (const auto songData = song()) {
|
||||
songData->duration = d.vduration.v;
|
||||
songData->title = qs(d.vtitle);
|
||||
songData->performer = qs(d.vperformer);
|
||||
}
|
||||
} break;
|
||||
case mtpc_documentAttributeFilename: {
|
||||
@ -472,7 +505,7 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
|
||||
bool DocumentData::saveToCache() const {
|
||||
return (type == StickerDocument && size < Storage::kMaxStickerInMemory)
|
||||
|| (isAnimation() && size < Storage::kMaxAnimationInMemory)
|
||||
|| (voice() && size < Storage::kMaxVoiceInMemory);
|
||||
|| (isVoiceMessage() && size < Storage::kMaxVoiceInMemory);
|
||||
}
|
||||
|
||||
void DocumentData::forget() {
|
||||
@ -500,7 +533,7 @@ void DocumentData::automaticLoad(const HistoryItem *item) {
|
||||
loadFromCloud = !(cAutoDownloadGif() & dbiadNoPrivate) || !(cAutoDownloadGif() & dbiadNoGroups);
|
||||
}
|
||||
save(QString(), _actionOnLoad, _actionOnLoadMsgId, loadFromCloud ? LoadFromCloudOrLocal : LoadFromLocalOnly, true);
|
||||
} else if (voice()) {
|
||||
} else if (isVoiceMessage()) {
|
||||
if (item) {
|
||||
bool loadFromCloud = false;
|
||||
if (item->history()->peer->isUser()) {
|
||||
@ -515,7 +548,7 @@ void DocumentData::automaticLoad(const HistoryItem *item) {
|
||||
}
|
||||
|
||||
void DocumentData::automaticLoadSettingsChanged() {
|
||||
if (loaded() || status != FileReady || (!isAnimation() && !voice()) || !saveToCache() || _loader != CancelledMtpFileLoader) {
|
||||
if (loaded() || status != FileReady || (!isAnimation() && !isVoiceMessage()) || !saveToCache() || _loader != CancelledMtpFileLoader) {
|
||||
return;
|
||||
}
|
||||
_loader = nullptr;
|
||||
@ -527,9 +560,9 @@ void DocumentData::performActionOnLoad() {
|
||||
auto loc = location(true);
|
||||
auto already = loc.name();
|
||||
auto item = _actionOnLoadMsgId.msg ? App::histItemById(_actionOnLoadMsgId) : nullptr;
|
||||
auto showImage = !isVideo() && (size < App::kImageSizeLimit);
|
||||
auto playVoice = voice() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
||||
auto playMusic = tryPlaySong() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
||||
auto showImage = !isVideoFile() && (size < App::kImageSizeLimit);
|
||||
auto playVoice = isVoiceMessage() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
||||
auto playMusic = isAudioFile() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen);
|
||||
auto playAnimation = isAnimation() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen) && showImage && item && item->getMedia();
|
||||
if (auto applyTheme = isTheme()) {
|
||||
if (!loc.isEmpty() && loc.accessEnable()) {
|
||||
@ -582,7 +615,7 @@ void DocumentData::performActionOnLoad() {
|
||||
if (_actionOnLoad == ActionOnLoadOpenWith) {
|
||||
File::OpenWith(already, QCursor::pos());
|
||||
} else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) {
|
||||
if (voice() || song() || isVideo()) {
|
||||
if (isVoiceMessage() || isAudioFile() || isVideoFile()) {
|
||||
if (documentIsValidMediaFile(already)) {
|
||||
File::Launch(already);
|
||||
}
|
||||
@ -844,7 +877,7 @@ ImagePtr DocumentData::makeReplyPreview() {
|
||||
if (h <= 0) h = 1;
|
||||
auto thumbSize = (w > h) ? QSize(w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : QSize(st::msgReplyBarSize.height(), h * st::msgReplyBarSize.height() / w);
|
||||
thumbSize *= cIntRetinaFactor();
|
||||
auto options = Images::Option::Smooth | (isRoundVideo() ? Images::Option::Circled : Images::Option::None) | Images::Option::TransparentBackground;
|
||||
auto options = Images::Option::Smooth | (isVideoMessage() ? Images::Option::Circled : Images::Option::None) | Images::Option::TransparentBackground;
|
||||
auto outerSize = st::msgReplyBarSize.height();
|
||||
auto image = thumb->pixNoCache(thumbSize.width(), thumbSize.height(), options, outerSize, outerSize);
|
||||
replyPreview = ImagePtr(image, "PNG");
|
||||
@ -855,27 +888,69 @@ ImagePtr DocumentData::makeReplyPreview() {
|
||||
return replyPreview;
|
||||
}
|
||||
|
||||
bool fileIsImage(const QString &name, const QString &mime) {
|
||||
QString lowermime = mime.toLower(), namelower = name.toLower();
|
||||
if (lowermime.startsWith(qstr("image/"))) {
|
||||
return true;
|
||||
} else if (namelower.endsWith(qstr(".bmp"))
|
||||
|| namelower.endsWith(qstr(".jpg"))
|
||||
|| namelower.endsWith(qstr(".jpeg"))
|
||||
|| namelower.endsWith(qstr(".gif"))
|
||||
|| namelower.endsWith(qstr(".webp"))
|
||||
|| namelower.endsWith(qstr(".tga"))
|
||||
|| namelower.endsWith(qstr(".tiff"))
|
||||
|| namelower.endsWith(qstr(".tif"))
|
||||
|| namelower.endsWith(qstr(".psd"))
|
||||
|| namelower.endsWith(qstr(".png"))) {
|
||||
bool DocumentData::isVoiceMessage() const {
|
||||
return (type == VoiceDocument);
|
||||
}
|
||||
|
||||
bool DocumentData::isVideoMessage() const {
|
||||
return (type == RoundVideoDocument);
|
||||
}
|
||||
|
||||
bool DocumentData::isAnimation() const {
|
||||
return (type == AnimatedDocument)
|
||||
|| isVideoMessage()
|
||||
|| hasMimeType(qstr("image/gif"));
|
||||
}
|
||||
|
||||
bool DocumentData::isGifv() const {
|
||||
return (type == AnimatedDocument)
|
||||
&& hasMimeType(qstr("video/mp4"));
|
||||
}
|
||||
|
||||
bool DocumentData::isTheme() const {
|
||||
return
|
||||
_filename.endsWith(
|
||||
qstr(".tdesktop-theme"),
|
||||
Qt::CaseInsensitive)
|
||||
|| _filename.endsWith(
|
||||
qstr(".tdesktop-palette"),
|
||||
Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool DocumentData::isSong() const {
|
||||
return (type == SongDocument);
|
||||
}
|
||||
|
||||
bool DocumentData::isAudioFile() const {
|
||||
if (isVoiceMessage()) {
|
||||
return false;
|
||||
} else if (isSong()) {
|
||||
return true;
|
||||
}
|
||||
return _mimeString.startsWith(qstr("audio/"), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool DocumentData::isSharedMediaMusic() const {
|
||||
if (const auto songData = song()) {
|
||||
return (songData->duration > 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocumentData::isVideoFile() const {
|
||||
return (type == VideoDocument);
|
||||
}
|
||||
|
||||
int32 DocumentData::duration() const {
|
||||
return (isAnimation() || isVideoFile()) ? _duration : -1;
|
||||
}
|
||||
|
||||
bool DocumentData::isImage() const {
|
||||
return !isAnimation() && !isVideoFile() && (_duration > 0);
|
||||
}
|
||||
|
||||
void DocumentData::recountIsImage() {
|
||||
if (isAnimation() || isVideo()) {
|
||||
if (isAnimation() || isVideoFile()) {
|
||||
return;
|
||||
}
|
||||
_duration = fileIsImage(filename(), mimeString()) ? 1 : -1; // hack
|
||||
@ -916,7 +991,7 @@ void DocumentData::collectLocalData(DocumentData *local) {
|
||||
|
||||
if (!local->_data.isEmpty()) {
|
||||
_data = local->_data;
|
||||
if (voice()) {
|
||||
if (isVoiceMessage()) {
|
||||
if (!Local::copyAudio(local->mediaKey(), mediaKey())) {
|
||||
Local::writeAudio(mediaKey(), _data);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public:
|
||||
}
|
||||
}
|
||||
SongData *song() {
|
||||
return (type == SongDocument)
|
||||
return isSong()
|
||||
? static_cast<SongData*>(_additional.get())
|
||||
: nullptr;
|
||||
}
|
||||
@ -171,55 +171,24 @@ public:
|
||||
return const_cast<DocumentData*>(this)->song();
|
||||
}
|
||||
VoiceData *voice() {
|
||||
return (type == VoiceDocument)
|
||||
return isVoiceMessage()
|
||||
? static_cast<VoiceData*>(_additional.get())
|
||||
: nullptr;
|
||||
}
|
||||
const VoiceData *voice() const {
|
||||
return const_cast<DocumentData*>(this)->voice();
|
||||
}
|
||||
bool isRoundVideo() const {
|
||||
return (type == RoundVideoDocument);
|
||||
}
|
||||
bool isAnimation() const {
|
||||
return (type == AnimatedDocument)
|
||||
|| isRoundVideo()
|
||||
|| hasMimeType(qstr("image/gif"));
|
||||
}
|
||||
bool isGifv() const {
|
||||
return (type == AnimatedDocument)
|
||||
&& hasMimeType(qstr("video/mp4"));
|
||||
}
|
||||
bool isTheme() const {
|
||||
return
|
||||
_filename.endsWith(
|
||||
qstr(".tdesktop-theme"),
|
||||
Qt::CaseInsensitive)
|
||||
|| _filename.endsWith(
|
||||
qstr(".tdesktop-palette"),
|
||||
Qt::CaseInsensitive);
|
||||
}
|
||||
bool tryPlaySong() const {
|
||||
return (song() != nullptr)
|
||||
|| _mimeString.startsWith(
|
||||
qstr("audio/"),
|
||||
Qt::CaseInsensitive);
|
||||
}
|
||||
bool isMusic() const {
|
||||
if (auto s = song()) {
|
||||
return (s->duration > 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool isVideo() const {
|
||||
return (type == VideoDocument);
|
||||
}
|
||||
int32 duration() const {
|
||||
return (isAnimation() || isVideo()) ? _duration : -1;
|
||||
}
|
||||
bool isImage() const {
|
||||
return !isAnimation() && !isVideo() && (_duration > 0);
|
||||
}
|
||||
bool isVoiceMessage() const;
|
||||
bool isVideoMessage() const;
|
||||
bool isSong() const;
|
||||
bool isAudioFile() const;
|
||||
bool isVideoFile() const;
|
||||
bool isAnimation() const;
|
||||
bool isGifv() const;
|
||||
bool isTheme() const;
|
||||
bool isSharedMediaMusic() const;
|
||||
int32 duration() const;
|
||||
bool isImage() const;
|
||||
void recountIsImage();
|
||||
void setData(const QByteArray &data) {
|
||||
_data = data;
|
||||
@ -306,9 +275,9 @@ private:
|
||||
friend class Serialize::Document;
|
||||
|
||||
LocationType locationType() const {
|
||||
return voice()
|
||||
return isVoiceMessage()
|
||||
? AudioFileLocation
|
||||
: isVideo()
|
||||
: isVideoFile()
|
||||
? VideoFileLocation
|
||||
: DocumentFileLocation;
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "data/data_document.h"
|
||||
|
||||
void AudioMsgId::setTypeFromAudio() {
|
||||
if (_audio->voice() || _audio->isRoundVideo()) {
|
||||
if (_audio->isVoiceMessage() || _audio->isVideoMessage()) {
|
||||
_type = Type::Voice;
|
||||
} else if (_audio->isVideo()) {
|
||||
} else if (_audio->isVideoFile()) {
|
||||
_type = Type::Video;
|
||||
} else if (_audio->tryPlaySong()) {
|
||||
} else if (_audio->isAudioFile()) {
|
||||
_type = Type::Song;
|
||||
} else {
|
||||
_type = Type::Unknown;
|
||||
|
@ -824,9 +824,9 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.data());
|
||||
auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data());
|
||||
auto lnkPeer = dynamic_cast<PeerClickHandler*>(_contextMenuLink.data());
|
||||
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideo() : false;
|
||||
auto lnkIsAudio = lnkDocument ? (lnkDocument->document()->voice() != nullptr) : false;
|
||||
auto lnkIsSong = lnkDocument ? (lnkDocument->document()->song() != nullptr) : false;
|
||||
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false;
|
||||
auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false;
|
||||
auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false;
|
||||
if (lnkPhoto || lnkDocument) {
|
||||
if (isUponSelected > 0) {
|
||||
_menu->addAction(lang(lng_context_copy_selected), [this] { copySelectedText(); })->setEnabled(true);
|
||||
@ -851,7 +851,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
|
||||
_menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), [this] { showContextInFolder(); })->setEnabled(true);
|
||||
}
|
||||
_menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsAudio ? lng_context_save_audio : (lnkIsSong ? lng_context_save_audio_file : lng_context_save_file))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
||||
_menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsVoice ? lng_context_save_audio : (lnkIsAudio ? lng_context_save_audio_file : lng_context_save_file))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
||||
saveDocumentToFile(document);
|
||||
}))->setEnabled(true);
|
||||
}
|
||||
|
@ -1209,9 +1209,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||
HistoryItem *item = App::hoveredItem() ? App::hoveredItem() : App::hoveredLinkItem();
|
||||
PhotoClickHandler *lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.data());
|
||||
DocumentClickHandler *lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data());
|
||||
bool lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideo() : false;
|
||||
bool lnkIsAudio = lnkDocument ? (lnkDocument->document()->voice() != nullptr) : false;
|
||||
bool lnkIsSong = lnkDocument ? (lnkDocument->document()->song() != nullptr) : false;
|
||||
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false;
|
||||
auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false;
|
||||
auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false;
|
||||
if (lnkPhoto || lnkDocument) {
|
||||
if (isUponSelected > 0) {
|
||||
_menu->addAction(lang((isUponSelected > 1) ? lng_context_copy_selected_items : lng_context_copy_selected), this, SLOT(copySelectedText()))->setEnabled(true);
|
||||
@ -1249,7 +1249,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
|
||||
_menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true);
|
||||
}
|
||||
_menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsAudio ? lng_context_save_audio : (lnkIsSong ? lng_context_save_audio_file : lng_context_save_file))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
||||
_menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsVoice ? lng_context_save_audio : (lnkIsAudio ? lng_context_save_audio_file : lng_context_save_file))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
||||
saveDocumentToFile(document);
|
||||
}))->setEnabled(true);
|
||||
}
|
||||
|
@ -1017,7 +1017,7 @@ QString HistoryItem::directLink() const {
|
||||
if (!channel->isMegagroup()) {
|
||||
if (auto media = getMedia()) {
|
||||
if (auto document = media->getDocument()) {
|
||||
if (document->isRoundVideo()) {
|
||||
if (document->isVideoMessage()) {
|
||||
return qsl("https://telesco.pe/") + query;
|
||||
}
|
||||
}
|
||||
|
@ -105,13 +105,13 @@ namespace {
|
||||
|
||||
int32 documentMaxStatusWidth(DocumentData *document) {
|
||||
int32 result = st::normalFont->width(formatDownloadText(document->size, document->size));
|
||||
if (auto song = document->song()) {
|
||||
if (const auto song = document->song()) {
|
||||
result = qMax(result, st::normalFont->width(formatPlayedText(song->duration, song->duration)));
|
||||
result = qMax(result, st::normalFont->width(formatDurationAndSizeText(song->duration, document->size)));
|
||||
} else if (auto voice = document->voice()) {
|
||||
} else if (const auto voice = document->voice()) {
|
||||
result = qMax(result, st::normalFont->width(formatPlayedText(voice->duration, voice->duration)));
|
||||
result = qMax(result, st::normalFont->width(formatDurationAndSizeText(voice->duration, document->size)));
|
||||
} else if (document->isVideo()) {
|
||||
} else if (document->isVideoFile()) {
|
||||
result = qMax(result, st::normalFont->width(formatDurationAndSizeText(document->duration(), document->size)));
|
||||
} else {
|
||||
result = qMax(result, st::normalFont->width(formatSizeText(document->size)));
|
||||
@ -1080,11 +1080,11 @@ HistoryDocument::HistoryDocument(
|
||||
|
||||
void HistoryDocument::createComponents(bool caption) {
|
||||
uint64 mask = 0;
|
||||
if (_data->voice()) {
|
||||
if (_data->isVoiceMessage()) {
|
||||
mask |= HistoryDocumentVoice::Bit();
|
||||
} else {
|
||||
mask |= HistoryDocumentNamed::Bit();
|
||||
if (!_data->song()
|
||||
if (!_data->isSong()
|
||||
&& !documentIsExecutableName(_data->filename())
|
||||
&& !_data->thumb->isNull()
|
||||
&& _data->thumb->width()
|
||||
@ -1137,7 +1137,7 @@ void HistoryDocument::initDimensions() {
|
||||
} else {
|
||||
tleft = st::msgFilePadding.left() + st::msgFileSize + st::msgFilePadding.right();
|
||||
tright = st::msgFileThumbPadding.left();
|
||||
auto unread = _data->voice() ? (st::mediaUnreadSkip + st::mediaUnreadSize) : 0;
|
||||
auto unread = _data->isVoiceMessage() ? (st::mediaUnreadSkip + st::mediaUnreadSize) : 0;
|
||||
_maxw = qMax(_maxw, tleft + documentMaxStatusWidth(_data) + unread + _parent->skipBlockWidth() + st::msgPadding.right());
|
||||
}
|
||||
|
||||
@ -1317,7 +1317,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
|
||||
} else if (radial || _data->loading()) {
|
||||
return &(outbg ? (selected ? st::historyFileOutCancelSelected : st::historyFileOutCancel) : (selected ? st::historyFileInCancelSelected : st::historyFileInCancel));
|
||||
} else if (loaded) {
|
||||
if (_data->song() || _data->voice()) {
|
||||
if (_data->isAudioFile() || _data->isVoiceMessage()) {
|
||||
return &(outbg ? (selected ? st::historyFileOutPlaySelected : st::historyFileOutPlay) : (selected ? st::historyFileInPlaySelected : st::historyFileInPlay));
|
||||
} else if (_data->isImage()) {
|
||||
return &(outbg ? (selected ? st::historyFileOutImageSelected : st::historyFileOutImage) : (selected ? st::historyFileInImageSelected : st::historyFileInImage));
|
||||
@ -1335,8 +1335,8 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
const VoiceWaveform *wf = nullptr;
|
||||
uchar norm_value = 0;
|
||||
if (_data->voice()) {
|
||||
wf = &_data->voice()->waveform;
|
||||
if (const auto voiceData = _data->voice()) {
|
||||
wf = &voiceData->waveform;
|
||||
if (wf->isEmpty()) {
|
||||
wf = nullptr;
|
||||
if (loaded) {
|
||||
@ -1345,7 +1345,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection,
|
||||
} else if (wf->at(0) < 0) {
|
||||
wf = nullptr;
|
||||
} else {
|
||||
norm_value = _data->voice()->wavemax;
|
||||
norm_value = voiceData->wavemax;
|
||||
}
|
||||
}
|
||||
auto progress = ([voice] {
|
||||
@ -1564,11 +1564,11 @@ TextWithEntities HistoryDocument::selectedText(TextSelection selection) const {
|
||||
|
||||
Storage::SharedMediaTypesMask HistoryDocument::sharedMediaTypes() const {
|
||||
using Type = Storage::SharedMediaType;
|
||||
if (_data->voice()) {
|
||||
if (_data->isVoiceMessage()) {
|
||||
return Storage::SharedMediaTypesMask{}
|
||||
.added(Type::VoiceFile)
|
||||
.added(Type::RoundVoiceFile);
|
||||
} else if (_data->isMusic()) {
|
||||
} else if (_data->isSharedMediaMusic()) {
|
||||
return Type::MusicFile;
|
||||
}
|
||||
return Type::File;
|
||||
@ -1584,7 +1584,7 @@ void HistoryDocument::buildStringRepresentation(Callback callback) const {
|
||||
QString attachType = lang(lng_in_dlg_file);
|
||||
if (Has<HistoryDocumentVoice>()) {
|
||||
attachType = lang(lng_in_dlg_audio);
|
||||
} else if (_data->song()) {
|
||||
} else if (_data->isAudioFile()) {
|
||||
attachType = lang(lng_in_dlg_audio_file);
|
||||
}
|
||||
|
||||
@ -1598,7 +1598,11 @@ void HistoryDocument::buildStringRepresentation(Callback callback) const {
|
||||
}
|
||||
|
||||
void HistoryDocument::setStatusSize(int32 newSize, qint64 realDuration) const {
|
||||
int32 duration = _data->song() ? _data->song()->duration : (_data->voice() ? _data->voice()->duration : -1);
|
||||
int32 duration = _data->isSong()
|
||||
? _data->song()->duration
|
||||
: (_data->isVoiceMessage()
|
||||
? _data->voice()->duration
|
||||
: -1);
|
||||
HistoryFileMedia::setStatusSize(newSize, _data->size, duration, realDuration);
|
||||
if (auto thumbed = Get<HistoryDocumentThumbed>()) {
|
||||
if (_statusSize == FileStatusSizeReady) {
|
||||
@ -1628,7 +1632,7 @@ bool HistoryDocument::updateStatusText() const {
|
||||
} else if (_data->loaded()) {
|
||||
using State = Media::Player::State;
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
if (_data->voice()) {
|
||||
if (_data->isVoiceMessage()) {
|
||||
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Voice);
|
||||
if (state.id == AudioMsgId(_data, _parent->fullId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
||||
if (auto voice = Get<HistoryDocumentVoice>()) {
|
||||
@ -1658,7 +1662,7 @@ bool HistoryDocument::updateStatusText() const {
|
||||
if (!showPause && (state.id == AudioMsgId(_data, _parent->fullId()))) {
|
||||
showPause = Media::Player::instance()->isSeeking(AudioMsgId::Type::Voice);
|
||||
}
|
||||
} else if (_data->song()) {
|
||||
} else if (_data->isAudioFile()) {
|
||||
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
|
||||
if (state.id == AudioMsgId(_data, _parent->fullId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
||||
statusSize = -1 - (state.position / state.frequency);
|
||||
@ -1723,10 +1727,10 @@ void HistoryDocument::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool
|
||||
}
|
||||
|
||||
bool HistoryDocument::playInline(bool autoplay) {
|
||||
if (_data->voice()) {
|
||||
if (_data->isVoiceMessage()) {
|
||||
DocumentOpenClickHandler::doOpen(_data, _parent, ActionOnLoadPlayInline);
|
||||
return true;
|
||||
} else if (_data->song()) {
|
||||
} else if (_data->isAudioFile()) {
|
||||
Media::Player::instance()->play(AudioMsgId(_data, _parent->fullId()));
|
||||
return true;
|
||||
}
|
||||
@ -1750,7 +1754,7 @@ void HistoryDocument::updateSentMedia(const MTPMessageMedia &media) {
|
||||
}
|
||||
App::feedDocument(mediaDocument.vdocument, _data);
|
||||
if (!_data->data().isEmpty()) {
|
||||
if (_data->voice()) {
|
||||
if (_data->isVoiceMessage()) {
|
||||
Local::writeAudio(_data->mediaKey(), _data->data());
|
||||
} else {
|
||||
Local::writeStickerImage(_data->mediaKey(), _data->data());
|
||||
@ -1774,7 +1778,7 @@ HistoryGif::HistoryGif(not_null<HistoryItem*> parent, DocumentData *document, co
|
||||
|
||||
setStatusSize(FileStatusSizeReady);
|
||||
|
||||
if (!caption.isEmpty() && !_data->isRoundVideo()) {
|
||||
if (!caption.isEmpty() && !_data->isVideoMessage()) {
|
||||
_caption.setText(st::messageTextStyle, caption + _parent->skipBlock(), itemTextNoMonoOptions(_parent));
|
||||
}
|
||||
|
||||
@ -1899,7 +1903,7 @@ int HistoryGif::resizeGetHeight(int width) {
|
||||
_width = qMax(_width, _parent->infoWidth() + 2 * int32(st::msgDateImgDelta + st::msgDateImgPadding.x()));
|
||||
if (_gif && _gif->ready()) {
|
||||
if (!_gif->started()) {
|
||||
auto isRound = _data->isRoundVideo();
|
||||
auto isRound = _data->isVideoMessage();
|
||||
auto inWebPage = (_parent->getMedia() != this);
|
||||
auto roundRadius = isRound ? ImageRoundRadius::Ellipse : inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large;
|
||||
auto roundCorners = (isRound || inWebPage) ? ImageRoundCorner::All : ((isBubbleTop() ? (ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight) : ImageRoundCorner::None)
|
||||
@ -1961,7 +1965,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
|
||||
|
||||
auto captionw = width - st::msgPadding.left() - st::msgPadding.right();
|
||||
|
||||
auto isRound = _data->isRoundVideo();
|
||||
auto isRound = _data->isVideoMessage();
|
||||
auto displayMute = false;
|
||||
auto animating = (_gif && _gif->started());
|
||||
|
||||
@ -2244,7 +2248,7 @@ HistoryTextState HistoryGif::getState(QPoint point, HistoryStateRequest request)
|
||||
}
|
||||
auto outbg = _parent->hasOutLayout();
|
||||
auto isChildMedia = (_parent->getMedia() != this);
|
||||
auto isRound = _data->isRoundVideo();
|
||||
auto isRound = _data->isVideoMessage();
|
||||
auto usew = width, usex = 0;
|
||||
auto separateRoundVideo = isSeparateRoundVideo();
|
||||
auto via = separateRoundVideo ? _parent->Get<HistoryMessageVia>() : nullptr;
|
||||
@ -2315,7 +2319,7 @@ HistoryTextState HistoryGif::getState(QPoint point, HistoryStateRequest request)
|
||||
if (QRect(usex + skipx, skipy, usew, height).contains(point)) {
|
||||
if (_data->uploading()) {
|
||||
result.link = _cancell;
|
||||
} else if (!_gif || !cAutoPlayGif() || _data->isRoundVideo()) {
|
||||
} else if (!_gif || !cAutoPlayGif() || _data->isVideoMessage()) {
|
||||
result.link = _data->loaded() ? _openl : (_data->loading() ? _cancell : _savel);
|
||||
} else {
|
||||
result.link = _openInMediaviewLink;
|
||||
@ -2373,7 +2377,7 @@ TextWithEntities HistoryGif::selectedText(TextSelection selection) const {
|
||||
}
|
||||
|
||||
bool HistoryGif::needsBubble() const {
|
||||
if (_data->isRoundVideo()) {
|
||||
if (_data->isVideoMessage()) {
|
||||
return false;
|
||||
}
|
||||
if (!_caption.isEmpty()) {
|
||||
@ -2390,7 +2394,7 @@ bool HistoryGif::needsBubble() const {
|
||||
|
||||
Storage::SharedMediaTypesMask HistoryGif::sharedMediaTypes() const {
|
||||
using Type = Storage::SharedMediaType;
|
||||
if (_data->isRoundVideo()) {
|
||||
if (_data->isVideoMessage()) {
|
||||
return Storage::SharedMediaTypesMask{}
|
||||
.added(Type::RoundFile)
|
||||
.added(Type::RoundVoiceFile);
|
||||
@ -2401,15 +2405,19 @@ Storage::SharedMediaTypesMask HistoryGif::sharedMediaTypes() const {
|
||||
}
|
||||
|
||||
QString HistoryGif::mediaTypeString() const {
|
||||
return _data->isRoundVideo() ? lang(lng_in_dlg_video_message) : qsl("GIF");
|
||||
return _data->isVideoMessage()
|
||||
? lang(lng_in_dlg_video_message)
|
||||
: qsl("GIF");
|
||||
}
|
||||
|
||||
bool HistoryGif::isSeparateRoundVideo() const {
|
||||
return _data->isRoundVideo() && (_parent->getMedia() == this) && !_parent->hasBubble();
|
||||
return _data->isVideoMessage()
|
||||
&& (_parent->getMedia() == this)
|
||||
&& !_parent->hasBubble();
|
||||
}
|
||||
|
||||
void HistoryGif::setStatusSize(int32 newSize) const {
|
||||
if (_data->isRoundVideo()) {
|
||||
if (_data->isVideoMessage()) {
|
||||
_statusSize = newSize;
|
||||
if (newSize < 0) {
|
||||
_statusText = formatDurationText(-newSize - 1);
|
||||
@ -2460,7 +2468,7 @@ void HistoryGif::updateStatusText() const {
|
||||
}
|
||||
|
||||
QString HistoryGif::additionalInfoString() const {
|
||||
if (_data->isRoundVideo()) {
|
||||
if (_data->isVideoMessage()) {
|
||||
updateStatusText();
|
||||
return _statusText;
|
||||
}
|
||||
@ -2509,7 +2517,7 @@ int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessa
|
||||
|
||||
bool HistoryGif::playInline(bool autoplay) {
|
||||
using Mode = Media::Clip::Reader::Mode;
|
||||
if (_data->isRoundVideo() && _gif) {
|
||||
if (_data->isVideoMessage() && _gif) {
|
||||
// Stop autoplayed silent video when we start playback by click.
|
||||
// Stop finished video message when autoplay starts.
|
||||
if (!autoplay) {
|
||||
@ -2529,7 +2537,9 @@ bool HistoryGif::playInline(bool autoplay) {
|
||||
if (!cAutoPlayGif()) {
|
||||
App::stopGifItems();
|
||||
}
|
||||
auto mode = (!autoplay && _data->isRoundVideo()) ? Mode::Video : Mode::Gif;
|
||||
const auto mode = (!autoplay && _data->isVideoMessage())
|
||||
? Mode::Video
|
||||
: Mode::Gif;
|
||||
setClipReader(Media::Clip::MakeReader(_data, _parent->fullId(), [this](Media::Clip::Notification notification) {
|
||||
_parent->clipCallback(notification);
|
||||
}, mode));
|
||||
@ -3262,7 +3272,7 @@ void HistoryWebPage::initDimensions() {
|
||||
_attach = std::make_unique<HistorySticker>(_parent, _data->document);
|
||||
} else if (_data->document->isAnimation()) {
|
||||
_attach = std::make_unique<HistoryGif>(_parent, _data->document, QString());
|
||||
} else if (_data->document->isVideo()) {
|
||||
} else if (_data->document->isVideoFile()) {
|
||||
_attach = std::make_unique<HistoryVideo>(_parent, _data->document, QString());
|
||||
} else {
|
||||
_attach = std::make_unique<HistoryDocument>(_parent, _data->document, QString());
|
||||
@ -3788,7 +3798,7 @@ void HistoryGame::initDimensions() {
|
||||
_attach = std::make_unique<HistorySticker>(_parent, _data->document);
|
||||
} else if (_data->document->isAnimation()) {
|
||||
_attach = std::make_unique<HistoryGif>(_parent, _data->document, QString());
|
||||
} else if (_data->document->isVideo()) {
|
||||
} else if (_data->document->isVideoFile()) {
|
||||
_attach = std::make_unique<HistoryVideo>(_parent, _data->document, QString());
|
||||
} else {
|
||||
_attach = std::make_unique<HistoryDocument>(_parent, _data->document, QString());
|
||||
|
@ -71,7 +71,7 @@ protected:
|
||||
}
|
||||
if (inlinegif) {
|
||||
save = MakeShared<GifOpenClickHandler>(document);
|
||||
} else if (document->voice()) {
|
||||
} else if (document->isVoiceMessage()) {
|
||||
save = MakeShared<DocumentOpenClickHandler>(document);
|
||||
} else {
|
||||
save = MakeShared<DocumentSaveClickHandler>(document);
|
||||
@ -373,7 +373,11 @@ public:
|
||||
HistoryDocument(not_null<HistoryItem*> parent, DocumentData *document, const QString &caption);
|
||||
HistoryDocument(not_null<HistoryItem*> parent, const HistoryDocument &other);
|
||||
HistoryMediaType type() const override {
|
||||
return _data->voice() ? MediaTypeVoiceFile : (_data->song() ? MediaTypeMusicFile : MediaTypeFile);
|
||||
return _data->isVoiceMessage()
|
||||
? MediaTypeVoiceFile
|
||||
: (_data->isSong()
|
||||
? MediaTypeMusicFile
|
||||
: MediaTypeFile);
|
||||
}
|
||||
std::unique_ptr<HistoryMedia> clone(HistoryItem *newParent) const override {
|
||||
return std::make_unique<HistoryDocument>(newParent, *this);
|
||||
@ -445,7 +449,7 @@ public:
|
||||
}
|
||||
QMargins bubbleMargins() const override;
|
||||
bool hideForwardedFrom() const override {
|
||||
return _data->song();
|
||||
return _data->isSong();
|
||||
}
|
||||
bool canEditCaption() const override {
|
||||
return true;
|
||||
@ -556,7 +560,7 @@ public:
|
||||
return isBubbleBottom() && _caption.isEmpty();
|
||||
}
|
||||
bool canEditCaption() const override {
|
||||
return !_data->isRoundVideo();
|
||||
return !_data->isVideoMessage();
|
||||
}
|
||||
bool isReadyForOpen() const override {
|
||||
return _data->loaded();
|
||||
|
@ -128,7 +128,7 @@ bool HasMediaItems(const HistoryItemsList &items) {
|
||||
case MediaTypeFile:
|
||||
case MediaTypeMusicFile:
|
||||
case MediaTypeVoiceFile: return true;
|
||||
case MediaTypeGif: return media->getDocument()->isRoundVideo();
|
||||
case MediaTypeGif: return media->getDocument()->isVideoMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ bool HasGifItems(const HistoryItemsList &items) {
|
||||
for (const auto item : items) {
|
||||
if (const auto media = item->getMedia()) {
|
||||
switch (media->type()) {
|
||||
case MediaTypeGif: return !media->getDocument()->isRoundVideo();
|
||||
case MediaTypeGif: return !media->getDocument()->isVideoMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1131,7 +1131,7 @@ void HistoryMessage::initMediaFromDocument(DocumentData *doc, const QString &cap
|
||||
_media = std::make_unique<HistorySticker>(this, doc);
|
||||
} else if (doc->isAnimation()) {
|
||||
_media = std::make_unique<HistoryGif>(this, doc, caption);
|
||||
} else if (doc->isVideo()) {
|
||||
} else if (doc->isVideoFile()) {
|
||||
_media = std::make_unique<HistoryVideo>(this, doc, caption);
|
||||
} else {
|
||||
_media = std::make_unique<HistoryDocument>(this, doc, caption);
|
||||
|
@ -290,7 +290,7 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
|
||||
case MediaTypeFile: return lang(lng_action_pinned_media_file);
|
||||
case MediaTypeGif: {
|
||||
if (auto document = media->getDocument()) {
|
||||
if (document->isRoundVideo()) {
|
||||
if (document->isVideoMessage()) {
|
||||
return lang(lng_action_pinned_media_video_message);
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ MTPVector<MTPDocumentAttribute> composeDocumentAttributes(DocumentData *document
|
||||
int32 duration = document->duration();
|
||||
if (duration >= 0) {
|
||||
auto flags = MTPDdocumentAttributeVideo::Flags(0);
|
||||
if (document->isRoundVideo()) {
|
||||
if (document->isVideoMessage()) {
|
||||
flags |= MTPDdocumentAttributeVideo::Flag::f_round_message;
|
||||
}
|
||||
attributes.push_back(MTP_documentAttributeVideo(MTP_flags(flags), MTP_int(duration), MTP_int(document->dimensions.width()), MTP_int(document->dimensions.height())));
|
||||
@ -122,12 +122,12 @@ MTPVector<MTPDocumentAttribute> composeDocumentAttributes(DocumentData *document
|
||||
attributes.push_back(MTP_documentAttributeAnimated());
|
||||
} else if (document->type == StickerDocument && document->sticker()) {
|
||||
attributes.push_back(MTP_documentAttributeSticker(MTP_flags(0), MTP_string(document->sticker()->alt), document->sticker()->set, MTPMaskCoords()));
|
||||
} else if (document->type == SongDocument && document->song()) {
|
||||
} else if (const auto song = document->song()) {
|
||||
auto flags = MTPDdocumentAttributeAudio::Flag::f_title | MTPDdocumentAttributeAudio::Flag::f_performer;
|
||||
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(document->song()->duration), MTP_string(document->song()->title), MTP_string(document->song()->performer), MTPstring()));
|
||||
} else if (document->type == VoiceDocument && document->voice()) {
|
||||
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(song->duration), MTP_string(song->title), MTP_string(song->performer), MTPstring()));
|
||||
} else if (const auto voice = document->voice()) {
|
||||
auto flags = MTPDdocumentAttributeAudio::Flag::f_voice | MTPDdocumentAttributeAudio::Flag::f_waveform;
|
||||
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(document->voice()->duration), MTPstring(), MTPstring(), MTP_bytes(documentWaveformEncode5bit(document->voice()->waveform))));
|
||||
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(voice->duration), MTPstring(), MTPstring(), MTP_bytes(documentWaveformEncode5bit(voice->waveform))));
|
||||
}
|
||||
return MTP_vector<MTPDocumentAttribute>(attributes);
|
||||
}
|
||||
@ -4530,7 +4530,7 @@ void HistoryWidget::onDocumentProgress(const FullMsgId &newId) {
|
||||
if (const auto item = App::histItemById(newId)) {
|
||||
const auto media = item->getMedia();
|
||||
const auto document = media ? media->getDocument() : nullptr;
|
||||
const auto sendAction = (document && document->voice())
|
||||
const auto sendAction = (document && document->isVoiceMessage())
|
||||
? SendAction::Type::UploadVoice
|
||||
: SendAction::Type::UploadFile;
|
||||
updateSendAction(
|
||||
@ -4552,7 +4552,7 @@ void HistoryWidget::onDocumentFailed(const FullMsgId &newId) {
|
||||
if (const auto item = App::histItemById(newId)) {
|
||||
const auto media = item->getMedia();
|
||||
const auto document = media ? media->getDocument() : nullptr;
|
||||
const auto sendAction = (document && document->voice())
|
||||
const auto sendAction = (document && document->isVoiceMessage())
|
||||
? SendAction::Type::UploadVoice
|
||||
: SendAction::Type::UploadFile;
|
||||
updateSendAction(item->history(), sendAction, -1);
|
||||
|
@ -1238,13 +1238,13 @@ void ListWidget::showContextMenu(
|
||||
auto photoLink = dynamic_cast<PhotoClickHandler*>(link.data());
|
||||
auto fileLink = dynamic_cast<DocumentClickHandler*>(link.data());
|
||||
if (photoLink || fileLink) {
|
||||
auto [isVideo, isVoice, isSong] = [&] {
|
||||
auto [isVideo, isVoice, isAudio] = [&] {
|
||||
if (fileLink) {
|
||||
auto document = fileLink->document();
|
||||
return std::make_tuple(
|
||||
document->isVideo(),
|
||||
(document->voice() != nullptr),
|
||||
(document->song() != nullptr)
|
||||
document->isVideoFile(),
|
||||
document->isVoiceMessage(),
|
||||
document->isAudioFile()
|
||||
);
|
||||
}
|
||||
return std::make_tuple(false, false, false);
|
||||
@ -1285,7 +1285,7 @@ void ListWidget::showContextMenu(
|
||||
? lng_context_save_video
|
||||
: isVoice
|
||||
? lng_context_save_audio
|
||||
: isSong
|
||||
: isAudio
|
||||
? lng_context_save_audio_file
|
||||
: lng_context_save_file),
|
||||
std::move(handler));
|
||||
|
@ -75,10 +75,10 @@ int FileBase::content_height() const {
|
||||
}
|
||||
|
||||
int FileBase::content_duration() const {
|
||||
if (DocumentData *document = getShownDocument()) {
|
||||
if (const auto document = getShownDocument()) {
|
||||
if (document->duration() > 0) {
|
||||
return document->duration();
|
||||
} else if (SongData *song = document->song()) {
|
||||
} else if (const auto song = document->song()) {
|
||||
if (song->duration) {
|
||||
return song->duration;
|
||||
}
|
||||
@ -750,7 +750,7 @@ void File::paint(Painter &p, const QRect &clip, const PaintContext *context) con
|
||||
} else if (true || document->loaded()) {
|
||||
if (document->isImage()) {
|
||||
return &st::historyFileInImage;
|
||||
} else if (document->voice() || document->song()) {
|
||||
} else if (document->isVoiceMessage() || document->isAudioFile()) {
|
||||
return &st::historyFileInPlay;
|
||||
}
|
||||
return &st::historyFileInDocument;
|
||||
@ -850,7 +850,7 @@ bool File::updateStatusText() const {
|
||||
statusSize = document->loadOffset();
|
||||
} else if (document->loaded()) {
|
||||
using State = Media::Player::State;
|
||||
if (document->voice()) {
|
||||
if (document->isVoiceMessage()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Voice);
|
||||
if (state.id == AudioMsgId(document, FullMsgId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
||||
@ -858,7 +858,7 @@ bool File::updateStatusText() const {
|
||||
realDuration = (state.length / state.frequency);
|
||||
showPause = (state.state == State::Playing || state.state == State::Resuming || state.state == State::Starting);
|
||||
}
|
||||
} else if (document->song()) {
|
||||
} else if (document->isAudioFile()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
|
||||
if (state.id == AudioMsgId(document, FullMsgId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
||||
@ -876,7 +876,11 @@ bool File::updateStatusText() const {
|
||||
statusSize = FileStatusSizeReady;
|
||||
}
|
||||
if (statusSize != _statusSize) {
|
||||
int32 duration = document->song() ? document->song()->duration : (document->voice() ? document->voice()->duration : -1);
|
||||
int32 duration = document->isSong()
|
||||
? document->song()->duration
|
||||
: (document->isVoiceMessage()
|
||||
? document->voice()->duration
|
||||
: -1);
|
||||
setStatusSize(statusSize, document->size, duration, realDuration);
|
||||
}
|
||||
return showPause;
|
||||
|
@ -138,9 +138,12 @@ QString SendFile::getErrorOnSend(const Result *owner, History *history) const {
|
||||
if (auto megagroup = history->peer->asMegagroup()) {
|
||||
if (megagroup->restricted(ChannelRestriction::f_send_media)) {
|
||||
return lang(lng_restricted_send_media);
|
||||
} else if (megagroup->restricted(ChannelRestriction::f_send_stickers) && (_document->sticker() != nullptr)) {
|
||||
} else if (megagroup->restricted(ChannelRestriction::f_send_stickers)
|
||||
&& (_document->sticker() != nullptr)) {
|
||||
return lang(lng_restricted_send_stickers);
|
||||
} else if (megagroup->restricted(ChannelRestriction::f_send_gifs) && _document->isAnimation() && !_document->isRoundVideo()) {
|
||||
} else if (megagroup->restricted(ChannelRestriction::f_send_gifs)
|
||||
&& _document->isAnimation()
|
||||
&& !_document->isVideoMessage()) {
|
||||
return lang(lng_restricted_send_gifs);
|
||||
}
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ void MainWidget::checkCurrentFloatPlayer() {
|
||||
if (auto item = App::histItemById(fullId)) {
|
||||
if (auto media = item->getMedia()) {
|
||||
if (auto document = media->getDocument()) {
|
||||
if (document->isRoundVideo()) {
|
||||
if (document->isVideoMessage()) {
|
||||
_playerFloats.push_back(std::make_unique<Float>(this, item, [this](not_null<Float*> instance, bool visible) {
|
||||
instance->hiddenByWidget = !visible;
|
||||
toggleFloatPlayer(instance);
|
||||
@ -1853,7 +1853,7 @@ void MainWidget::documentLoadProgress(DocumentData *document) {
|
||||
}
|
||||
Auth().documentUpdated.notify(document, true);
|
||||
|
||||
if (!document->loaded() && document->song()) {
|
||||
if (!document->loaded() && document->isAudioFile()) {
|
||||
Media::Player::instance()->documentLoadProgress(document);
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ void CoverWidget::updateRepeatTrackIcon() {
|
||||
}
|
||||
|
||||
void CoverWidget::handleSongUpdate(const TrackState &state) {
|
||||
if (!state.id.audio() || !state.id.audio()->song()) {
|
||||
if (!state.id.audio() || !state.id.audio()->isAudioFile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -282,8 +282,8 @@ void CoverWidget::updateTimeText(const TrackState &state) {
|
||||
if (!IsStoppedOrStopping(state.state)) {
|
||||
display = position = state.position;
|
||||
length = state.length;
|
||||
} else {
|
||||
length = state.length ? state.length : (state.id.audio()->song()->duration * frequency);
|
||||
} else if (const auto songData = state.id.audio()->song()) {
|
||||
length = state.length ? state.length : (songData->duration * frequency);
|
||||
}
|
||||
|
||||
_lastDurationMs = (state.length * 1000LL) / frequency;
|
||||
@ -316,18 +316,23 @@ void CoverWidget::updateTimeLabel() {
|
||||
}
|
||||
|
||||
void CoverWidget::handleSongChange() {
|
||||
auto current = instance()->current(AudioMsgId::Type::Song);
|
||||
auto song = current.audio()->song();
|
||||
if (!song) {
|
||||
const auto current = instance()->current(AudioMsgId::Type::Song);
|
||||
const auto document = current.audio();
|
||||
if (!current || !document) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextWithEntities textWithEntities;
|
||||
if (song->performer.isEmpty()) {
|
||||
const auto song = document ? document->song() : nullptr;
|
||||
if (!song) {
|
||||
textWithEntities.text = document->filename().isEmpty()
|
||||
? qsl("Unknown Track")
|
||||
: document->filename();
|
||||
} else if (song->performer.isEmpty()) {
|
||||
textWithEntities.text = song->title.isEmpty()
|
||||
? (current.audio()->filename().isEmpty()
|
||||
? (document->filename().isEmpty()
|
||||
? qsl("Unknown Track")
|
||||
: current.audio()->filename())
|
||||
: document->filename())
|
||||
: song->title;
|
||||
} else {
|
||||
auto title = song->title.isEmpty()
|
||||
|
@ -47,7 +47,7 @@ Float::Float(
|
||||
|
||||
auto document = media->getDocument();
|
||||
Assert(document != nullptr);
|
||||
Assert(document->isRoundVideo());
|
||||
Assert(document->isVideoMessage());
|
||||
|
||||
auto margin = st::mediaPlayerFloatMargin;
|
||||
auto size = 2 * margin + st::mediaPlayerFloatSize;
|
||||
|
@ -239,7 +239,7 @@ bool Instance::moveInPlaylist(
|
||||
item->fullId()
|
||||
});
|
||||
}
|
||||
if (document->tryPlaySong()) {
|
||||
if (document->isAudioFile()) {
|
||||
play(AudioMsgId(document, item->fullId()));
|
||||
} else {
|
||||
DocumentOpenClickHandler::doOpen(
|
||||
@ -298,18 +298,19 @@ void Instance::play(AudioMsgId::Type type) {
|
||||
}
|
||||
|
||||
void Instance::play(const AudioMsgId &audioId) {
|
||||
if (!audioId) {
|
||||
const auto document = audioId.audio();
|
||||
if (!audioId || !document) {
|
||||
return;
|
||||
}
|
||||
if (audioId.audio()->tryPlaySong() || audioId.audio()->voice()) {
|
||||
if (document->isAudioFile() || document->isVoiceMessage()) {
|
||||
mixer()->play(audioId);
|
||||
setCurrent(audioId);
|
||||
if (audioId.audio()->loading()) {
|
||||
documentLoadProgress(audioId.audio());
|
||||
if (document->loading()) {
|
||||
documentLoadProgress(document);
|
||||
}
|
||||
} else if (audioId.audio()->isRoundVideo()) {
|
||||
if (auto item = App::histItemById(audioId.contextId())) {
|
||||
if (auto media = item->getMedia()) {
|
||||
} else if (document->isVideoMessage()) {
|
||||
if (const auto item = App::histItemById(audioId.contextId())) {
|
||||
if (const auto media = item->getMedia()) {
|
||||
media->playInline();
|
||||
}
|
||||
}
|
||||
@ -395,7 +396,7 @@ void Instance::stopSeeking(AudioMsgId::Type type) {
|
||||
}
|
||||
|
||||
void Instance::documentLoadProgress(DocumentData *document) {
|
||||
const auto type = document->tryPlaySong()
|
||||
const auto type = document->isAudioFile()
|
||||
? AudioMsgId::Type::Song
|
||||
: AudioMsgId::Type::Voice;
|
||||
emitUpdate(type, [document](const AudioMsgId &audioId) {
|
||||
|
@ -23,6 +23,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "media/player/media_player_cover.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "info/media/info_media_list_widget.h"
|
||||
#include "history/history_media.h"
|
||||
#include "data/data_document.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "mainwindow.h"
|
||||
@ -267,14 +269,16 @@ void Panel::refreshList() {
|
||||
const auto contextId = current.contextId();
|
||||
const auto peer = [&]() -> PeerData* {
|
||||
const auto item = contextId ? App::histItemById(contextId) : nullptr;
|
||||
if (item) {
|
||||
const auto result = item->history()->peer;
|
||||
if (const auto migrated = result->migrateTo()) {
|
||||
return migrated;
|
||||
}
|
||||
return result;
|
||||
const auto media = item ? item->getMedia() : nullptr;
|
||||
const auto document = media ? media->getDocument() : nullptr;
|
||||
if (!document || !document->isSharedMediaMusic()) {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
const auto result = item->history()->peer;
|
||||
if (const auto migrated = result->migrateTo()) {
|
||||
return migrated;
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
const auto migrated = peer ? peer->migrateFrom() : nullptr;
|
||||
if (_listPeer != peer || _listMigratedPeer != migrated) {
|
||||
|
@ -431,20 +431,21 @@ void Widget::handleSongUpdate(const TrackState &state) {
|
||||
void Widget::updateTimeText(const TrackState &state) {
|
||||
QString time;
|
||||
qint64 position = 0, length = 0, display = 0;
|
||||
auto frequency = state.frequency;
|
||||
const auto frequency = state.frequency;
|
||||
const auto document = state.id.audio();
|
||||
if (!IsStoppedOrStopping(state.state)) {
|
||||
display = position = state.position;
|
||||
length = state.length;
|
||||
} else if (state.length) {
|
||||
display = state.length;
|
||||
} else if (state.id.audio()->song()) {
|
||||
display = (state.id.audio()->song()->duration * frequency);
|
||||
} else if (const auto song = document->song()) {
|
||||
display = (song->duration * frequency);
|
||||
}
|
||||
|
||||
_lastDurationMs = (state.length * 1000LL) / frequency;
|
||||
|
||||
if (state.id.audio()->loading()) {
|
||||
_time = QString::number(qRound(state.id.audio()->progress() * 100)) + '%';
|
||||
if (document->loading()) {
|
||||
_time = QString::number(qRound(document->progress() * 100)) + '%';
|
||||
_playbackSlider->setDisabled(true);
|
||||
} else {
|
||||
display = display / frequency;
|
||||
@ -470,13 +471,14 @@ void Widget::updateTimeLabel() {
|
||||
}
|
||||
|
||||
void Widget::handleSongChange() {
|
||||
auto current = instance()->current(_type);
|
||||
if (!current || !current.audio()) {
|
||||
const auto current = instance()->current(_type);
|
||||
const auto document = current.audio();
|
||||
if (!current || !document) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextWithEntities textWithEntities;
|
||||
if (current.audio()->voice() || current.audio()->isRoundVideo()) {
|
||||
if (document->isVoiceMessage() || document->isVideoMessage()) {
|
||||
if (auto item = App::histItemById(current.contextId())) {
|
||||
auto name = App::peerName(item->fromOriginal());
|
||||
auto date = [item] {
|
||||
@ -497,12 +499,12 @@ void Widget::handleSongChange() {
|
||||
textWithEntities.text = lang(lng_media_audio);
|
||||
}
|
||||
} else {
|
||||
auto song = current.audio()->song();
|
||||
const auto song = document->song();
|
||||
if (!song || song->performer.isEmpty()) {
|
||||
textWithEntities.text = (!song || song->title.isEmpty())
|
||||
? (current.audio()->filename().isEmpty()
|
||||
? (document->filename().isEmpty()
|
||||
? qsl("Unknown Track")
|
||||
: current.audio()->filename())
|
||||
: document->filename())
|
||||
: song->title;
|
||||
} else {
|
||||
auto title = song->title.isEmpty()
|
||||
|
@ -211,11 +211,11 @@ bool MediaView::fileBubbleShown() const {
|
||||
bool MediaView::gifShown() const {
|
||||
if (_gif && _gif->ready()) {
|
||||
if (!_gif->started()) {
|
||||
if (_doc && (_doc->isVideo() || _doc->isRoundVideo()) && _autoplayVideoDocument != _doc && !_gif->videoPaused()) {
|
||||
if (_doc && (_doc->isVideoFile() || _doc->isVideoMessage()) && _autoplayVideoDocument != _doc && !_gif->videoPaused()) {
|
||||
_gif->pauseResumeVideo();
|
||||
const_cast<MediaView*>(this)->_videoPaused = _gif->videoPaused();
|
||||
}
|
||||
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
auto rounding = (_doc && _doc->isVideoMessage()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
_gif->start(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::All);
|
||||
const_cast<MediaView*>(this)->_current = QPixmap();
|
||||
updateMixerVideoVolume();
|
||||
@ -517,16 +517,16 @@ void MediaView::step_radial(TimeMs ms, bool timer) {
|
||||
if (timer && (wasAnimating || _radial.animating())) {
|
||||
update(radialRect());
|
||||
}
|
||||
if (_doc && _doc->loaded() && _doc->size < App::kImageSizeLimit && (!_radial.animating() || _doc->isAnimation() || _doc->isVideo())) {
|
||||
if (_doc->isVideo() || _doc->isRoundVideo()) {
|
||||
if (_doc && _doc->loaded() && _doc->size < App::kImageSizeLimit && (!_radial.animating() || _doc->isAnimation() || _doc->isVideoFile())) {
|
||||
if (_doc->isVideoFile() || _doc->isVideoMessage()) {
|
||||
_autoplayVideoDocument = _doc;
|
||||
}
|
||||
if (!_doc->data().isEmpty() && (_doc->isAnimation() || _doc->isVideo())) {
|
||||
if (!_doc->data().isEmpty() && (_doc->isAnimation() || _doc->isVideoFile())) {
|
||||
displayDocument(_doc, App::histItemById(_msgid));
|
||||
} else {
|
||||
auto &location = _doc->location(true);
|
||||
if (location.accessEnable()) {
|
||||
if (_doc->isAnimation() || _doc->isVideo() || _doc->isTheme() || QImageReader(location.name()).canRead()) {
|
||||
if (_doc->isAnimation() || _doc->isVideoFile() || _doc->isTheme() || QImageReader(location.name()).canRead()) {
|
||||
displayDocument(_doc, App::histItemById(_msgid));
|
||||
}
|
||||
location.accessDisable();
|
||||
@ -642,7 +642,7 @@ void MediaView::showSaveMsgFile() {
|
||||
}
|
||||
|
||||
void MediaView::updateMixerVideoVolume() const {
|
||||
if (_doc && (_doc->isVideo() || _doc->isRoundVideo())) {
|
||||
if (_doc && (_doc->isVideoFile() || _doc->isVideoMessage())) {
|
||||
Media::Player::mixer()->setVideoVolume(Global::VideoVolume());
|
||||
}
|
||||
}
|
||||
@ -825,7 +825,7 @@ void MediaView::clipCallback(Media::Clip::Notification notification) {
|
||||
_videoStopped = true;
|
||||
updateSilentVideoPlaybackState();
|
||||
} else {
|
||||
_videoIsSilent = _doc && (_doc->isVideo() || _doc->isRoundVideo()) && !_gif->hasAudio();
|
||||
_videoIsSilent = _doc && (_doc->isVideoFile() || _doc->isVideoMessage()) && !_gif->hasAudio();
|
||||
_videoDurationMs = _gif->getDurationMs();
|
||||
_videoPositionMs = _gif->getPositionMs();
|
||||
if (_videoIsSilent) {
|
||||
@ -997,7 +997,7 @@ base::optional<MediaView::SharedMediaType> MediaView::sharedMediaType() const {
|
||||
} else if (_doc) {
|
||||
if (_doc->isGifv()) {
|
||||
return Type::GIF;
|
||||
} else if (_doc->isVideo()) {
|
||||
} else if (_doc->isVideoFile()) {
|
||||
return Type::Video;
|
||||
}
|
||||
return Type::File;
|
||||
@ -1243,7 +1243,7 @@ void MediaView::showDocument(not_null<DocumentData*> document, HistoryItem *cont
|
||||
}
|
||||
if (!_animOpacities.isEmpty()) _animOpacities.clear();
|
||||
|
||||
if (document->isVideo() || document->isRoundVideo()) {
|
||||
if (document->isVideoFile() || document->isVideoMessage()) {
|
||||
_autoplayVideoDocument = document;
|
||||
}
|
||||
displayDocument(document, context);
|
||||
@ -1320,7 +1320,7 @@ void MediaView::destroyThemePreview() {
|
||||
|
||||
void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty messages shown as docs: doc can be NULL
|
||||
auto documentChanged = (!doc || doc != _doc || (item && item->fullId() != _msgid));
|
||||
if (documentChanged || (!doc->isAnimation() && !doc->isVideo())) {
|
||||
if (documentChanged || (!doc->isAnimation() && !doc->isVideoFile())) {
|
||||
_fullScreenVideo = false;
|
||||
_current = QPixmap();
|
||||
stopGif();
|
||||
@ -1352,7 +1352,7 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty
|
||||
} else {
|
||||
_doc->automaticLoad(item);
|
||||
|
||||
if (_doc->isAnimation() || _doc->isVideo()) {
|
||||
if (_doc->isAnimation() || _doc->isVideoFile()) {
|
||||
initAnimation();
|
||||
} else if (_doc->isTheme()) {
|
||||
initThemePreview();
|
||||
@ -1506,7 +1506,7 @@ void MediaView::displayFinished() {
|
||||
|
||||
Images::Options MediaView::videoThumbOptions() const {
|
||||
auto options = Images::Option::Smooth | Images::Option::Blurred;
|
||||
if (_doc && _doc->isRoundVideo()) {
|
||||
if (_doc && _doc->isVideoMessage()) {
|
||||
options |= Images::Option::Circled;
|
||||
}
|
||||
return options;
|
||||
@ -1514,7 +1514,7 @@ Images::Options MediaView::videoThumbOptions() const {
|
||||
|
||||
void MediaView::initAnimation() {
|
||||
Expects(_doc != nullptr);
|
||||
Expects(_doc->isAnimation() || _doc->isVideo());
|
||||
Expects(_doc->isAnimation() || _doc->isVideoFile());
|
||||
|
||||
auto &location = _doc->location(true);
|
||||
if (!_doc->data().isEmpty()) {
|
||||
@ -1536,7 +1536,7 @@ void MediaView::createClipReader() {
|
||||
if (_gif) return;
|
||||
|
||||
Expects(_doc != nullptr);
|
||||
Expects(_doc->isAnimation() || _doc->isVideo());
|
||||
Expects(_doc->isAnimation() || _doc->isVideoFile());
|
||||
|
||||
if (_doc->dimensions.width() && _doc->dimensions.height()) {
|
||||
int w = _doc->dimensions.width();
|
||||
@ -1546,7 +1546,9 @@ void MediaView::createClipReader() {
|
||||
} else {
|
||||
_current = _doc->thumb->pixNoCache(_doc->thumb->width(), _doc->thumb->height(), videoThumbOptions(), st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
||||
}
|
||||
auto mode = (_doc->isVideo() || _doc->isRoundVideo()) ? Media::Clip::Reader::Mode::Video : Media::Clip::Reader::Mode::Gif;
|
||||
auto mode = (_doc->isVideoFile() || _doc->isVideoMessage())
|
||||
? Media::Clip::Reader::Mode::Video
|
||||
: Media::Clip::Reader::Mode::Gif;
|
||||
_gif = Media::Clip::MakeReader(_doc, _msgid, [this](Media::Clip::Notification notification) {
|
||||
clipCallback(notification);
|
||||
}, mode);
|
||||
@ -1605,7 +1607,7 @@ void MediaView::initThemePreview() {
|
||||
|
||||
void MediaView::createClipController() {
|
||||
Expects(_doc != nullptr);
|
||||
if (!_doc->isVideo() && !_doc->isRoundVideo()) return;
|
||||
if (!_doc->isVideoFile() && !_doc->isVideoMessage()) return;
|
||||
|
||||
_clipController.create(this);
|
||||
setClipControllerGeometry();
|
||||
@ -1660,7 +1662,7 @@ void MediaView::restartVideoAtSeekPosition(TimeMs positionMs) {
|
||||
_autoplayVideoDocument = _doc;
|
||||
|
||||
if (_current.isNull()) {
|
||||
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
auto rounding = (_doc && _doc->isVideoMessage()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
_current = _gif->current(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::All, getms());
|
||||
}
|
||||
_gif = Media::Clip::MakeReader(_doc, _msgid, [this](Media::Clip::Notification notification) {
|
||||
@ -1773,7 +1775,7 @@ void MediaView::paintEvent(QPaintEvent *e) {
|
||||
for (int i = 0, l = region.rectCount(); i < l; ++i) {
|
||||
p.fillRect(rs.at(i), st::mediaviewVideoBg);
|
||||
}
|
||||
if (_doc && _doc->isRoundVideo()) {
|
||||
if (_doc && _doc->isVideoMessage()) {
|
||||
p.setCompositionMode(m);
|
||||
}
|
||||
} else {
|
||||
@ -1808,7 +1810,7 @@ void MediaView::paintEvent(QPaintEvent *e) {
|
||||
if (_photo || fileShown()) {
|
||||
QRect imgRect(_x, _y, _w, _h);
|
||||
if (imgRect.intersects(r)) {
|
||||
auto rounding = (_doc && _doc->isRoundVideo()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
auto rounding = (_doc && _doc->isVideoMessage()) ? ImageRoundRadius::Ellipse : ImageRoundRadius::None;
|
||||
auto toDraw = _current.isNull() ? _gif->current(_gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), _gif->width() / cIntRetinaFactor(), _gif->height() / cIntRetinaFactor(), rounding, ImageRoundCorner::None, ms) : _current;
|
||||
if (!_gif && (!_doc || !_doc->sticker() || _doc->sticker()->img->isNull()) && toDraw.hasAlpha()) {
|
||||
p.fillRect(imgRect, _transparentBrush);
|
||||
@ -2150,7 +2152,7 @@ void MediaView::keyPressEvent(QKeyEvent *e) {
|
||||
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
||||
if (_doc && !_doc->loading() && (fileBubbleShown() || !_doc->loaded())) {
|
||||
onDocClick();
|
||||
} else if (_doc && (_doc->isVideo() || _doc->isRoundVideo())) {
|
||||
} else if (_doc && (_doc->isVideoFile() || _doc->isVideoMessage())) {
|
||||
onVideoPauseResume();
|
||||
}
|
||||
} else if (e->key() == Qt::Key_Left) {
|
||||
@ -2570,7 +2572,7 @@ void MediaView::updateOver(QPoint pos) {
|
||||
} else if (_closeNav.contains(pos)) {
|
||||
updateOverState(OverClose);
|
||||
} else if (_doc && fileShown() && QRect(_x, _y, _w, _h).contains(pos)) {
|
||||
if ((_doc->isVideo() || _doc->isRoundVideo()) && _gif) {
|
||||
if ((_doc->isVideoFile() || _doc->isVideoMessage()) && _gif) {
|
||||
updateOverState(OverVideo);
|
||||
} else if (!_doc->loaded()) {
|
||||
updateOverState(OverIcon);
|
||||
|
@ -220,7 +220,7 @@ void Messenger::showPhoto(not_null<PhotoData*> photo, PeerData *peer) {
|
||||
}
|
||||
|
||||
void Messenger::showDocument(not_null<DocumentData*> document, HistoryItem *item) {
|
||||
if (cUseExternalVideoPlayer() && document->isVideo()) {
|
||||
if (cUseExternalVideoPlayer() && document->isVideoFile()) {
|
||||
QDesktopServices::openUrl(QUrl("file:///" + document->location(false).fname));
|
||||
} else {
|
||||
if (_mediaView->isHidden()) {
|
||||
|
@ -50,7 +50,7 @@ TextParseOptions _documentNameOptions = {
|
||||
|
||||
TextWithEntities ComposeNameWithEntities(DocumentData *document) {
|
||||
TextWithEntities result;
|
||||
auto song = document->song();
|
||||
const auto song = document->song();
|
||||
if (!song || (song->title.isEmpty() && song->performer.isEmpty())) {
|
||||
result.text = document->filename().isEmpty()
|
||||
? qsl("Unknown File")
|
||||
@ -185,7 +185,7 @@ void RadialProgressItem::setDocumentLinks(
|
||||
auto createSaveHandler = [](
|
||||
not_null<DocumentData*> document
|
||||
) -> ClickHandlerPtr {
|
||||
if (document->voice()) {
|
||||
if (document->isVoiceMessage()) {
|
||||
return MakeShared<DocumentOpenClickHandler>(document);
|
||||
}
|
||||
return MakeShared<DocumentSaveClickHandler>(document);
|
||||
@ -548,7 +548,7 @@ Voice::Voice(
|
||||
, _st(st) {
|
||||
AddComponents(Info::Bit());
|
||||
|
||||
Assert(_data->voice() != 0);
|
||||
Assert(_data->isVoiceMessage());
|
||||
|
||||
setDocumentLinks(_data);
|
||||
|
||||
@ -799,7 +799,7 @@ Document::Document(
|
||||
|
||||
setDocumentLinks(_data);
|
||||
|
||||
_status.update(FileStatusSizeReady, _data->size, _data->song() ? _data->song()->duration : -1, 0);
|
||||
_status.update(FileStatusSizeReady, _data->size, _data->isSong() ? _data->song()->duration : -1, 0);
|
||||
|
||||
if (withThumb()) {
|
||||
_data->thumb->load();
|
||||
@ -822,7 +822,7 @@ Document::Document(
|
||||
|
||||
void Document::initDimensions() {
|
||||
_maxw = _st.maxWidth;
|
||||
if (_data->song()) {
|
||||
if (_data->isAudioFile()) {
|
||||
_minh = _st.songPadding.top() + _st.songThumbSize + _st.songPadding.bottom();
|
||||
} else {
|
||||
_minh = _st.filePadding.top() + _st.fileThumbSize + _st.filePadding.bottom() + st::lineWidth;
|
||||
@ -847,7 +847,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
|
||||
int32 nameleft = 0, nametop = 0, nameright = 0, statustop = 0, datetop = -1;
|
||||
bool wthumb = withThumb();
|
||||
|
||||
auto isSong = (_data->song() != nullptr);
|
||||
auto isSong = _data->isAudioFile();
|
||||
if (isSong) {
|
||||
nameleft = _st.songPadding.left() + _st.songThumbSize + _st.songPadding.right();
|
||||
nameright = _st.songPadding.left();
|
||||
@ -998,7 +998,7 @@ HistoryTextState Document::getState(
|
||||
|| Local::willStickerImageLoad(_data->mediaKey());
|
||||
const auto wthumb = withThumb();
|
||||
|
||||
if (_data->song()) {
|
||||
if (_data->isAudioFile()) {
|
||||
const auto nameleft = _st.songPadding.left() + _st.songThumbSize + _st.songPadding.right();
|
||||
const auto nameright = _st.songPadding.left();
|
||||
const auto namewidth = std::min(
|
||||
@ -1106,11 +1106,13 @@ bool Document::dataLoaded() const {
|
||||
}
|
||||
|
||||
bool Document::iconAnimated() const {
|
||||
return _data->song() || !_data->loaded() || (_radial && _radial->animating());
|
||||
return _data->isAudioFile()
|
||||
|| !_data->loaded()
|
||||
|| (_radial && _radial->animating());
|
||||
}
|
||||
|
||||
bool Document::withThumb() const {
|
||||
return !_data->song()
|
||||
return !_data->isAudioFile()
|
||||
&& !_data->thumb->isNull()
|
||||
&& _data->thumb->width()
|
||||
&& _data->thumb->height()
|
||||
@ -1127,7 +1129,7 @@ bool Document::updateStatusText() {
|
||||
} else if (_data->loading()) {
|
||||
statusSize = _data->loadOffset();
|
||||
} else if (_data->loaded()) {
|
||||
if (_data->song()) {
|
||||
if (_data->isAudioFile()) {
|
||||
statusSize = FileStatusSizeLoaded;
|
||||
using State = Media::Player::State;
|
||||
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
|
||||
@ -1146,7 +1148,7 @@ bool Document::updateStatusText() {
|
||||
statusSize = FileStatusSizeReady;
|
||||
}
|
||||
if (statusSize != _status.size()) {
|
||||
_status.update(statusSize, _data->size, _data->song() ? _data->song()->duration : -1, realDuration);
|
||||
_status.update(statusSize, _data->size, _data->isSong() ? _data->song()->duration : -1, realDuration);
|
||||
}
|
||||
return showPause;
|
||||
}
|
||||
@ -1327,7 +1329,9 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P
|
||||
}
|
||||
p.drawPixmapLeft(pixLeft, pixTop, _width, pix);
|
||||
} else if (_page && _page->document && !_page->document->thumb->isNull()) {
|
||||
auto roundRadius = _page->document->isRoundVideo() ? ImageRoundRadius::Ellipse : ImageRoundRadius::Small;
|
||||
auto roundRadius = _page->document->isVideoMessage()
|
||||
? ImageRoundRadius::Ellipse
|
||||
: ImageRoundRadius::Small;
|
||||
p.drawPixmapLeft(pixLeft, pixTop, _width, _page->document->thumb->pixSingle(_pixw, _pixh, st::linksPhotoSize, st::linksPhotoSize, roundRadius));
|
||||
} else {
|
||||
const auto index = _letter.isEmpty()
|
||||
|
@ -251,7 +251,7 @@ bool FileLoadTask::CheckForSong(const QString &filepath, const QByteArray &conte
|
||||
if (!CheckMimeOrExtensions(filepath, result->filemime, mimes, extensions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
auto media = Media::Player::PrepareForSending(filepath, content);
|
||||
if (media.duration < 0) {
|
||||
return false;
|
||||
|
@ -3134,7 +3134,7 @@ public:
|
||||
_wavemax = wavemax;
|
||||
}
|
||||
void finish() {
|
||||
if (VoiceData *voice = _doc ? _doc->voice() : 0) {
|
||||
if (const auto voice = _doc ? _doc->voice() : nullptr) {
|
||||
if (!_waveform.isEmpty()) {
|
||||
voice->waveform = _waveform;
|
||||
voice->wavemax = _wavemax;
|
||||
@ -3172,7 +3172,7 @@ protected:
|
||||
};
|
||||
|
||||
void countVoiceWaveform(DocumentData *document) {
|
||||
if (VoiceData *voice = document->voice()) {
|
||||
if (const auto voice = document->voice()) {
|
||||
if (_localLoader) {
|
||||
voice->waveform.resize(1 + sizeof(TaskId));
|
||||
voice->waveform[0] = -1; // counting
|
||||
|
@ -837,7 +837,9 @@ void MediaPreviewWidget::resizeEvent(QResizeEvent *e) {
|
||||
}
|
||||
|
||||
void MediaPreviewWidget::showPreview(DocumentData *document) {
|
||||
if (!document || (!document->isAnimation() && !document->sticker()) || document->isRoundVideo()) {
|
||||
if (!document
|
||||
|| (!document->isAnimation() && !document->sticker())
|
||||
|| document->isVideoMessage()) {
|
||||
hidePreview();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user