2018-11-09 23:56:00 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
2018-11-09 23:56:00 +01:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2019-03-30 15:59:35 +01:00
|
|
|
#include "td/telegram/ContactsManager.h"
|
2019-01-06 20:59:17 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2018-11-15 16:58:33 +01:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
|
2019-04-05 08:09:58 +02:00
|
|
|
#include "td/utils/misc.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class NotificationTypeMessage : public NotificationType {
|
2018-11-15 17:09:01 +01:00
|
|
|
bool can_be_delayed() const override {
|
2019-03-26 14:39:15 +01:00
|
|
|
return message_id_.is_valid() && message_id_.is_server();
|
2018-11-15 17:09:01 +01:00
|
|
|
}
|
|
|
|
|
2019-03-30 21:49:14 +01:00
|
|
|
bool is_temporary() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-20 15:08:44 +01:00
|
|
|
MessageId get_message_id() const override {
|
|
|
|
return message_id_;
|
|
|
|
}
|
|
|
|
|
2018-11-15 16:58:33 +01:00
|
|
|
td_api::object_ptr<td_api::NotificationType> 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<td_api::notificationTypeNewMessage>(std::move(message_object));
|
|
|
|
}
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
StringBuilder &to_string_builder(StringBuilder &string_builder) const override {
|
|
|
|
return string_builder << "NewMessageNotification[" << message_id_ << ']';
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
/*
|
2018-12-11 21:18:58 +01:00
|
|
|
Type get_type() const override {
|
2018-11-09 23:56:00 +01:00
|
|
|
return Type::Message;
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
*/
|
2018-11-09 23:56:00 +01:00
|
|
|
MessageId message_id_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit NotificationTypeMessage(MessageId message_id) : message_id_(message_id) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NotificationTypeSecretChat : public NotificationType {
|
2018-11-15 17:09:01 +01:00
|
|
|
bool can_be_delayed() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-30 21:49:14 +01:00
|
|
|
bool is_temporary() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-20 15:08:44 +01:00
|
|
|
MessageId get_message_id() const override {
|
|
|
|
return MessageId();
|
|
|
|
}
|
|
|
|
|
2018-11-15 16:58:33 +01:00
|
|
|
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
|
|
|
return td_api::make_object<td_api::notificationTypeNewSecretChat>();
|
|
|
|
}
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
StringBuilder &to_string_builder(StringBuilder &string_builder) const override {
|
|
|
|
return string_builder << "NewSecretChatNotification[]";
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
/*
|
2018-12-11 21:18:58 +01:00
|
|
|
Type get_type() const override {
|
2018-11-09 23:56:00 +01:00
|
|
|
return Type::SecretChat;
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
*/
|
2018-11-09 23:56:00 +01:00
|
|
|
public:
|
|
|
|
NotificationTypeSecretChat() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NotificationTypeCall : public NotificationType {
|
2018-11-15 17:09:01 +01:00
|
|
|
bool can_be_delayed() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-30 21:49:14 +01:00
|
|
|
bool is_temporary() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-20 15:08:44 +01:00
|
|
|
MessageId get_message_id() const override {
|
2018-11-22 18:17:26 +01:00
|
|
|
return MessageId::max();
|
2018-11-20 15:08:44 +01:00
|
|
|
}
|
|
|
|
|
2018-11-15 16:58:33 +01:00
|
|
|
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
|
|
|
return td_api::make_object<td_api::notificationTypeNewCall>(call_id_.get());
|
|
|
|
}
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
StringBuilder &to_string_builder(StringBuilder &string_builder) const override {
|
|
|
|
return string_builder << "NewCallNotification[" << call_id_ << ']';
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
/*
|
2018-12-11 21:18:58 +01:00
|
|
|
Type get_type() const override {
|
2018-11-09 23:56:00 +01:00
|
|
|
return Type::Call;
|
|
|
|
}
|
2019-03-28 22:08:57 +01:00
|
|
|
*/
|
2018-11-09 23:56:00 +01:00
|
|
|
CallId call_id_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit NotificationTypeCall(CallId call_id) : call_id_(call_id) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-28 22:08:57 +01:00
|
|
|
class NotificationTypePushMessage : public NotificationType {
|
|
|
|
bool can_be_delayed() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-30 21:49:14 +01:00
|
|
|
bool is_temporary() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-28 22:08:57 +01:00
|
|
|
MessageId get_message_id() const override {
|
|
|
|
return message_id_;
|
|
|
|
}
|
|
|
|
|
2019-04-09 16:33:27 +02:00
|
|
|
static td_api::object_ptr<td_api::PushMessageContent> get_push_message_content_object(Slice key, const string &arg,
|
|
|
|
const Photo &photo) {
|
2019-04-05 08:09:58 +02:00
|
|
|
bool is_pinned = false;
|
|
|
|
if (begins_with(key, "PINNED_")) {
|
|
|
|
is_pinned = true;
|
|
|
|
key = key.substr(7);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentHidden>(is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGES") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentMediaAlbum>(to_integer<int32>(arg), true, true);
|
|
|
|
}
|
|
|
|
CHECK(key.size() > 8);
|
|
|
|
switch (key[8]) {
|
|
|
|
case 'A':
|
|
|
|
if (key == "MESSAGE_ANIMATION") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentAnimation>(is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
if (key == "MESSAGE_BASIC_GROUP_CHAT_CREATE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentBasicGroupChatCreate>();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
if (key == "MESSAGE_CHAT_ADD_MEMBERS") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatAddMembers>(arg, false, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_ADD_MEMBERS_RETURNED") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatAddMembers>(arg, false, true);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_ADD_MEMBERS_YOU") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatAddMembers>(arg, true, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_CHANGE_PHOTO") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatChangePhoto>();
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_CHANGE_TITLE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatChangeTitle>();
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_DELETE_MEMBER") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatDeleteMember>(arg, false, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_DELETE_MEMBER_LEFT") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatDeleteMember>(arg, false, true);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_DELETE_MEMBER_YOU") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatDeleteMember>(arg, true, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CHAT_JOIN_BY_LINK") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentChatJoinByLink>();
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CONTACT") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentContact>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_CONTACT_REGISTERED") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentContactRegistered>();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
if (key == "MESSAGE_DOCUMENT") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentDocument>(is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
if (key == "MESSAGE_FORWARDS") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentMessageForwards>(to_integer<int32>(arg));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
if (key == "MESSAGE_GAME") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentGame>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_GAME_SCORE") {
|
|
|
|
int32 score = 0;
|
|
|
|
string title;
|
|
|
|
if (!is_pinned) {
|
|
|
|
string score_str;
|
|
|
|
std::tie(score_str, title) = split(arg);
|
|
|
|
score = to_integer<int32>(score_str);
|
|
|
|
}
|
|
|
|
return td_api::make_object<td_api::pushMessageContentGameScore>(title, score, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
if (key == "MESSAGE_INVOICE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentInvoice>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if (key == "MESSAGE_LIVE_LOCATION") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentLocation>(false, is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_LOCATION") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentLocation>(true, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
if (key == "MESSAGE_PHOTO") {
|
2019-04-09 16:33:27 +02:00
|
|
|
auto file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
|
|
|
|
return td_api::make_object<td_api::pushMessageContentPhoto>(get_photo_object(file_manager, &photo), arg,
|
|
|
|
false, is_pinned);
|
2019-04-05 08:09:58 +02:00
|
|
|
}
|
|
|
|
if (key == "MESSAGE_PHOTOS") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentMediaAlbum>(to_integer<int32>(arg), true, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_POLL") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentPoll>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
if (key == "MESSAGE_SECRET_PHOTO") {
|
2019-04-09 16:33:27 +02:00
|
|
|
return td_api::make_object<td_api::pushMessageContentPhoto>(nullptr, arg, true, false);
|
2019-04-05 08:09:58 +02:00
|
|
|
}
|
|
|
|
if (key == "MESSAGE_SECRET_VIDEO") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentVideo>(true, false);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_SCREENSHOT_TAKEN") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentScreenshotTaken>();
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_STICKER") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentSticker>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
if (key == "MESSAGE_TEXT") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentText>(arg, is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
if (key == "MESSAGE_VIDEO") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentVideo>(false, is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_VIDEO_NOTE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentVideoNote>(is_pinned);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_VIDEOS") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentMediaAlbum>(to_integer<int32>(arg), false, true);
|
|
|
|
}
|
|
|
|
if (key == "MESSAGE_VOICE_NOTE") {
|
|
|
|
return td_api::make_object<td_api::pushMessageContentVoiceNote>(is_pinned);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2019-03-28 22:08:57 +01:00
|
|
|
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
2019-03-30 21:49:14 +01:00
|
|
|
auto sender_user_id = G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object(
|
|
|
|
sender_user_id_, "get_notification_type_object");
|
2019-04-09 16:33:27 +02:00
|
|
|
return td_api::make_object<td_api::notificationTypeNewPushMessage>(
|
|
|
|
message_id_.get(), sender_user_id, get_push_message_content_object(key_, arg_, photo_));
|
2019-03-28 22:08:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &to_string_builder(StringBuilder &string_builder) const override {
|
2019-03-30 15:59:35 +01:00
|
|
|
return string_builder << "NewPushMessageNotification[" << sender_user_id_ << ", " << message_id_ << ", " << key_
|
2019-04-09 16:33:27 +02:00
|
|
|
<< ", " << arg_ << ", " << photo_ << ']';
|
2019-03-28 22:08:57 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
Type get_type() const override {
|
|
|
|
return Type::PushMessage;
|
|
|
|
}
|
|
|
|
*/
|
2019-03-30 15:59:35 +01:00
|
|
|
UserId sender_user_id_;
|
2019-03-28 22:08:57 +01:00
|
|
|
MessageId message_id_;
|
|
|
|
string key_;
|
|
|
|
string arg_;
|
2019-04-09 16:33:27 +02:00
|
|
|
Photo photo_;
|
2019-03-28 22:08:57 +01:00
|
|
|
|
|
|
|
public:
|
2019-04-09 16:33:27 +02:00
|
|
|
NotificationTypePushMessage(UserId sender_user_id, MessageId message_id, string key, string arg, Photo photo)
|
2019-03-30 15:59:35 +01:00
|
|
|
: sender_user_id_(std::move(sender_user_id))
|
2019-03-28 22:08:57 +01:00
|
|
|
, message_id_(message_id)
|
|
|
|
, key_(std::move(key))
|
2019-04-09 16:33:27 +02:00
|
|
|
, arg_(std::move(arg))
|
|
|
|
, photo_(std::move(photo)) {
|
2019-03-28 22:08:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-30 15:59:35 +01:00
|
|
|
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, MessageId message_id,
|
2019-04-09 16:33:27 +02:00
|
|
|
string key, string arg, Photo photo) {
|
|
|
|
return td::make_unique<NotificationTypePushMessage>(sender_user_id, message_id, std::move(key), std::move(arg),
|
|
|
|
std::move(photo));
|
2019-03-28 22:08:57 +01:00
|
|
|
}
|
|
|
|
|
2018-11-09 23:56:00 +01:00
|
|
|
} // namespace td
|