Add class NotificationType.

GitOrigin-RevId: 16951bb0dd0d13a1f3332449350fed4a4a1ef13e
This commit is contained in:
levlam 2018-11-10 01:56:00 +03:00
parent 5f23a99fca
commit 4605f56d3c
10 changed files with 161 additions and 13 deletions

View File

@ -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

View File

@ -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<notification> edited_notifications:vector<notification> removed_notification_ids:vector<int32> = Update;
updateNotificationGroup notification_group_id:int32 chat_id:int53 notification_settings_chat_id:int53 silent:Bool total_count:int32 new_notifications:vector<notification> edited_notifications:vector<notification> removed_notification_ids:vector<int32> = 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<notificationGroup> = 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

Binary file not shown.

View File

@ -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<NotificationType> type) {
}
void NotificationManager::edit_notification(int32 notification_id, unique_ptr<NotificationType> type) {
}
void NotificationManager::delete_notification(int32 notification_id) {
}
void NotificationManager::remove_notification(int32 notification_id, Promise<Unit> &&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<Uni
promise.set_value(Unit());
}
void NotificationManager::remove_notifications(int32 group_id, int32 max_notification_id, Promise<Unit> &&promise) {
void NotificationManager::remove_notification_group(int32 group_id, int32 max_notification_id,
Promise<Unit> &&promise) {
if (!is_valid_group_id(group_id)) {
return promise.set_error(Status::Error(400, "Group identifier is invalid"));
}

View File

@ -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<NotificationType> type);
void edit_notification(int32 notification_id, unique_ptr<NotificationType> type);
void delete_notification(int32 notification_id);
void remove_notification(int32 notification_id, Promise<Unit> &&promise);
void remove_notifications(int32 group_id, int32 max_notification_id, Promise<Unit> &&promise);
void remove_notification_group(int32 group_id, int32 max_notification_id, Promise<Unit> &&promise);
private:
static bool is_valid_notification_id(int32 notification_id);

View File

@ -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<NotificationType> create_new_message_notification(MessageId message_id) {
return make_unique<NotificationTypeMessage>(message_id);
}
unique_ptr<NotificationType> create_new_secret_chat_notification() {
return make_unique<NotificationTypeSecretChat>();
}
unique_ptr<NotificationType> create_new_call_notification(CallId call_id) {
return make_unique<NotificationTypeCall>(call_id);
}
} // namespace td

View File

@ -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 &notification_type) {
return notification_type.to_string_builder(string_builder);
}
unique_ptr<NotificationType> create_new_message_notification(MessageId message_id);
unique_ptr<NotificationType> create_new_secret_chat_notification();
unique_ptr<NotificationType> create_new_call_notification(CallId call_id);
} // namespace td

View File

@ -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) {

View File

@ -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);

View File

@ -3295,12 +3295,12 @@ class CliClient final : public Actor {
} else if (op == "rn") {
string notification_id = args;
send_request(make_tl_object<td_api::removeNotification>(to_integer<int32>(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<td_api::removeNotifications>(to_integer<int32>(group_id),
to_integer<int32>(max_notification_id)));
send_request(make_tl_object<td_api::removeNotificationGroup>(to_integer<int32>(group_id),
to_integer<int32>(max_notification_id)));
} else if (op == "gcrss") {
send_request(make_tl_object<td_api::getChatReportSpamState>(as_chat_id(args)));
} else if (op == "ccrss") {