init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
103
Telegram/SourceFiles/data/data_audio_msg_id.cpp
Normal file
103
Telegram/SourceFiles/data/data_audio_msg_id.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/data_audio_msg_id.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto kMinLengthForChangeablePlaybackSpeed = 20 * TimeId(60); // 20 minutes.
|
||||
|
||||
} // namespace
|
||||
|
||||
AudioMsgId::AudioMsgId() {
|
||||
}
|
||||
|
||||
AudioMsgId::AudioMsgId(
|
||||
not_null<DocumentData*> audio,
|
||||
FullMsgId msgId,
|
||||
uint32 externalPlayId)
|
||||
: _audio(audio)
|
||||
, _contextId(msgId)
|
||||
, _externalPlayId(externalPlayId)
|
||||
, _changeablePlaybackSpeed(_audio->isVoiceMessage()
|
||||
|| _audio->isVideoMessage()
|
||||
|| (_audio->duration() >= kMinLengthForChangeablePlaybackSpeed)) {
|
||||
setTypeFromAudio();
|
||||
}
|
||||
|
||||
uint32 AudioMsgId::CreateExternalPlayId() {
|
||||
static auto Result = uint32(0);
|
||||
return ++Result ? Result : ++Result;
|
||||
}
|
||||
|
||||
AudioMsgId AudioMsgId::ForVideo() {
|
||||
auto result = AudioMsgId();
|
||||
result._externalPlayId = CreateExternalPlayId();
|
||||
result._type = Type::Video;
|
||||
return result;
|
||||
}
|
||||
|
||||
void AudioMsgId::setTypeFromAudio() {
|
||||
if (_audio->isVoiceMessage() || _audio->isVideoMessage()) {
|
||||
_type = Type::Voice;
|
||||
} else if (_audio->isVideoFile()) {
|
||||
_type = Type::Video;
|
||||
} else if (_audio->isAudioFile()) {
|
||||
_type = Type::Song;
|
||||
} else {
|
||||
_type = Type::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
AudioMsgId::Type AudioMsgId::type() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
DocumentData *AudioMsgId::audio() const {
|
||||
return _audio;
|
||||
}
|
||||
|
||||
FullMsgId AudioMsgId::contextId() const {
|
||||
return _contextId;
|
||||
}
|
||||
|
||||
uint32 AudioMsgId::externalPlayId() const {
|
||||
return _externalPlayId;
|
||||
}
|
||||
|
||||
bool AudioMsgId::changeablePlaybackSpeed() const {
|
||||
return _changeablePlaybackSpeed;
|
||||
}
|
||||
|
||||
AudioMsgId::operator bool() const {
|
||||
return (_audio != nullptr) || (_externalPlayId != 0);
|
||||
}
|
||||
|
||||
bool AudioMsgId::operator<(const AudioMsgId &other) const {
|
||||
if (quintptr(audio()) < quintptr(other.audio())) {
|
||||
return true;
|
||||
} else if (quintptr(other.audio()) < quintptr(audio())) {
|
||||
return false;
|
||||
} else if (contextId() < other.contextId()) {
|
||||
return true;
|
||||
} else if (other.contextId() < contextId()) {
|
||||
return false;
|
||||
}
|
||||
return (externalPlayId() < other.externalPlayId());
|
||||
}
|
||||
|
||||
bool AudioMsgId::operator==(const AudioMsgId &other) const {
|
||||
return (audio() == other.audio())
|
||||
&& (contextId() == other.contextId())
|
||||
&& (externalPlayId() == other.externalPlayId());
|
||||
}
|
||||
|
||||
bool AudioMsgId::operator!=(const AudioMsgId &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
Reference in New Issue
Block a user