diff --git a/CMakeLists.txt b/CMakeLists.txt index efe9bec41..045597fa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -406,6 +406,7 @@ set(TDLIB_SOURCE td/telegram/net/SessionMultiProxy.cpp td/telegram/NotificationManager.cpp td/telegram/NotificationSettings.cpp + td/telegram/NotificationType.cpp td/telegram/Payments.cpp td/telegram/PasswordManager.cpp td/telegram/PrivacyManager.cpp @@ -536,6 +537,7 @@ set(TDLIB_SOURCE td/telegram/net/TempAuthKeyWatchdog.h td/telegram/NotificationManager.h td/telegram/NotificationSettings.h + td/telegram/NotificationType.h td/telegram/PasswordManager.h td/telegram/Payments.h td/telegram/Photo.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ba95ab2c3..26e9f50de 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1811,8 +1811,8 @@ notificationTypeNewMessage message:message = NotificationType; //@description New secret chat was created notificationTypeNewSecretChat = NotificationType; -//@description New incoming call was received @call_id Call identifier -notificationTypeNewIncomingCall call_id:int32 = NotificationType; +//@description New call was received @call_id Call identifier +notificationTypeNewCall call_id:int32 = NotificationType; //@description Contains information about a notification @id Unique persistent identifier of this notification @type Notification type @@ -2219,7 +2219,7 @@ updateChatDraftMessage chat_id:int53 draft_message:draftMessage order:int64 = Up //@description A list of active notifications in a notification group has changed @notification_group_id Unique notification group identifier @chat_id Identifier of a chat to which all notifications in the group belong //@notification_settings_chat_id Chat identifier, which notification settings must be applied @silent True, if the notifications should be shown without sound //@total_count Total number of active notifications in the group @new_notifications List of new group notifications @edited_notifications List of edited group notifications @removed_notification_ids Identifiers of removed group notifications -updateNotificationGroup chat_id:int53 notification_group_id:int32 notification_settings_chat_id:int53 silent:Bool total_count:int32 new_notifications:vector edited_notifications:vector removed_notification_ids:vector = Update; +updateNotificationGroup notification_group_id:int32 chat_id:int53 notification_settings_chat_id:int53 silent:Bool total_count:int32 new_notifications:vector edited_notifications:vector removed_notification_ids:vector = Update; //@description Contains active notifications that was shown on previous application launches. This update is sent only if a message database is used. In that case it comes once before any updateNotificationGroup update @groups Lists of active notification groups updateActiveNotifications groups:vector = Update; @@ -2614,7 +2614,7 @@ getChatMessageCount chat_id:int53 filter:SearchMessagesFilter return_local:Bool removeNotification notification_id:int32 = Ok; //@description Removes group of active notifications @notification_group_id Notification group identifier @max_notification_id Maximum identifier of removed notifications -removeNotifications notification_group_id:int32 max_notification_id:int32 = Ok; +removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = Ok; //@description Returns a public HTTPS link to a message. Available only for messages in public supergroups and channels diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 35be09534..f3805abce 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 6115437a1..615220743 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -13,6 +13,21 @@ namespace td { NotificationManager::NotificationManager(Td *td) : td_(td) { } +int32 NotificationManager::get_next_notification_id() { + return 0; +} + +void NotificationManager::add_notification(int32 group_id, int32 total_count, DialogId dialog_id, + DialogId notification_settings_dialog_id, bool silent, int32 notification_id, + unique_ptr type) { +} + +void NotificationManager::edit_notification(int32 notification_id, unique_ptr type) { +} + +void NotificationManager::delete_notification(int32 notification_id) { +} + 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")); @@ -20,7 +35,8 @@ void NotificationManager::remove_notification(int32 notification_id, Promise &&promise) { +void NotificationManager::remove_notification_group(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")); } diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 118f08c95..bd5203c7a 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -6,8 +6,13 @@ // #pragma once +#include "td/telegram/DialogId.h" +#include "td/telegram/NotificationType.h" + #include "td/actor/PromiseFuture.h" +#include "td/utils/common.h" + namespace td { class Td; @@ -16,9 +21,18 @@ class NotificationManager { public: explicit NotificationManager(Td *td); + int32 get_next_notification_id(); + + void add_notification(int32 group_id, int32 total_count, DialogId dialog_id, DialogId notification_settings_dialog_id, + bool silent, int32 notification_id, unique_ptr type); + + void edit_notification(int32 notification_id, unique_ptr type); + + void delete_notification(int32 notification_id); + void remove_notification(int32 notification_id, Promise &&promise); - void remove_notifications(int32 group_id, int32 max_notification_id, Promise &&promise); + void remove_notification_group(int32 group_id, int32 max_notification_id, Promise &&promise); private: static bool is_valid_notification_id(int32 notification_id); diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp new file mode 100644 index 000000000..06f9192bc --- /dev/null +++ b/td/telegram/NotificationType.cpp @@ -0,0 +1,69 @@ +// +// 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/NotificationType.h" + +namespace td { + +class NotificationTypeMessage : public NotificationType { + StringBuilder &to_string_builder(StringBuilder &string_builder) const override { + return string_builder << "NewMessageNotification[" << message_id_ << ']'; + } + + Type get_type() const { + return Type::Message; + } + + MessageId message_id_; + + public: + explicit NotificationTypeMessage(MessageId message_id) : message_id_(message_id) { + } +}; + +class NotificationTypeSecretChat : public NotificationType { + StringBuilder &to_string_builder(StringBuilder &string_builder) const override { + return string_builder << "NewSecretChatNotification[]"; + } + + Type get_type() const { + return Type::SecretChat; + } + + public: + NotificationTypeSecretChat() { + } +}; + +class NotificationTypeCall : public NotificationType { + StringBuilder &to_string_builder(StringBuilder &string_builder) const override { + return string_builder << "NewCallNotification[" << call_id_ << ']'; + } + + Type get_type() const { + return Type::Call; + } + + CallId call_id_; + + public: + explicit NotificationTypeCall(CallId call_id) : call_id_(call_id) { + } +}; + +unique_ptr create_new_message_notification(MessageId message_id) { + return make_unique(message_id); +} + +unique_ptr create_new_secret_chat_notification() { + return make_unique(); +} + +unique_ptr create_new_call_notification(CallId call_id) { + return make_unique(call_id); +} + +} // namespace td diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h new file mode 100644 index 000000000..d7672a8f3 --- /dev/null +++ b/td/telegram/NotificationType.h @@ -0,0 +1,47 @@ +// +// 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/telegram/CallId.h" +#include "td/telegram/MessageId.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class NotificationType { + public: + NotificationType() = default; + NotificationType(const NotificationType &) = delete; + NotificationType &operator=(const NotificationType &) = delete; + NotificationType(NotificationType &&) = delete; + NotificationType &operator=(NotificationType &&) = delete; + + virtual ~NotificationType() { + } + + virtual StringBuilder &to_string_builder(StringBuilder &string_builder) const = 0; + + protected: + // append only + enum class Type : int32 { Message, SecretChat, Call }; + + virtual Type get_type() const = 0; +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, const NotificationType ¬ification_type) { + return notification_type.to_string_builder(string_builder); +} + +unique_ptr create_new_message_notification(MessageId message_id); + +unique_ptr create_new_secret_chat_notification(); + +unique_ptr create_new_call_notification(CallId call_id); + +} // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 438ae7897..bd6603fd0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5070,11 +5070,11 @@ void Td::on_request(uint64 id, const td_api::removeNotification &request) { notification_manager_->remove_notification(request.notification_id_, std::move(promise)); } -void Td::on_request(uint64 id, const td_api::removeNotifications &request) { +void Td::on_request(uint64 id, const td_api::removeNotificationGroup &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - notification_manager_->remove_notifications(request.notification_group_id_, request.max_notification_id_, - std::move(promise)); + notification_manager_->remove_notification_group(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 8f6b53569..2cc31fdbc 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -511,7 +511,7 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::removeNotification &request); - void on_request(uint64 id, const td_api::removeNotifications &request); + void on_request(uint64 id, const td_api::removeNotificationGroup &request); void on_request(uint64 id, const td_api::deleteMessages &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d3211ebc1..9bb16e291 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3295,12 +3295,12 @@ class CliClient final : public Actor { } else if (op == "rn") { string notification_id = args; send_request(make_tl_object(to_integer(notification_id))); - } else if (op == "rns") { + } else if (op == "rng") { 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))); + 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") {