From 5f23a99fca53f30531e18fa6c98c9af2601b5373 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 9 Nov 2018 17:14:02 +0300 Subject: [PATCH] Add dummy NotificationManager. GitOrigin-RevId: f8915918dfa91562b7acad45133c1c493affc896 --- CMakeLists.txt | 2 ++ td/telegram/NotificationManager.cpp | 41 +++++++++++++++++++++++++++++ td/telegram/NotificationManager.h | 31 ++++++++++++++++++++++ td/telegram/Td.cpp | 9 +++++-- td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 9 +++++++ 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 td/telegram/NotificationManager.cpp create mode 100644 td/telegram/NotificationManager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e9f629213..efe9bec41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -404,6 +404,7 @@ set(TDLIB_SOURCE td/telegram/net/Session.cpp td/telegram/net/SessionProxy.cpp td/telegram/net/SessionMultiProxy.cpp + td/telegram/NotificationManager.cpp td/telegram/NotificationSettings.cpp td/telegram/Payments.cpp td/telegram/PasswordManager.cpp @@ -533,6 +534,7 @@ set(TDLIB_SOURCE td/telegram/net/SessionProxy.h td/telegram/net/SessionMultiProxy.h td/telegram/net/TempAuthKeyWatchdog.h + td/telegram/NotificationManager.h td/telegram/NotificationSettings.h td/telegram/PasswordManager.h td/telegram/Payments.h diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp new file mode 100644 index 000000000..6115437a1 --- /dev/null +++ b/td/telegram/NotificationManager.cpp @@ -0,0 +1,41 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// 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) +// +#include "td/telegram/NotificationManager.h" + +#include "td/telegram/Td.h" + +namespace td { + +NotificationManager::NotificationManager(Td *td) : td_(td) { +} + +void NotificationManager::remove_notification(int32 notification_id, Promise &&promise) { + if (!is_valid_notification_id(notification_id)) { + return promise.set_error(Status::Error(400, "Notification identifier is invalid")); + } + promise.set_value(Unit()); +} + +void NotificationManager::remove_notifications(int32 group_id, int32 max_notification_id, Promise &&promise) { + if (!is_valid_group_id(group_id)) { + return promise.set_error(Status::Error(400, "Group identifier is invalid")); + } + if (!is_valid_notification_id(max_notification_id)) { + return promise.set_error(Status::Error(400, "Notification identifier is invalid")); + } + promise.set_value(Unit()); +} + +bool NotificationManager::is_valid_notification_id(int32 notification_id) { + return notification_id > 0; +} + +bool NotificationManager::is_valid_group_id(int32 group_id) { + return group_id > 0; +} + +} // namespace td diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h new file mode 100644 index 000000000..118f08c95 --- /dev/null +++ b/td/telegram/NotificationManager.h @@ -0,0 +1,31 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// 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/actor/PromiseFuture.h" + +namespace td { + +class Td; + +class NotificationManager { + public: + explicit NotificationManager(Td *td); + + void remove_notification(int32 notification_id, Promise &&promise); + + void remove_notifications(int32 group_id, int32 max_notification_id, Promise &&promise); + + private: + static bool is_valid_notification_id(int32 notification_id); + + static bool is_valid_group_id(int32 group_id); + + Td *td_; +}; + +} // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4b9037f4a..438ae7897 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -44,6 +44,7 @@ #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" +#include "td/telegram/NotificationManager.h" #include "td/telegram/NotificationSettings.h" #include "td/telegram/PasswordManager.h" #include "td/telegram/Payments.h" @@ -3603,6 +3604,8 @@ void Td::dec_actor_refcnt() { LOG(DEBUG) << "InlineQueriesManager was cleared " << timer; messages_manager_.reset(); LOG(DEBUG) << "MessagesManager was cleared " << timer; + notification_manager_.reset(); + LOG(DEBUG) << "NotificationManager was cleared " << timer; stickers_manager_.reset(); LOG(DEBUG) << "StickersManager was cleared " << timer; updates_manager_.reset(); @@ -4023,6 +4026,7 @@ Status Td::init(DbKey key) { audios_manager_ = make_unique(this); callback_queries_manager_ = make_unique(this); documents_manager_ = make_unique(this); + notification_manager_ = make_unique(this); video_notes_manager_ = make_unique(this); videos_manager_ = make_unique(this); voice_notes_manager_ = make_unique(this); @@ -5063,13 +5067,14 @@ void Td::on_request(uint64 id, td_api::getChatMessageCount &request) { void Td::on_request(uint64 id, const td_api::removeNotification &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - // TODO notification_manager->remove_notification(request.notification_id_, std::move(promise)); + notification_manager_->remove_notification(request.notification_id_, std::move(promise)); } void Td::on_request(uint64 id, const td_api::removeNotifications &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - // TODO notification_manager->remove_notifications(request.notification_group_id_, request.max_notification_id_, std::move(promise)); + notification_manager_->remove_notifications(request.notification_group_id_, request.max_notification_id_, + std::move(promise)); } void Td::on_request(uint64 id, const td_api::deleteMessages &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 19ccdd59e..8f6b53569 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -49,6 +49,7 @@ class HashtagHints; class LanguagePackManager; class MessagesManager; class NetStatsManager; +class NotificationManager; class PasswordManager; class PhoneNumberManager; class PrivacyManager; @@ -125,6 +126,7 @@ class Td final : public NetQueryCallback { unique_ptr audios_manager_; unique_ptr callback_queries_manager_; unique_ptr documents_manager_; + unique_ptr notification_manager_; unique_ptr video_notes_manager_; unique_ptr videos_manager_; unique_ptr voice_notes_manager_; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 90851d0be..d3211ebc1 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3292,6 +3292,15 @@ class CliClient final : public Actor { to_integer(mute_for), sound, as_bool(show_previews)))); } else if (op == "rans") { send_request(make_tl_object()); + } else if (op == "rn") { + string notification_id = args; + send_request(make_tl_object(to_integer(notification_id))); + } else if (op == "rns") { + string group_id; + string max_notification_id; + std::tie(group_id, max_notification_id) = split(args); + send_request(make_tl_object(to_integer(group_id), + to_integer(max_notification_id))); } else if (op == "gcrss") { send_request(make_tl_object(as_chat_id(args))); } else if (op == "ccrss") {