Add getSavedNotificationSound.

This commit is contained in:
levlam 2022-04-14 13:23:43 +03:00
parent dfa38e059d
commit f849131873
7 changed files with 60 additions and 6 deletions

View File

@ -5178,6 +5178,9 @@ getChatAdministrators chat_id:int53 = ChatAdministrators;
clearAllDraftMessages exclude_secret_chats:Bool = Ok;
//@description Returns saved notification sound by its identifier. Returns a 404 error if there is no saved notification sound with the specified identifier @notification_sound_id Identifier of the notification sound
getSavedNotificationSound notification_sound_id:int64 = NotificationSounds;
//@description Returns list of saved notification sounds. If a sound isn't in the list, then default sound needs to be used
getSavedNotificationSounds = NotificationSounds;

View File

@ -45,7 +45,9 @@ tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) con
}
td_api::object_ptr<td_api::notificationSound> AudiosManager::get_notification_sound_object(FileId file_id) const {
CHECK(file_id.is_valid());
if (!file_id.is_valid()) {
return nullptr;
}
auto it = audios_.find(file_id);
CHECK(it != audios_.end());

View File

@ -10,6 +10,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/logevent/LogEventHelper.h"
@ -624,6 +625,25 @@ bool NotificationSettingsManager::is_active() const {
return !G()->close_flag() && td_->auth_manager_->is_authorized() && !td_->auth_manager_->is_bot();
}
FileId NotificationSettingsManager::get_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise) {
if (!are_saved_ringtones_loaded_) {
reload_saved_ringtones(std::move(promise));
return {};
}
promise.set_value(Unit());
for (auto &file_id : saved_ringtone_file_ids_) {
auto file_view = td_->file_manager_->get_file_view(file_id);
CHECK(!file_view.empty());
CHECK(file_view.get_type() == FileType::Ringtone);
CHECK(file_view.has_remote_location());
if (file_view.remote_location().get_id() == ringtone_id) {
return file_view.file_id();
}
}
return {};
}
vector<FileId> NotificationSettingsManager::get_saved_ringtones(Promise<Unit> &&promise) {
if (!are_saved_ringtones_loaded_) {
reload_saved_ringtones(std::move(promise));

View File

@ -46,6 +46,8 @@ class NotificationSettingsManager final : public Actor {
void on_update_scope_notify_settings(NotificationSettingsScope scope,
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings);
FileId get_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
vector<FileId> get_saved_ringtones(Promise<Unit> &&promise);
void reload_saved_ringtones(Promise<Unit> &&promise);

View File

@ -2593,6 +2593,24 @@ class RemoveSavedAnimationRequest final : public RequestOnceActor {
}
};
class GetSavedNotificationSoundRequest final : public RequestActor<> {
int64 ringtone_id_;
FileId ringtone_file_id_;
void do_run(Promise<Unit> &&promise) final {
ringtone_file_id_ = td_->notification_settings_manager_->get_saved_ringtone(ringtone_id_, std::move(promise));
}
void do_send_result() final {
send_result(td_->audios_manager_->get_notification_sound_object(ringtone_file_id_));
}
public:
GetSavedNotificationSoundRequest(ActorShared<Td> td, uint64 request_id, int64 ringtone_id)
: RequestActor(std::move(td), request_id), ringtone_id_(ringtone_id) {
}
};
class GetSavedNotificationSoundsRequest final : public RequestActor<> {
vector<FileId> ringtone_file_ids_;
@ -7113,6 +7131,11 @@ void Td::on_request(uint64 id, td_api::removeSavedAnimation &request) {
CREATE_REQUEST(RemoveSavedAnimationRequest, std::move(request.animation_));
}
void Td::on_request(uint64 id, const td_api::getSavedNotificationSound &request) {
CHECK_IS_USER();
CREATE_REQUEST(GetSavedNotificationSoundRequest, request.notification_sound_id_);
}
void Td::on_request(uint64 id, const td_api::getSavedNotificationSounds &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetSavedNotificationSoundsRequest);

View File

@ -1104,6 +1104,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::removeFavoriteSticker &request);
void on_request(uint64 id, const td_api::getSavedNotificationSound &request);
void on_request(uint64 id, const td_api::getSavedNotificationSounds &request);
void on_request(uint64 id, const td_api::getChatNotificationSettingsExceptions &request);

View File

@ -4490,7 +4490,9 @@ class CliClient final : public Actor {
int64 profile_photo_id;
get_args(args, profile_photo_id);
send_request(td_api::make_object<td_api::deleteProfilePhoto>(profile_photo_id));
} else if (op == "gsnss") {
} else if (op == "gns") {
send_request(td_api::make_object<td_api::getSavedNotificationSound>());
} else if (op == "gnss") {
send_request(td_api::make_object<td_api::getSavedNotificationSounds>());
} else if (op == "gcnse" || op == "gcnses") {
send_request(td_api::make_object<td_api::getChatNotificationSettingsExceptions>(
@ -4500,17 +4502,17 @@ class CliClient final : public Actor {
} else if (op == "scns" || op == "ssns") {
string chat_id_or_scope;
string mute_for;
int64 ringtone_id;
int64 sound_id;
string show_preview;
string disable_pinned_message_notifications;
string disable_mention_notifications;
get_args(args, chat_id_or_scope, mute_for, ringtone_id, show_preview, disable_pinned_message_notifications,
get_args(args, chat_id_or_scope, mute_for, sound_id, show_preview, disable_pinned_message_notifications,
disable_mention_notifications);
if (op == "scns") {
send_request(td_api::make_object<td_api::setChatNotificationSettings>(
as_chat_id(chat_id_or_scope),
td_api::make_object<td_api::chatNotificationSettings>(
mute_for.empty(), to_integer<int32>(mute_for), ringtone_id == -1, ringtone_id, show_preview.empty(),
mute_for.empty(), to_integer<int32>(mute_for), sound_id == -1, sound_id, show_preview.empty(),
as_bool(show_preview), disable_pinned_message_notifications.empty(),
as_bool(disable_pinned_message_notifications), disable_mention_notifications.empty(),
as_bool(disable_mention_notifications))));
@ -4518,7 +4520,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setScopeNotificationSettings>(
get_notification_settings_scope(chat_id_or_scope),
td_api::make_object<td_api::scopeNotificationSettings>(
to_integer<int32>(mute_for), ringtone_id, as_bool(show_preview),
to_integer<int32>(mute_for), sound_id, as_bool(show_preview),
as_bool(disable_pinned_message_notifications), as_bool(disable_mention_notifications))));
}
} else if (op == "rans") {