Add td_api::removeSavedNotificationSound.
This commit is contained in:
parent
f849131873
commit
178d6414dd
|
@ -5184,6 +5184,9 @@ 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;
|
||||
|
||||
//@description Removes a notification sound from the list of saved notification sounds @notification_sound_id Identifier of the notification sound
|
||||
removeSavedNotificationSound notification_sound_id:int64 = Ok;
|
||||
|
||||
|
||||
//@description Returns list of chats with non-default notification settings
|
||||
//@scope If specified, only chats from the scope will be returned; pass null to return chats from all scopes
|
||||
|
|
|
@ -48,6 +48,7 @@ class MessagesManager;
|
|||
class MtprotoHeader;
|
||||
class NetQueryDispatcher;
|
||||
class NotificationManager;
|
||||
class NotificationSettingsManager;
|
||||
class OptionManager;
|
||||
class PasswordManager;
|
||||
class SecretChatsManager;
|
||||
|
@ -270,6 +271,13 @@ class Global final : public ActorContext {
|
|||
notification_manager_ = notification_manager;
|
||||
}
|
||||
|
||||
ActorId<NotificationSettingsManager> notification_settings_manager() const {
|
||||
return notification_settings_manager_;
|
||||
}
|
||||
void set_notification_settings_manager(ActorId<NotificationSettingsManager> notification_settings_manager) {
|
||||
notification_settings_manager_ = notification_settings_manager;
|
||||
}
|
||||
|
||||
ActorId<OptionManager> option_manager() const {
|
||||
return option_manager_;
|
||||
}
|
||||
|
@ -457,6 +465,7 @@ class Global final : public ActorContext {
|
|||
ActorId<LinkManager> link_manager_;
|
||||
ActorId<MessagesManager> messages_manager_;
|
||||
ActorId<NotificationManager> notification_manager_;
|
||||
ActorId<NotificationSettingsManager> notification_settings_manager_;
|
||||
ActorId<OptionManager> option_manager_;
|
||||
ActorId<PasswordManager> password_manager_;
|
||||
ActorId<SecretChatsManager> secret_chats_manager_;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/DocumentsManager.h"
|
||||
#include "td/telegram/FileReferenceManager.h"
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/logevent/LogEvent.h"
|
||||
|
@ -34,6 +35,65 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
class SaveRingtoneQuery final : public Td::ResultHandler {
|
||||
FileId file_id_;
|
||||
string file_reference_;
|
||||
bool unsave_ = false;
|
||||
|
||||
Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> promise_;
|
||||
|
||||
public:
|
||||
explicit SaveRingtoneQuery(Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(FileId file_id, tl_object_ptr<telegram_api::inputDocument> &&input_document, bool unsave) {
|
||||
CHECK(input_document != nullptr);
|
||||
CHECK(file_id.is_valid());
|
||||
file_id_ = file_id;
|
||||
file_reference_ = input_document->file_reference_.as_slice().str();
|
||||
unsave_ = unsave;
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_saveRingtone(std::move(input_document), unsave),
|
||||
{{"ringtone"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_saveRingtone>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for SaveRingtoneQuery: " << to_string(result);
|
||||
promise_.set_value(std::move(result));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
if (!td_->auth_manager_->is_bot() && FileReferenceManager::is_file_reference_error(status)) {
|
||||
VLOG(file_references) << "Receive " << status << " for " << file_id_;
|
||||
td_->file_manager_->delete_file_reference(file_id_, file_reference_);
|
||||
td_->file_reference_manager_->repair_file_reference(
|
||||
file_id_, PromiseCreator::lambda([ringtone_id = file_id_, unsave = unsave_,
|
||||
promise = std::move(promise_)](Result<Unit> result) mutable {
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(Status::Error(400, "Failed to find the ringtone"));
|
||||
}
|
||||
|
||||
send_closure(G()->notification_settings_manager(), &NotificationSettingsManager::send_save_ringtone_query,
|
||||
ringtone_id, unsave, std::move(promise));
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!G()->is_expected_error(status)) {
|
||||
LOG(ERROR) << "Receive error for SaveRingtoneQuery: " << status;
|
||||
}
|
||||
td_->notification_settings_manager_->reload_saved_ringtones(Auto());
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetSavedRingtonesQuery final : public Td::ResultHandler {
|
||||
Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtones>> promise_;
|
||||
|
||||
|
@ -43,7 +103,7 @@ class GetSavedRingtonesQuery final : public Td::ResultHandler {
|
|||
}
|
||||
|
||||
void send(int64 hash) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getSavedRingtones(hash)));
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getSavedRingtones(hash), {{"ringtone"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
|
@ -654,6 +714,69 @@ vector<FileId> NotificationSettingsManager::get_saved_ringtones(Promise<Unit> &&
|
|||
return saved_ringtone_file_ids_;
|
||||
}
|
||||
|
||||
void NotificationSettingsManager::send_save_ringtone_query(
|
||||
FileId ringtone_file_id, bool unsave,
|
||||
Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
// TODO log event
|
||||
auto file_view = td_->file_manager_->get_file_view(ringtone_file_id);
|
||||
CHECK(!file_view.empty());
|
||||
CHECK(file_view.has_remote_location());
|
||||
CHECK(file_view.remote_location().is_document());
|
||||
CHECK(!file_view.remote_location().is_web());
|
||||
td_->create_handler<SaveRingtoneQuery>(std::move(promise))
|
||||
->send(ringtone_file_id, file_view.remote_location().as_input_document(), unsave);
|
||||
}
|
||||
|
||||
void NotificationSettingsManager::remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise) {
|
||||
if (!are_saved_ringtones_loaded_) {
|
||||
reload_saved_ringtones(std::move(promise));
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
send_save_ringtone_query(
|
||||
file_view.file_id(), true,
|
||||
PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), ringtone_id, promise = std::move(promise)](
|
||||
Result<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &NotificationSettingsManager::on_remove_saved_ringtone, ringtone_id,
|
||||
std::move(promise));
|
||||
}
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void NotificationSettingsManager::on_remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise) {
|
||||
CHECK(are_saved_ringtones_loaded_);
|
||||
|
||||
for (auto it = saved_ringtone_file_ids_.begin(); it != saved_ringtone_file_ids_.begin(); ++it) {
|
||||
auto file_view = td_->file_manager_->get_file_view(*it);
|
||||
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) {
|
||||
saved_ringtone_file_ids_.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
Result<FileId> NotificationSettingsManager::get_ringtone(
|
||||
telegram_api::object_ptr<telegram_api::Document> &&ringtone) const {
|
||||
int32 document_id = ringtone->get_id();
|
||||
|
|
|
@ -50,8 +50,13 @@ class NotificationSettingsManager final : public Actor {
|
|||
|
||||
vector<FileId> get_saved_ringtones(Promise<Unit> &&promise);
|
||||
|
||||
void remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
|
||||
|
||||
void reload_saved_ringtones(Promise<Unit> &&promise);
|
||||
|
||||
void send_save_ringtone_query(FileId ringtone_file_id, bool unsave,
|
||||
Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&promise);
|
||||
|
||||
void send_get_dialog_notification_settings_query(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
const ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope,
|
||||
|
@ -97,6 +102,8 @@ class NotificationSettingsManager final : public Actor {
|
|||
|
||||
Result<FileId> get_ringtone(telegram_api::object_ptr<telegram_api::Document> &&ringtone) const;
|
||||
|
||||
void on_remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
|
||||
|
||||
void on_reload_saved_ringtones(Result<telegram_api::object_ptr<telegram_api::account_SavedRingtones>> &&result);
|
||||
|
||||
ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope);
|
||||
|
|
|
@ -2630,6 +2630,20 @@ class GetSavedNotificationSoundsRequest final : public RequestActor<> {
|
|||
}
|
||||
};
|
||||
|
||||
class RemoveSavedNotificationSoundRequest final : public RequestOnceActor {
|
||||
int64 ringtone_id_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) final {
|
||||
td_->notification_settings_manager_->remove_saved_ringtone(ringtone_id_, std::move(promise));
|
||||
}
|
||||
|
||||
public:
|
||||
RemoveSavedNotificationSoundRequest(ActorShared<Td> td, uint64 request_id, int64 ringtone_id)
|
||||
: RequestOnceActor(std::move(td), request_id), ringtone_id_(ringtone_id) {
|
||||
set_tries(3);
|
||||
}
|
||||
};
|
||||
|
||||
class GetInlineQueryResultsRequest final : public RequestOnceActor {
|
||||
UserId bot_user_id_;
|
||||
DialogId dialog_id_;
|
||||
|
@ -4039,6 +4053,7 @@ void Td::init_managers() {
|
|||
notification_settings_manager_ = make_unique<NotificationSettingsManager>(this, create_reference());
|
||||
notification_settings_manager_actor_ =
|
||||
register_actor("NotificationSettingsManager", notification_settings_manager_.get());
|
||||
G()->set_notification_settings_manager(notification_settings_manager_actor_.get());
|
||||
poll_manager_ = make_unique<PollManager>(this, create_reference());
|
||||
poll_manager_actor_ = register_actor("PollManager", poll_manager_.get());
|
||||
sponsored_message_manager_ = make_unique<SponsoredMessageManager>(this, create_reference());
|
||||
|
@ -7141,6 +7156,11 @@ void Td::on_request(uint64 id, const td_api::getSavedNotificationSounds &request
|
|||
CREATE_NO_ARGS_REQUEST(GetSavedNotificationSoundsRequest);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::removeSavedNotificationSound &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST(RemoveSavedNotificationSoundRequest, request.notification_sound_id_);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChatNotificationSettingsExceptions &request) {
|
||||
CHECK_IS_USER();
|
||||
bool filter_scope = false;
|
||||
|
|
|
@ -1108,6 +1108,8 @@ class Td final : public Actor {
|
|||
|
||||
void on_request(uint64 id, const td_api::getSavedNotificationSounds &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::removeSavedNotificationSound &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getChatNotificationSettingsExceptions &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getScopeNotificationSettings &request);
|
||||
|
|
|
@ -4491,9 +4491,15 @@ class CliClient final : public Actor {
|
|||
get_args(args, profile_photo_id);
|
||||
send_request(td_api::make_object<td_api::deleteProfilePhoto>(profile_photo_id));
|
||||
} else if (op == "gns") {
|
||||
send_request(td_api::make_object<td_api::getSavedNotificationSound>());
|
||||
int64 notification_sound_id;
|
||||
get_args(args, notification_sound_id);
|
||||
send_request(td_api::make_object<td_api::getSavedNotificationSound>(notification_sound_id));
|
||||
} else if (op == "gnss") {
|
||||
send_request(td_api::make_object<td_api::getSavedNotificationSounds>());
|
||||
} else if (op == "rns") {
|
||||
int64 notification_sound_id;
|
||||
get_args(args, notification_sound_id);
|
||||
send_request(td_api::make_object<td_api::removeSavedNotificationSound>(notification_sound_id));
|
||||
} else if (op == "gcnse" || op == "gcnses") {
|
||||
send_request(td_api::make_object<td_api::getChatNotificationSettingsExceptions>(
|
||||
get_notification_settings_scope(args), op == "gcnses"));
|
||||
|
|
Loading…
Reference in New Issue
Block a user