// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 // // 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" #include "td/telegram/ContactsManager.h" #include "td/telegram/Global.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/Td.h" namespace td { class NotificationTypeMessage : public NotificationType { bool can_be_delayed() const override { return message_id_.is_valid() && message_id_.is_server(); } bool is_temporary() const override { return false; } MessageId get_message_id() const override { return message_id_; } td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object({dialog_id, message_id_}); if (message_object == nullptr) { return nullptr; } return td_api::make_object(std::move(message_object)); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { return string_builder << "NewMessageNotification[" << message_id_ << ']'; } /* Type get_type() const override { return Type::Message; } */ MessageId message_id_; public: explicit NotificationTypeMessage(MessageId message_id) : message_id_(message_id) { } }; class NotificationTypeSecretChat : public NotificationType { bool can_be_delayed() const override { return false; } bool is_temporary() const override { return false; } MessageId get_message_id() const override { return MessageId(); } td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { return string_builder << "NewSecretChatNotification[]"; } /* Type get_type() const override { return Type::SecretChat; } */ public: NotificationTypeSecretChat() { } }; class NotificationTypeCall : public NotificationType { bool can_be_delayed() const override { return false; } bool is_temporary() const override { return false; } MessageId get_message_id() const override { return MessageId::max(); } td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(call_id_.get()); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { return string_builder << "NewCallNotification[" << call_id_ << ']'; } /* Type get_type() const override { return Type::Call; } */ CallId call_id_; public: explicit NotificationTypeCall(CallId call_id) : call_id_(call_id) { } }; class NotificationTypePushMessage : public NotificationType { bool can_be_delayed() const override { return false; } bool is_temporary() const override { return true; } MessageId get_message_id() const override { return message_id_; } td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { auto sender_user_id = G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object( sender_user_id_, "get_notification_type_object"); return td_api::make_object(message_id_.get(), sender_user_id, key_, arg_); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { return string_builder << "NewPushMessageNotification[" << sender_user_id_ << ", " << message_id_ << ", " << key_ << ", " << arg_ << ']'; } /* Type get_type() const override { return Type::PushMessage; } */ UserId sender_user_id_; MessageId message_id_; string key_; string arg_; public: NotificationTypePushMessage(UserId sender_user_id, MessageId message_id, string key, string arg) : sender_user_id_(std::move(sender_user_id)) , message_id_(message_id) , key_(std::move(key)) , arg_(std::move(arg)) { } }; 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); } unique_ptr create_new_push_message_notification(UserId sender_user_id, MessageId message_id, string key, string arg) { return td::make_unique(sender_user_id, message_id, std::move(key), std::move(arg)); } } // namespace td