tdlight/td/telegram/VoiceNotesManager.hpp

89 lines
2.5 KiB
C++
Raw Normal View History

//
2022-01-01 01:35:39 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
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
}
store(file_id, storer);
}
template <class ParserT>
FileId VoiceNotesManager::parse_voice_note(ParserT &parser) {
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
}
parse(voice_note->file_id, parser);
if (parser.get_error() != nullptr || !voice_note->file_id.is_valid()) {
return FileId();
}
return on_get_voice_note(std::move(voice_note), false);
}
} // namespace td