Add sender_name to notificationTypeNewPushMessage.

GitOrigin-RevId: 6fd18136c30e23787e4c7e60ad8c8e81c12eebb3
This commit is contained in:
levlam 2020-02-18 16:04:37 +03:00
parent 9183772611
commit c2526c67c8
6 changed files with 40 additions and 27 deletions

View File

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

Binary file not shown.

View File

@ -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<telegram_api::user>(
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<telegram_api::user>(
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<int64> NotificationManager::get_push_receiver_id(string payload) {

View File

@ -388,6 +388,7 @@ class NotificationManager : public Actor {
NotificationGroupId group_id;
NotificationId notification_id;
UserId sender_user_id;
string sender_name;
};
std::unordered_map<FullMessageId, TemporaryNotification, FullMessageIdHash> temporary_notifications_;
std::unordered_map<NotificationId, FullMessageId, NotificationIdHash> temporary_notification_message_ids_;

View File

@ -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<td_api::notificationTypeNewPushMessage>(
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<NotificationType> create_new_call_notification(CallId call_id) {
return make_unique<NotificationTypeCall>(call_id);
}
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, MessageId message_id,
string key, string arg, Photo photo,
Document document) {
return td::make_unique<NotificationTypePushMessage>(sender_user_id, message_id, std::move(key), std::move(arg),
std::move(photo), std::move(document));
unique_ptr<NotificationType> 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<NotificationTypePushMessage>(sender_user_id, std::move(sender_name), message_id,
std::move(key), std::move(arg), std::move(photo),
std::move(document));
}
} // namespace td

View File

@ -59,8 +59,8 @@ unique_ptr<NotificationType> create_new_secret_chat_notification();
unique_ptr<NotificationType> create_new_call_notification(CallId call_id);
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, MessageId message_id,
string key, string arg, Photo photo,
Document document);
unique_ptr<NotificationType> 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