Remove unneeded document.is_changed.

This commit is contained in:
levlam 2021-08-26 18:50:28 +03:00
parent ca03135f02
commit cf7c14fb59
16 changed files with 63 additions and 173 deletions

View File

@ -158,8 +158,6 @@ tl_object_ptr<td_api::animation> AnimationsManager::get_animation_object(FileId
auto &animation = animations_[file_id];
LOG_CHECK(animation != nullptr) << source << " " << file_id << " "
<< static_cast<int32>(td_->file_manager_->get_file_view(file_id).get_type());
// TODO can we make that function const?
animation->is_changed = false;
auto thumbnail =
animation->animated_thumbnail.file_id.is_valid()
? get_thumbnail_object(td_->file_manager_.get(), animation->animated_thumbnail, PhotoFormat::Mpeg4)
@ -183,26 +181,21 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
if (a->mime_type != new_animation->mime_type) {
LOG(DEBUG) << "Animation " << file_id << " info has changed";
a->mime_type = new_animation->mime_type;
a->is_changed = true;
}
if (a->file_name != new_animation->file_name) {
LOG(DEBUG) << "Animation " << file_id << " file name has changed";
a->file_name = std::move(new_animation->file_name);
a->is_changed = true;
}
if (a->dimensions != new_animation->dimensions) {
LOG(DEBUG) << "Animation " << file_id << " dimensions has changed";
a->dimensions = new_animation->dimensions;
a->is_changed = true;
}
if (a->duration != new_animation->duration) {
LOG(DEBUG) << "Animation " << file_id << " duration has changed";
a->duration = new_animation->duration;
a->is_changed = true;
}
if (a->minithumbnail != new_animation->minithumbnail) {
a->minithumbnail = std::move(new_animation->minithumbnail);
a->is_changed = true;
}
if (a->thumbnail != new_animation->thumbnail) {
if (!a->thumbnail.file_id.is_valid()) {
@ -212,7 +205,6 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
<< new_animation->thumbnail;
}
a->thumbnail = new_animation->thumbnail;
a->is_changed = true;
}
if (a->animated_thumbnail != new_animation->animated_thumbnail) {
if (!a->animated_thumbnail.file_id.is_valid()) {
@ -222,15 +214,12 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
<< " to " << new_animation->animated_thumbnail;
}
a->animated_thumbnail = new_animation->animated_thumbnail;
a->is_changed = true;
}
if (a->has_stickers != new_animation->has_stickers && new_animation->has_stickers) {
a->has_stickers = new_animation->has_stickers;
a->is_changed = true;
}
if (a->sticker_file_ids != new_animation->sticker_file_ids && !new_animation->sticker_file_ids.empty()) {
a->sticker_file_ids = std::move(new_animation->sticker_file_ids);
a->is_changed = true;
}
}
@ -280,24 +269,18 @@ FileId AnimationsManager::dup_animation(FileId new_id, FileId old_id) {
return new_id;
}
bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge animations " << new_id << " and " << old_id;
const Animation *old_ = get_animation(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
bool need_merge = true;
auto new_it = animations_.find(new_id);
if (new_it == animations_.end()) {
auto &old = animations_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_animation(new_id, old_id);
} else {
@ -308,7 +291,6 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_
Animation *new_ = new_it->second.get();
CHECK(new_ != nullptr);
new_->is_changed = true;
if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
}
@ -322,7 +304,6 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_
if (can_delete_old) {
animations_.erase(old_id);
}
return true;
}
void AnimationsManager::create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail,

View File

