Use file name instead of notification sound title if there is none.

This commit is contained in:
levlam 2022-04-17 19:01:01 +03:00
parent d2535835e5
commit 9b19e88c2a
2 changed files with 10 additions and 1 deletions

View File

@ -14,6 +14,7 @@
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/PathView.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
@ -58,7 +59,11 @@ td_api::object_ptr<td_api::notificationSound> AudiosManager::get_notification_so
CHECK(file_view.get_type() == FileType::Ringtone);
CHECK(file_view.has_remote_location());
auto document_id = file_view.remote_location().get_id();
return td_api::make_object<td_api::notificationSound>(document_id, audio->duration, audio->date, audio->title,
auto title = audio->title;
if (title.empty() && !audio->file_name.empty()) {
title = PathView(audio->file_name).file_name_without_extension().str();
}
return td_api::make_object<td_api::notificationSound>(document_id, audio->duration, audio->date, title,
audio->performer, td_->file_manager_->get_file_object(file_id));
}

View File

@ -49,6 +49,10 @@ class PathView {
return path_.substr(last_slash_ + 1);
}
Slice file_name_without_extension() const {
return path_.substr(last_slash_ + 1, last_dot_ - last_slash_ - 1);
}
Slice path() const {
return path_;
}