1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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->getDuration() >= 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);
}
|