From c2526c67c84c23b335cd979bd321924754e117da Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Feb 2020 16:04:37 +0300 Subject: [PATCH] Add sender_name to notificationTypeNewPushMessage. GitOrigin-RevId: 6fd18136c30e23787e4c7e60ad8c8e81c12eebb3 --- td/generate/scheme/td_api.tl | 6 ++++-- td/generate/scheme/td_api.tlo | Bin 167372 -> 167408 bytes td/telegram/NotificationManager.cpp | 30 +++++++++++++++++----------- td/telegram/NotificationManager.h | 1 + td/telegram/NotificationType.cpp | 24 ++++++++++++---------- td/telegram/NotificationType.h | 6 +++--- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f0478d03..0ce71cba 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2301,8 +2301,10 @@ notificationTypeNewCall call_id:int32 = NotificationType; //@description New message was received through a push notification //@message_id The message identifier. The message will not be available in the chat history, but the ID can be used in viewMessages and as reply_to_message_id -//@sender_user_id Sender of the message. Corresponding user may be inaccessible @content Push message content -notificationTypeNewPushMessage message_id:int53 sender_user_id:int32 content:PushMessageContent = NotificationType; +//@sender_user_id Sender of the message; 0 if unknown. Corresponding user may be inaccessible +//@sender_name Name of the sender; can be different from the name of the sender user +//@content Push message content +notificationTypeNewPushMessage message_id:int53 sender_user_id:int32 sender_name:string content:PushMessageContent = NotificationType; //@class NotificationGroupType @description Describes the type of notifications in a notification group diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 761a9c091b7c0eb9886a64ef13d5cec35a376353..cf3d05b0d42011b7a11f63c379004feec82cda55 100644 GIT binary patch delta 175 zcmX>zo9n}Dt_?hrEIaJEw{I4ZJn|XL+J1wF(SaGvoNh3g(E!2<5MVTr04cnAOvr}; z2#TE9bU19=4uZs{&k$hL;DpICP8a;ks66?DHisxk2&5PUuF7%6xUFM-CO17%fKhn5 rj36TqTno!|LqW#i=@KlA3X>b&iADYB z$eB%t!?x`pNNoBH0Y(i@m@MOT-B>2&$se>iL_tCz#UOB1jw@zL?<7~b>4^f2!qa60 g8F}DZn5P>GG6qjyA;_o#wyynxAmjE6f=miE0Q5aCNB{r; diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index bc572f43..9c0debd6 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3247,10 +3247,11 @@ Status NotificationManager::process_push_notification_payload(string payload, bo if (sender_photo != nullptr) { flags |= telegram_api::user::PHOTO_MASK; } + auto user_name = sender_user_id.get() == 136817688 ? "Channel" : sender_name; auto user = telegram_api::make_object( flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), sender_access_hash, sender_name, + false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), sender_access_hash, user_name, string(), string(), string(), std::move(sender_photo), nullptr, 0, Auto(), string(), string()); td_->contacts_manager_->on_get_user(std::move(user), "process_push_notification_payload"); } @@ -3570,11 +3571,12 @@ void NotificationManager::add_message_push_notification( if (sender_user_id.is_valid() && !td_->contacts_manager_->have_user_force(sender_user_id)) { int32 flags = telegram_api::user::FIRST_NAME_MASK | telegram_api::user::MIN_MASK; + auto user_name = sender_user_id.get() == 136817688 ? "Channel" : sender_name; auto user = telegram_api::make_object( flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), 0, sender_name, string(), - string(), string(), nullptr, nullptr, 0, Auto(), string(), string()); + false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), 0, user_name, string(), string(), + string(), nullptr, nullptr, 0, Auto(), string(), string()); td_->contacts_manager_->on_get_user(std::move(user), "add_message_push_notification"); } @@ -3593,7 +3595,8 @@ void NotificationManager::add_message_push_notification( if (logevent_id != 0) { VLOG(notifications) << "Register temporary " << notification_id << " with logevent " << logevent_id; temporary_notification_logevent_ids_[notification_id] = logevent_id; - temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id}; + temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id, + sender_name}; temporary_notification_message_ids_[notification_id] = FullMessageId(dialog_id, message_id); } push_notification_promises_[notification_id].push_back(std::move(promise)); @@ -3601,14 +3604,15 @@ void NotificationManager::add_message_push_notification( auto group_type = info.group_type; auto settings_dialog_id = info.settings_dialog_id; VLOG(notifications) << "Add message push " << notification_id << " of type " << loc_key << " for " << message_id - << "/" << random_id << " in " << dialog_id << ", sent by " << sender_user_id << " at " << date - << " with arg " << arg << ", photo " << photo << " and document " << document << " to " - << group_id << " of type " << group_type << " with settings from " << settings_dialog_id; + << "/" << random_id << " in " << dialog_id << ", sent by " << sender_user_id << "/\"" + << sender_name << "\" at " << date << " with arg " << arg << ", photo " << photo + << " and document " << document << " to " << group_id << " of type " << group_type + << " with settings from " << settings_dialog_id; add_notification(group_id, group_type, dialog_id, date, settings_dialog_id, initial_is_silent, is_silent, 0, notification_id, - create_new_push_message_notification(sender_user_id, message_id, std::move(loc_key), std::move(arg), - std::move(photo), std::move(document)), + create_new_push_message_notification(sender_user_id, sender_name, message_id, std::move(loc_key), + std::move(arg), std::move(photo), std::move(document)), "add_message_push_notification"); } @@ -3701,6 +3705,7 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes auto group_id = it->second.group_id; auto notification_id = it->second.notification_id; auto sender_user_id = it->second.sender_user_id; + auto sender_name = it->second.sender_name; CHECK(group_id.is_valid()); CHECK(notification_id.is_valid()); @@ -3725,9 +3730,10 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes push_notification_promises_[notification_id].push_back(std::move(promise)); - edit_notification(group_id, notification_id, - create_new_push_message_notification(sender_user_id, message_id, std::move(loc_key), std::move(arg), - std::move(photo), std::move(document))); + edit_notification( + group_id, notification_id, + create_new_push_message_notification(sender_user_id, std::move(sender_name), message_id, std::move(loc_key), + std::move(arg), std::move(photo), std::move(document))); } Result NotificationManager::get_push_receiver_id(string payload) { diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 7ed05aa7..89ac66f5 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -388,6 +388,7 @@ class NotificationManager : public Actor { NotificationGroupId group_id; NotificationId notification_id; UserId sender_user_id; + string sender_name; }; std::unordered_map temporary_notifications_; std::unordered_map temporary_notification_message_ids_; diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 798578ac..43825052 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -321,25 +321,28 @@ class NotificationTypePushMessage : public NotificationType { 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, get_push_message_content_object(key_, arg_, photo_, document_)); + message_id_.get(), sender_user_id, sender_name_, + get_push_message_content_object(key_, arg_, photo_, document_)); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { - return string_builder << "NewPushMessageNotification[" << sender_user_id_ << ", " << message_id_ << ", " << key_ - << ", " << arg_ << ", " << photo_ << ", " << document_ << ']'; + return string_builder << "NewPushMessageNotification[" << sender_user_id_ << "/\"" << sender_name_ << "\", " + << message_id_ << ", " << key_ << ", " << arg_ << ", " << photo_ << ", " << document_ << ']'; } UserId sender_user_id_; MessageId message_id_; + string sender_name_; string key_; string arg_; Photo photo_; Document document_; public: - NotificationTypePushMessage(UserId sender_user_id, MessageId message_id, string key, string arg, Photo photo, - Document document) + NotificationTypePushMessage(UserId sender_user_id, string sender_name, MessageId message_id, string key, string arg, + Photo photo, Document document) : sender_user_id_(std::move(sender_user_id)) + , sender_name_(std::move(sender_name)) , message_id_(message_id) , key_(std::move(key)) , arg_(std::move(arg)) @@ -360,11 +363,12 @@ 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, Photo photo, - Document document) { - return td::make_unique(sender_user_id, message_id, std::move(key), std::move(arg), - std::move(photo), std::move(document)); +unique_ptr create_new_push_message_notification(UserId sender_user_id, string sender_name, + MessageId message_id, string key, string arg, + Photo photo, Document document) { + return td::make_unique(sender_user_id, std::move(sender_name), message_id, + std::move(key), std::move(arg), std::move(photo), + std::move(document)); } } // namespace td diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h index a33b071c..49018d33 100644 --- a/td/telegram/NotificationType.h +++ b/td/telegram/NotificationType.h @@ -59,8 +59,8 @@ unique_ptr create_new_secret_chat_notification(); unique_ptr create_new_call_notification(CallId call_id); -unique_ptr create_new_push_message_notification(UserId sender_user_id, MessageId message_id, - string key, string arg, Photo photo, - Document document); +unique_ptr create_new_push_message_notification(UserId sender_user_id, string sender_name, + MessageId message_id, string key, string arg, + Photo photo, Document document); } // namespace td