Moved AudioMsgId to separated file.

This commit is contained in:
23rd 2021-08-31 14:26:17 +03:00
parent 22d4331ead
commit e6f0c176f7
10 changed files with 146 additions and 99 deletions

View File

@ -354,6 +354,8 @@ PRIVATE
data/data_abstract_sparse_ids.h
data/data_abstract_structure.cpp
data/data_abstract_structure.h
data/data_audio_msg_id.cpp
data/data_audio_msg_id.h
data/data_auto_download.cpp
data/data_auto_download.h
data/data_chat.cpp

View File

@ -0,0 +1,90 @@
/*
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"
AudioMsgId::AudioMsgId() {
}
AudioMsgId::AudioMsgId(
not_null<DocumentData*> audio,
FullMsgId msgId,
uint32 externalPlayId)
: _audio(audio)
, _contextId(msgId)
, _externalPlayId(externalPlayId) {
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;
}
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);
}

View File

@ -0,0 +1,48 @@
/*
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
*/
#pragma once
class DocumentData;
class AudioMsgId {
public:
enum class Type {
Unknown,
Voice,
Song,
Video,
};
AudioMsgId();
AudioMsgId(
not_null<DocumentData*> audio,
FullMsgId msgId,
uint32 externalPlayId = 0);
[[nodiscard]] static uint32 CreateExternalPlayId();
[[nodiscard]] static AudioMsgId ForVideo();
[[nodiscard]] Type type() const;
[[nodiscard]] DocumentData *audio() const;
[[nodiscard]] FullMsgId contextId() const;
[[nodiscard]] uint32 externalPlayId() const;
[[nodiscard]] explicit operator bool() const;
bool operator<(const AudioMsgId &other) const;
bool operator==(const AudioMsgId &other) const;
bool operator!=(const AudioMsgId &other) const;
private:
void setTypeFromAudio();
DocumentData *_audio = nullptr;
Type _type = Type::Unknown;
FullMsgId _contextId;
uint32 _externalPlayId = 0;
};

View File

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_types.h"
#include "data/data_document.h"
#include "data/data_session.h"
#include "ui/widgets/input_fields.h"
#include "storage/cache/storage_cache_types.h"
@ -90,30 +89,6 @@ Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location) {
} // namespace Data
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;
}
}
void MessageCursor::fillFrom(not_null<const Ui::InputField*> field) {
const auto cursor = field->textCursor();
position = cursor.position();

View File

@ -192,8 +192,6 @@ struct WebPageData;
struct GameData;
struct PollData;
class AudioMsgId;
using PhotoId = uint64;
using VideoId = uint64;
using AudioId = uint64;
@ -246,78 +244,6 @@ inline constexpr auto kStickerSideSize = 512;
using MediaKey = QPair<uint64, uint64>;
class AudioMsgId {
public:
enum class Type {
Unknown,
Voice,
Song,
Video,
};
AudioMsgId() = default;
AudioMsgId(
not_null<DocumentData*> audio,
FullMsgId msgId,
uint32 externalPlayId = 0)
: _audio(audio)
, _contextId(msgId)
, _externalPlayId(externalPlayId) {
setTypeFromAudio();
}
[[nodiscard]] static uint32 CreateExternalPlayId();
[[nodiscard]] static AudioMsgId ForVideo();
[[nodiscard]] Type type() const {
return _type;
}
[[nodiscard]] DocumentData *audio() const {
return _audio;
}
[[nodiscard]] FullMsgId contextId() const {
return _contextId;
}
[[nodiscard]] uint32 externalPlayId() const {
return _externalPlayId;
}
[[nodiscard]] explicit operator bool() const {
return (_audio != nullptr) || (_externalPlayId != 0);
}
private:
void setTypeFromAudio();
DocumentData *_audio = nullptr;
Type _type = Type::Unknown;
FullMsgId _contextId;
uint32 _externalPlayId = 0;
};
inline bool operator<(const AudioMsgId &a, const AudioMsgId &b) {
if (quintptr(a.audio()) < quintptr(b.audio())) {
return true;
} else if (quintptr(b.audio()) < quintptr(a.audio())) {
return false;
} else if (a.contextId() < b.contextId()) {
return true;
} else if (b.contextId() < a.contextId()) {
return false;
}
return (a.externalPlayId() < b.externalPlayId());
}
inline bool operator==(const AudioMsgId &a, const AudioMsgId &b) {
return (a.audio() == b.audio())
&& (a.contextId() == b.contextId())
&& (a.externalPlayId() == b.externalPlayId());
}
inline bool operator!=(const AudioMsgId &a, const AudioMsgId &b) {
return !(a == b);
}
struct MessageCursor {
MessageCursor() = default;
MessageCursor(int position, int anchor, int scroll)

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animation_value.h"
#include "ui/chat/attach/attach_prepare.h"
#include "core/file_location.h"
#include "data/data_audio_msg_id.h"
#include "base/bytes.h"
#include "base/timer.h"

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "data/data_audio_msg_id.h"
#include "data/data_shared_media.h"
class AudioMsgId;

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "data/data_audio_msg_id.h"
#include "ui/rp_widget.h"
#include "base/object_ptr.h"

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "data/data_audio_msg_id.h"
#include "ui/rect_part.h"
enum class ImageRoundRadius;

View File

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "data/data_audio_msg_id.h"
namespace base::Platform {
class SystemMediaControls;
} // namespace base::Platform