From 508889fadf90200f272de686c4d9035e01908567 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 30 Mar 2019 17:59:35 +0300 Subject: [PATCH] Store sender_user_id in message push notification. GitOrigin-RevId: e6dbf304266c63a92e5949a1ee48444f8c0e958f --- td/telegram/ContactsManager.cpp | 2 +- td/telegram/MessagesManager.cpp | 7 ------- td/telegram/NotificationManager.cpp | 22 +++++++++++----------- td/telegram/NotificationType.cpp | 23 +++++++++++------------ td/telegram/NotificationType.h | 5 +++-- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 396880b0..9a9ea3c5 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2945,7 +2945,7 @@ tl_object_ptr ContactsManager::get_input_encry } const DialogPhoto *ContactsManager::get_user_dialog_photo(UserId user_id) { - auto u = get_user_force(user_id); + auto u = get_user(user_id); if (u == nullptr) { return nullptr; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b68dbe49..c901dfe9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18210,19 +18210,12 @@ Result MessagesManager::get_messag return Status::Error("Ignore notification sent to bot"); } - if (sender_user_id.is_valid() && !td_->contacts_manager_->have_user(sender_user_id)) { - // allow messages from unknown sender, we will use only sender's name and photo - // return Status::Error("Ignore notification from unknown user"); - } - Dialog *d = get_dialog_force(dialog_id); if (d == nullptr) { return Status::Error("Ignore notification in unknown chat"); - ; } if (message_id.is_valid() && message_id.get() <= d->last_new_message_id.get()) { return Status::Error("Ignore notification about known message"); - ; } if (random_id != 0) { CHECK(dialog_id.get_type() == DialogType::SecretChat); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 179fc226..cc17e940 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -12,7 +12,6 @@ #include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DeviceTokenManager.h" -#include "td/telegram/files/FileManager.h" #include "td/telegram/Global.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" @@ -2809,13 +2808,14 @@ Status NotificationManager::process_message_push_notification(DialogId dialog_id return Status::OK(); } - auto sender_photo = td_->contacts_manager_->get_user_dialog_photo(sender_user_id); - string sender_photo_path; - if (sender_photo != nullptr) { - FileView file_view = td_->file_manager_->get_file_view(sender_photo->small_file_id); - if (file_view.has_local_location()) { - sender_photo_path = file_view.path(); - } + if (sender_user_id.is_valid() && !td_->contacts_manager_->have_user(sender_user_id)) { + int32 flags = telegram_api::user::FIRST_NAME_MASK | telegram_api::user::MIN_MASK; + 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*/, sender_user_id.get(), 0, sender_name, string(), string(), string(), + nullptr, nullptr, 0, string(), string(), string()); + td_->contacts_manager_->on_get_user(std::move(user), "process_message_push_notification"); } auto group_id = info.group_id; @@ -2826,9 +2826,9 @@ Status NotificationManager::process_message_push_notification(DialogId dialog_id << " with args " << loc_args << " 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, is_silent, 0, notification_id, - create_new_push_message_notification(std::move(sender_name), std::move(sender_photo_path), - message_id, std::move(loc_key), std::move(arg))); + add_notification( + group_id, group_type, dialog_id, date, settings_dialog_id, is_silent, 0, notification_id, + create_new_push_message_notification(sender_user_id, message_id, std::move(loc_key), std::move(arg))); return Status::OK(); } diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index a14eaf40..e68591f1 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -6,6 +6,7 @@ // #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" @@ -108,12 +109,14 @@ class NotificationTypePushMessage : public NotificationType { } 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(sender_user_id, message_id_.get(), key_, arg_); return nullptr; - // return td_api::make_object(sender_name_, sender_photo_path_, message_id_.get(), key_, arg_); } StringBuilder &to_string_builder(StringBuilder &string_builder) const override { - return string_builder << "NewPushMessageNotification[" << sender_name_ << ", " << message_id_ << ", " << key_ + return string_builder << "NewPushMessageNotification[" << sender_user_id_ << ", " << message_id_ << ", " << key_ << ", " << arg_ << ']'; } /* @@ -121,17 +124,14 @@ class NotificationTypePushMessage : public NotificationType { return Type::PushMessage; } */ - string sender_name_; - string sender_photo_path_; + UserId sender_user_id_; MessageId message_id_; string key_; string arg_; public: - NotificationTypePushMessage(string sender_name, string sender_photo_path, MessageId message_id, string key, - string arg) - : sender_name_(std::move(sender_name)) - , sender_photo_path_(std::move(sender_photo_path)) + 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)) { @@ -150,10 +150,9 @@ unique_ptr create_new_call_notification(CallId call_id) { return make_unique(call_id); } -unique_ptr create_new_push_message_notification(string sender_name, string sender_photo_path, - MessageId message_id, string key, string arg) { - return td::make_unique(std::move(sender_name), std::move(sender_photo_path), message_id, - std::move(key), std::move(arg)); +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 diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h index b6524d11..a7240e88 100644 --- a/td/telegram/NotificationType.h +++ b/td/telegram/NotificationType.h @@ -10,6 +10,7 @@ #include "td/telegram/DialogId.h" #include "td/telegram/MessageId.h" #include "td/telegram/td_api.h" +#include "td/telegram/UserId.h" #include "td/utils/common.h" #include "td/utils/StringBuilder.h" @@ -58,7 +59,7 @@ unique_ptr create_new_secret_chat_notification(); unique_ptr create_new_call_notification(CallId call_id); -unique_ptr create_new_push_message_notification(string sender_name, string sender_photo_path, - MessageId message_id, string key, string arg); +unique_ptr create_new_push_message_notification(UserId sender_user_id, MessageId message_id, + string key, string arg); } // namespace td