2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/VoiceNotesManager.h"
|
|
|
|
|
|
|
|
#include "td/telegram/files/FileId.hpp"
|
2022-10-19 19:43:30 +02:00
|
|
|
#include "td/telegram/TranscriptionInfo.hpp"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/telegram/Version.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-12 21:48:16 +01:00
|
|
|
#include "td/utils/common.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void VoiceNotesManager::store_voice_note(FileId file_id, StorerT &storer) const {
|
2022-08-03 22:23:32 +02:00
|
|
|
const VoiceNote *voice_note = get_voice_note(file_id);
|
|
|
|
CHECK(voice_note != nullptr);
|
2022-05-25 18:24:40 +02:00
|
|
|
bool has_mime_type = !voice_note->mime_type.empty();
|
|
|
|
bool has_duration = voice_note->duration != 0;
|
|
|
|
bool has_waveform = !voice_note->waveform.empty();
|
2022-10-19 19:43:30 +02:00
|
|
|
bool is_transcribed = voice_note->transcription_info != nullptr && voice_note->transcription_info->is_transcribed();
|
2022-05-25 18:24:40 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_mime_type);
|
|
|
|
STORE_FLAG(has_duration);
|
|
|
|
STORE_FLAG(has_waveform);
|
2022-10-19 19:43:30 +02:00
|
|
|
STORE_FLAG(is_transcribed);
|
2022-05-25 18:24:40 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_mime_type) {
|
|
|
|
store(voice_note->mime_type, storer);
|
|
|
|
}
|
|
|
|
if (has_duration) {
|
|
|
|
store(voice_note->duration, storer);
|
|
|
|
}
|
|
|
|
if (has_waveform) {
|
|
|
|
store(voice_note->waveform, storer);
|
|
|
|
}
|
2022-10-19 19:43:30 +02:00
|
|
|
if (is_transcribed) {
|
|
|
|
store(voice_note->transcription_info, storer);
|
2022-05-25 18:24:40 +02:00
|
|
|
}
|
2018-03-08 20:43:12 +01:00
|
|
|
store(file_id, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
FileId VoiceNotesManager::parse_voice_note(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto voice_note = make_unique<VoiceNote>();
|
2022-05-25 18:24:40 +02:00
|
|
|
bool has_mime_type;
|
|
|
|
bool has_duration;
|
|
|
|
bool has_waveform;
|
2022-10-19 19:43:30 +02:00
|
|
|
bool is_transcribed;
|
2022-05-25 18:24:40 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddVoiceNoteFlags)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_mime_type);
|
|
|
|
PARSE_FLAG(has_duration);
|
|
|
|
PARSE_FLAG(has_waveform);
|
2022-10-19 19:43:30 +02:00
|
|
|
PARSE_FLAG(is_transcribed);
|
2022-05-25 18:24:40 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
} else {
|
|
|
|
has_mime_type = true;
|
|
|
|
has_duration = true;
|
|
|
|
has_waveform = true;
|
2022-10-19 19:43:30 +02:00
|
|
|
is_transcribed = false;
|
2022-05-25 18:24:40 +02:00
|
|
|
}
|
|
|
|
if (has_mime_type) {
|
|
|
|
parse(voice_note->mime_type, parser);
|
|
|
|
}
|
|
|
|
if (has_duration) {
|
|
|
|
parse(voice_note->duration, parser);
|
|
|
|
}
|
|
|
|
if (has_waveform) {
|
|
|
|
parse(voice_note->waveform, parser);
|
|
|
|
}
|
2022-10-19 19:43:30 +02:00
|
|
|
if (is_transcribed) {
|
|
|
|
parse(voice_note->transcription_info, parser);
|
2022-05-25 18:24:40 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(voice_note->file_id, parser);
|
2019-08-01 02:58:49 +02:00
|
|
|
if (parser.get_error() != nullptr || !voice_note->file_id.is_valid()) {
|
|
|
|
return FileId();
|
|
|
|
}
|
2018-11-06 12:37:07 +01:00
|
|
|
return on_get_voice_note(std::move(voice_note), false);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|