@ -55,7 +55,7 @@ class AnimationsManager final : public Actor {
FileId dup_animation(FileId new_id, FileId old_id);
bool merge_animations(FileId new_id, FileId old_id, bool can_delete_old);
void merge_animations(FileId new_id, FileId old_id, bool can_delete_old);
void on_update_animation_search_emojis(string animation_search_emojis);
@ -110,8 +110,6 @@ class AnimationsManager final : public Actor {
vector<FileId> sticker_file_ids;
FileId file_id;
bool is_changed = true;
};
const Animation *get_animation(FileId file_id) const;

View File

@ -36,7 +36,6 @@ tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) {
auto &audio = audios_[file_id];
CHECK(audio != nullptr);
audio->is_changed = false;
return make_tl_object<td_api::audio>(
audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type,
get_minithumbnail_object(audio->minithumbnail),
@ -56,23 +55,19 @@ FileId AudiosManager::on_get_audio(unique_ptr<Audio> new_audio, bool replace) {
if (a->mime_type != new_audio->mime_type) {
LOG(DEBUG) << "Audio " << file_id << " info has changed";
a->mime_type = new_audio->mime_type;
a->is_changed = true;
}
if (a->duration != new_audio->duration || a->title != new_audio->title || a->performer != new_audio->performer) {
LOG(DEBUG) << "Audio " << file_id << " info has changed";
a->duration = new_audio->duration;
a->title = new_audio->title;
a->performer = new_audio->performer;
a->is_changed = true;
}
if (a->file_name != new_audio->file_name) {
LOG(DEBUG) << "Audio " << file_id << " file name has changed";
a->file_name = std::move(new_audio->file_name);
a->is_changed = true;
}
if (a->minithumbnail != new_audio->minithumbnail) {
a->minithumbnail = std::move(new_audio->minithumbnail);
a->is_changed = true;
}
if (a->thumbnail != new_audio->thumbnail) {
if (!a->thumbnail.file_id.is_valid()) {
@ -82,7 +77,6 @@ FileId AudiosManager::on_get_audio(unique_ptr<Audio> new_audio, bool replace) {
<< new_audio->thumbnail;
}
a->thumbnail = new_audio->thumbnail;
a->is_changed = true;
}
}
@ -110,23 +104,17 @@ FileId AudiosManager::dup_audio(FileId new_id, FileId old_id) {
return new_id;
}
bool AudiosManager::merge_audios(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void AudiosManager::merge_audios(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge audios " << new_id << " and " << old_id;
const Audio *old_ = get_audio(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = audios_.find(new_id);
if (new_it == audios_.end()) {
auto &old = audios_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_audio(new_id, old_id);
} else {
@ -141,7 +129,6 @@ bool AudiosManager::merge_audios(FileId new_id, FileId old_id, bool can_delete_o
LOG(INFO) << "Audio has changed: mime_type = (" << old_->mime_type << ", " << new_->mime_type << ")";
}
new_->is_changed = true;
if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
}
@ -150,7 +137,6 @@ bool AudiosManager::merge_audios(FileId new_id, FileId old_id, bool can_delete_o
if (can_delete_old) {
audios_.erase(old_id);
}
return true;
}
string AudiosManager::get_audio_search_text(FileId file_id) const {

View File

@ -47,7 +47,7 @@ class AudiosManager {
FileId dup_audio(FileId new_id, FileId old_id);
bool merge_audios(FileId new_id, FileId old_id, bool can_delete_old);
void merge_audios(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_audio(FileId file_id, StorerT &storer) const;
@ -69,8 +69,6 @@ class AudiosManager {
PhotoSize thumbnail;
FileId file_id;
bool is_changed = true;
};
const Audio *get_audio(FileId file_id) const;

View File

@ -55,7 +55,6 @@ tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId fil
LOG(INFO) << "Return document " << file_id << " object";
auto &document = documents_[file_id];
LOG_CHECK(document != nullptr) << tag("file_id", file_id);
document->is_changed = false;
return make_tl_object<td_api::document>(
document->file_name, document->mime_type, get_minithumbnail_object(document->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), document->thumbnail, thumbnail_format),
@ -486,16 +485,13 @@ FileId DocumentsManager::on_get_document(unique_ptr<GeneralDocument> new_documen
if (d->mime_type != new_document->mime_type) {
LOG(DEBUG) << "Document " << file_id << " mime_type has changed";
d->mime_type = new_document->mime_type;
d->is_changed = true;
}
if (d->file_name != new_document->file_name) {
LOG(DEBUG) << "Document " << file_id << " file_name has changed";
d->file_name = new_document->file_name;
d->is_changed = true;
}
if (d->minithumbnail != new_document->minithumbnail) {
d->minithumbnail = std::move(new_document->minithumbnail);
d->is_changed = true;
}
if (d->thumbnail != new_document->thumbnail) {
if (!d->thumbnail.file_id.is_valid()) {
@ -505,7 +501,6 @@ FileId DocumentsManager::on_get_document(unique_ptr<GeneralDocument> new_documen
<< new_document->thumbnail;
}
d->thumbnail = new_document->thumbnail;
d->is_changed = true;
}
}
@ -651,23 +646,17 @@ FileId DocumentsManager::dup_document(FileId new_id, FileId old_id) {
return new_id;
}
bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge documents " << new_id << " and " << old_id;
const GeneralDocument *old_ = get_document(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = documents_.find(new_id);
if (new_it == documents_.end()) {
auto &old = documents_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_document(new_id, old_id);
} else {
@ -681,14 +670,11 @@ bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_de
if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
}
new_->is_changed = true;
}
LOG_STATUS(td_->file_manager_->merge(new_id, old_id));
if (can_delete_old) {
documents_.erase(old_id);
}
return true;
}
string DocumentsManager::get_document_search_text(FileId file_id) const {

View File

@ -101,7 +101,7 @@ class DocumentsManager {
FileId dup_document(FileId new_id, FileId old_id);
bool merge_documents(FileId new_id, FileId old_id, bool can_delete_old);
void merge_documents(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_document(FileId file_id, StorerT &storer) const;
@ -119,8 +119,6 @@ class DocumentsManager {
string minithumbnail;
PhotoSize thumbnail;
FileId file_id;
bool is_changed = true;
};
const GeneralDocument *get_document(FileId file_id) const;

View File

@ -2943,8 +2943,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Animation: {
auto old_ = static_cast<const MessageAnimation *>(old_content);
auto new_ = static_cast<const MessageAnimation *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->animations_manager_->merge_animations(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->animations_manager_->merge_animations(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->caption != new_->caption) {
@ -2955,8 +2957,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Audio: {
auto old_ = static_cast<const MessageAudio *>(old_content);
auto new_ = static_cast<const MessageAudio *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->audios_manager_->merge_audios(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->audios_manager_->merge_audios(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->caption != new_->caption) {
@ -2975,8 +2979,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Document: {
auto old_ = static_cast<const MessageDocument *>(old_content);
auto new_ = static_cast<const MessageDocument *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->documents_manager_->merge_documents(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->documents_manager_->merge_documents(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->caption != new_->caption) {
@ -3106,8 +3112,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Sticker: {
auto old_ = static_cast<const MessageSticker *>(old_content);
auto new_ = static_cast<const MessageSticker *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->stickers_manager_->merge_stickers(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->stickers_manager_->merge_stickers(new_->file_id, old_->file_id, false);
}
need_update = true;
}
break;
@ -3127,8 +3135,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Video: {
auto old_ = static_cast<const MessageVideo *>(old_content);
auto new_ = static_cast<const MessageVideo *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->videos_manager_->merge_videos(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->videos_manager_->merge_videos(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->caption != new_->caption) {
@ -3139,8 +3149,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::VideoNote: {
auto old_ = static_cast<const MessageVideoNote *>(old_content);
auto new_ = static_cast<const MessageVideoNote *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->video_notes_manager_->merge_video_notes(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->video_notes_manager_->merge_video_notes(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->is_viewed != new_->is_viewed) {
@ -3151,8 +3163,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::VoiceNote: {
auto old_ = static_cast<const MessageVoiceNote *>(old_content);
auto new_ = static_cast<const MessageVoiceNote *>(new_content);
if (new_->file_id != old_->file_id &&
(!need_merge_files || td->voice_notes_manager_->merge_voice_notes(new_->file_id, old_->file_id, false))) {
if (new_->file_id != old_->file_id) {
if (need_merge_files) {
td->voice_notes_manager_->merge_voice_notes(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->caption != new_->caption) {

View File

@ -1639,8 +1639,6 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
CHECK(it != stickers_.end());
auto sticker = it->second.get();
CHECK(sticker != nullptr);
sticker->is_changed = false;
auto mask_position = sticker->point >= 0
? make_tl_object<td_api::maskPosition>(get_mask_point_object(sticker->point),
sticker->x_shift, sticker->y_shift, sticker->scale)
@ -1850,49 +1848,40 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
if (s->dimensions != new_sticker->dimensions && new_sticker->dimensions.width != 0) {
LOG(DEBUG) << "Sticker " << file_id << " dimensions has changed";
s->dimensions = new_sticker->dimensions;
s->is_changed = true;
}
if (s->set_id != new_sticker->set_id && new_sticker->set_id.is_valid()) {
LOG_IF(ERROR, s->set_id.is_valid()) << "Sticker " << file_id << " set_id has changed";
s->set_id = new_sticker->set_id;
s->is_changed = true;
}
if (s->alt != new_sticker->alt && !new_sticker->alt.empty()) {
LOG(DEBUG) << "Sticker " << file_id << " emoji has changed";
s->alt = std::move(new_sticker->alt);
s->is_changed = true;
}
if (s->minithumbnail != new_sticker->minithumbnail) {
LOG(DEBUG) << "Sticker " << file_id << " minithumbnail has changed";
s->minithumbnail = std::move(new_sticker->minithumbnail);
s->is_changed = true;
}
if (s->s_thumbnail != new_sticker->s_thumbnail && new_sticker->s_thumbnail.file_id.is_valid()) {
LOG_IF(INFO, s->s_thumbnail.file_id.is_valid()) << "Sticker " << file_id << " s thumbnail has changed from "
<< s->s_thumbnail << " to " << new_sticker->s_thumbnail;
s->s_thumbnail = std::move(new_sticker->s_thumbnail);
s->is_changed = true;
}
if (s->m_thumbnail != new_sticker->m_thumbnail && new_sticker->m_thumbnail.file_id.is_valid()) {
LOG_IF(INFO, s->m_thumbnail.file_id.is_valid()) << "Sticker " << file_id << " m thumbnail has changed from "
<< s->m_thumbnail << " to " << new_sticker->m_thumbnail;
s->m_thumbnail = std::move(new_sticker->m_thumbnail);
s->is_changed = true;
}
if (s->is_animated != new_sticker->is_animated && new_sticker->is_animated) {
s->is_animated = new_sticker->is_animated;
s->is_changed = true;
}
if (s->is_mask != new_sticker->is_mask && new_sticker->is_mask) {
s->is_mask = new_sticker->is_mask;
s->is_changed = true;
}
if (s->point != new_sticker->point && new_sticker->point != -1) {
s->point = new_sticker->point;
s->x_shift = new_sticker->x_shift;
s->y_shift = new_sticker->y_shift;
s->scale = new_sticker->scale;
s->is_changed = true;
}
}
@ -2133,23 +2122,17 @@ FileId StickersManager::dup_sticker(FileId new_id, FileId old_id) {
return new_id;
}
bool StickersManager::merge_stickers(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void StickersManager::merge_stickers(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge stickers " << new_id << " and " << old_id;
const Sticker *old_ = get_sticker(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = stickers_.find(new_id);
if (new_it == stickers_.end()) {
auto &old = stickers_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_sticker(new_id, old_id);
} else {
@ -2167,8 +2150,6 @@ bool StickersManager::merge_stickers(FileId new_id, FileId old_id, bool can_dele
<< ", " << new_->set_id << "), dimensions = (" << old_->dimensions << ", " << new_->dimensions << ")";
}
new_->is_changed = true;
if (old_->s_thumbnail != new_->s_thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->s_thumbnail.file_id, old_->s_thumbnail.file_id));
}
@ -2180,7 +2161,6 @@ bool StickersManager::merge_stickers(FileId new_id, FileId old_id, bool can_dele
if (can_delete_old) {
stickers_.erase(old_id);
}
return true;
}
tl_object_ptr<telegram_api::InputStickerSet> StickersManager::get_input_sticker_set(const StickerSet *set) {
@ -2277,7 +2257,6 @@ void StickersManager::on_resolve_sticker_set_short_name(FileId sticker_file_id,
CHECK(s->file_id == sticker_file_id);
if (s->set_id != set_id) {
s->set_id = set_id;
s->is_changed = true;
}
}
}
@ -5028,12 +5007,14 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, tl_object_ptr<tel
return promise.set_error(Status::Error(400, "Wrong file type"));
}
if (parsed_document.file_id != file_id) {
if (is_animated) {
merge_stickers(parsed_document.file_id, file_id, false);
} else {
// must not delete the old document, because the file_id could be used for simultaneous URL uploads
td_->documents_manager_->merge_documents(parsed_document.file_id, file_id, false);
}
}
promise.set_value(Unit());
}

View File

@ -263,7 +263,7 @@ class StickersManager final : public Actor {
FileId dup_sticker(FileId new_id, FileId old_id);
bool merge_stickers(FileId new_id, FileId old_id, bool can_delete_old);
void merge_stickers(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_sticker(FileId file_id, bool in_sticker_set, StorerT &storer) const;
@ -324,8 +324,6 @@ class StickersManager final : public Actor {
double x_shift = 0;
double y_shift = 0;
double scale = 0;
mutable bool is_changed = true;
};
class StickerSet {

View File

@ -300,7 +300,6 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
if (sticker->set_id != sticker_set->id) {
LOG_IF(ERROR, sticker->set_id.is_valid()) << "Sticker " << sticker_id << " set_id has changed";
sticker->set_id = sticker_set->id;
sticker->is_changed = true;
}
if (sticker_set->was_loaded) {

View File

@ -35,8 +35,6 @@ tl_object_ptr<td_api::videoNote> VideoNotesManager::get_video_note_object(FileId
auto &video_note = video_notes_[file_id];
CHECK(video_note != nullptr);
video_note->is_changed = false;
return make_tl_object<td_api::videoNote>(
video_note->duration, video_note->dimensions.width, get_minithumbnail_object(video_note->minithumbnail),
get_thumbnail_object(td_->file_manager_.get(), video_note->thumbnail, PhotoFormat::Jpeg),
@ -56,11 +54,9 @@ FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note
LOG(DEBUG) << "Video note " << file_id << " info has changed";
v->duration = new_video_note->duration;
v->dimensions = new_video_note->dimensions;
v->is_changed = true;
}
if (v->minithumbnail != new_video_note->minithumbnail) {
v->minithumbnail = std::move(new_video_note->minithumbnail);
v->is_changed = true;
}
if (v->thumbnail != new_video_note->thumbnail) {
if (!v->thumbnail.file_id.is_valid()) {
@ -70,7 +66,6 @@ FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note
<< new_video_note->thumbnail;
}
v->thumbnail = new_video_note->thumbnail;
v->is_changed = true;
}
}
return file_id;
@ -109,23 +104,17 @@ FileId VideoNotesManager::dup_video_note(FileId new_id, FileId old_id) {
return new_id;
}
bool VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge video notes " << new_id << " and " << old_id;
const VideoNote *old_ = get_video_note(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = video_notes_.find(new_id);
if (new_it == video_notes_.end()) {
auto &old = video_notes_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_video_note(new_id, old_id);
} else {
@ -135,7 +124,6 @@ bool VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id, bool can
} else {
VideoNote *new_ = new_it->second.get();
CHECK(new_ != nullptr);
new_->is_changed = true;
if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
}
@ -144,7 +132,6 @@ bool VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id, bool can
if (can_delete_old) {
video_notes_.erase(old_id);
}
return true;
}
void VideoNotesManager::create_video_note(FileId file_id, string minithumbnail, PhotoSize thumbnail, int32 duration,

View File

@ -47,7 +47,7 @@ class VideoNotesManager {
FileId dup_video_note(FileId new_id, FileId old_id);
bool merge_video_notes(FileId new_id, FileId old_id, bool can_delete_old);
void merge_video_notes(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_video_note(FileId file_id, StorerT &storer) const;
@ -64,8 +64,6 @@ class VideoNotesManager {
PhotoSize thumbnail;
FileId file_id;
bool is_changed = true;
};
const VideoNote *get_video_note(FileId file_id) const;

View File

@ -35,8 +35,6 @@ tl_object_ptr<td_api::video> VideosManager::get_video_object(FileId file_id) {
auto &video = videos_[file_id];
CHECK(video != nullptr);
video->is_changed = false;
auto thumbnail = video->animated_thumbnail.file_id.is_valid()
? get_thumbnail_object(td_->file_manager_.get(), video->animated_thumbnail, PhotoFormat::Mpeg4)
: get_thumbnail_object(td_->file_manager_.get(), video->thumbnail, PhotoFormat::Jpeg);
@ -58,7 +56,6 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
if (v->mime_type != new_video->mime_type) {
LOG(DEBUG) << "Video " << file_id << " MIME type has changed";
v->mime_type = new_video->mime_type;
v->is_changed = true;
}
if (v->duration != new_video->duration || v->dimensions != new_video->dimensions ||
v->supports_streaming != new_video->supports_streaming) {
@ -66,16 +63,13 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
v->duration = new_video->duration;
v->dimensions = new_video->dimensions;
v->supports_streaming = new_video->supports_streaming;
v->is_changed = true;
}
if (v->file_name != new_video->file_name) {
LOG(DEBUG) << "Video " << file_id << " file name has changed";
v->file_name = std::move(new_video->file_name);
v->is_changed = true;
}
if (v->minithumbnail != new_video->minithumbnail) {
v->minithumbnail = std::move(new_video->minithumbnail);
v->is_changed = true;
}
if (v->thumbnail != new_video->thumbnail) {
if (!v->thumbnail.file_id.is_valid()) {
@ -85,7 +79,6 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
<< new_video->thumbnail;
}
v->thumbnail = new_video->thumbnail;
v->is_changed = true;
}
if (v->animated_thumbnail != new_video->animated_thumbnail) {
if (!v->animated_thumbnail.file_id.is_valid()) {
@ -95,15 +88,12 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
<< new_video->animated_thumbnail;
}
v->animated_thumbnail = new_video->animated_thumbnail;
v->is_changed = true;
}
if (v->has_stickers != new_video->has_stickers && new_video->has_stickers) {
v->has_stickers = new_video->has_stickers;
v->is_changed = true;
}
if (v->sticker_file_ids != new_video->sticker_file_ids && !new_video->sticker_file_ids.empty()) {
v->sticker_file_ids = std::move(new_video->sticker_file_ids);
v->is_changed = true;
}
}
return file_id;
@ -150,23 +140,17 @@ FileId VideosManager::dup_video(FileId new_id, FileId old_id) {
return new_id;
}
bool VideosManager::merge_videos(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void VideosManager::merge_videos(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge videos " << new_id << " and " << old_id;
const Video *old_ = get_video(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = videos_.find(new_id);
if (new_it == videos_.end()) {
auto &old = videos_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_video(new_id, old_id);
} else {
@ -181,7 +165,6 @@ bool VideosManager::merge_videos(FileId new_id, FileId old_id, bool can_delete_o
LOG(INFO) << "Video has changed: mime_type = (" << old_->mime_type << ", " << new_->mime_type << ")";
}
new_->is_changed = true;
if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
}
@ -190,7 +173,6 @@ bool VideosManager::merge_videos(FileId new_id, FileId old_id, bool can_delete_o
if (can_delete_old) {
videos_.erase(old_id);
}
return true;
}
void VideosManager::create_video(FileId file_id, string minithumbnail, PhotoSize thumbnail,

View File

@ -51,7 +51,7 @@ class VideosManager {
FileId dup_video(FileId new_id, FileId old_id);
bool merge_videos(FileId new_id, FileId old_id, bool can_delete_old);
void merge_videos(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_video(FileId file_id, StorerT &storer) const;
@ -78,8 +78,6 @@ class VideosManager {
vector<FileId> sticker_file_ids;
FileId file_id;
bool is_changed = true;
};
const Video *get_video(FileId file_id) const;

View File

@ -35,7 +35,6 @@ tl_object_ptr<td_api::voiceNote> VoiceNotesManager::get_voice_note_object(FileId
auto &voice_note = voice_notes_[file_id];
CHECK(voice_note != nullptr);
voice_note->is_changed = false;
return make_tl_object<td_api::voiceNote>(voice_note->duration, voice_note->waveform, voice_note->mime_type,
td_->file_manager_->get_file_object(file_id));
}
@ -52,13 +51,11 @@ FileId VoiceNotesManager::on_get_voice_note(unique_ptr<VoiceNote> new_voice_note
if (v->mime_type != new_voice_note->mime_type) {
LOG(DEBUG) << "Voice note " << file_id << " info has changed";
v->mime_type = new_voice_note->mime_type;
v->is_changed = true;
}
if (v->duration != new_voice_note->duration || v->waveform != new_voice_note->waveform) {
LOG(DEBUG) << "Voice note " << file_id << " info has changed";
v->duration = new_voice_note->duration;
v->waveform = new_voice_note->waveform;
v->is_changed = true;
}
}
@ -85,23 +82,17 @@ FileId VoiceNotesManager::dup_voice_note(FileId new_id, FileId old_id) {
return new_id;
}
bool VoiceNotesManager::merge_voice_notes(FileId new_id, FileId old_id, bool can_delete_old) {
if (!old_id.is_valid()) {
LOG(ERROR) << "Old file identifier is invalid";
return true;
}
void VoiceNotesManager::merge_voice_notes(FileId new_id, FileId old_id, bool can_delete_old) {
CHECK(old_id.is_valid() && new_id.is_valid());
CHECK(new_id != old_id);
LOG(INFO) << "Merge voice notes " << new_id << " and " << old_id;
const VoiceNote *old_ = get_voice_note(old_id);
CHECK(old_ != nullptr);
if (old_id == new_id) {
return old_->is_changed;
}
auto new_it = voice_notes_.find(new_id);
if (new_it == voice_notes_.end()) {
auto &old = voice_notes_[old_id];
old->is_changed = true;
if (!can_delete_old) {
dup_voice_note(new_id, old_id);
} else {
@ -115,14 +106,11 @@ bool VoiceNotesManager::merge_voice_notes(FileId new_id, FileId old_id, bool can
if (!old_->mime_type.empty() && old_->mime_type != new_->mime_type) {
LOG(INFO) << "Voice note has changed: mime_type = (" << old_->mime_type << ", " << new_->mime_type << ")";
}
new_->is_changed = true;
}
LOG_STATUS(td_->file_manager_->merge(new_id, old_id));
if (can_delete_old) {
voice_notes_.erase(old_id);
}
return true;
}
void VoiceNotesManager::create_voice_note(FileId file_id, string mime_type, int32 duration, string waveform,

View File

@ -39,7 +39,7 @@ class VoiceNotesManager {
FileId dup_voice_note(FileId new_id, FileId old_id);
bool merge_voice_notes(FileId new_id, FileId old_id, bool can_delete_old);
void merge_voice_notes(FileId new_id, FileId old_id, bool can_delete_old);
template <class StorerT>
void store_voice_note(FileId file_id, StorerT &storer) const;
@ -55,8 +55,6 @@ class VoiceNotesManager {
string waveform;
FileId file_id;
bool is_changed = true;
};
const VoiceNote *get_voice_note(FileId file_id) const;