From 4605f56d3ce400cd61ff09ee8bf3eed2855db7c9 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 10 Nov 2018 01:56:00 +0300 Subject: [PATCH] Add class NotificationType. GitOrigin-RevId: 16951bb0dd0d13a1f3332449350fed4a4a1ef13e --- CMakeLists.txt | 2 + td/generate/scheme/td_api.tl | 8 ++-- td/generate/scheme/td_api.tlo | Bin 137412 -> 137408 bytes td/telegram/NotificationManager.cpp | 18 +++++++- td/telegram/NotificationManager.h | 16 ++++++- td/telegram/NotificationType.cpp | 69 ++++++++++++++++++++++++++++ td/telegram/NotificationType.h | 47 +++++++++++++++++++ td/telegram/Td.cpp | 6 +-- td/telegram/Td.h | 2 +- td/telegram/cli.cpp | 6 +-- 10 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 td/telegram/NotificationType.cpp create mode 100644 td/telegram/NotificationType.h diff --git a/CMakeLists.txt b/CMakeLists.txt index efe9bec4..045597fa 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 ba95ab2c..26e9f50d 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 35be095348cf2b955bb7caefca5daa05b6522d0b..f3805abcee7c6e0726571cf78de0e34b80052cca 100644 GIT binary patch delta 1733 zcmZ8hUr1A76!$ER86z$!Iby{iixro;(IBA(`=fK|O|QCgI{$3WO$V0CW+)9B1m#18 z_1V52eCVM_q6bC6h@chHlY$QgMn=PY@KM4CAMDTW{qFf%-KTSZ=bYc~oO92)3p2*- zjB$FitoYZ1y-l-QW$UKmr5`6YW>>A-ZyC0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@@vZMquI~H zI`VBKbbh{cur&Fp`UJ6;-Dqn8q5ULs!d5^;${I7h+3bL2oNzu^GO7qJuiF~DPq2lK&{R;a#~ z2#1mpZ#)?ti1vq)(fCN~X#84&jts}P|A7nAoC;6^n_?ev#TyOl$HYecK=F*j;E~N*6ItcY$awmqq&` zRI~Zbz-#=C3iiDV>QHf|O4>!0vBrfM;?)JVOCon94fC@W#L*l)$?L=8wQ6 z;>!`EfjNEvYK-L&2T7SaNL057)0BxCwlqk0wlHMOVs2~*_^W&0by#lNMkB-V>;LWK m)#%HgIsFQ^u-jg!!hQVq38aP^+EjhB=@+D9a~|F@!Tkdu19Bb! diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 6115437a..61522074 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 118f08c9..bd5203c7 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 00000000..06f9192b --- /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 00000000..d7672a8f --- /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 438ae789..bd6603fd 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 8f6b5356..2cc31fdb 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 d3211ebc..9bb16e29 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") {