Store sender_user_id in message push notification.
GitOrigin-RevId: e6dbf304266c63a92e5949a1ee48444f8c0e958f
This commit is contained in:
parent
0d6c1842e1
commit
508889fadf
@ -2945,7 +2945,7 @@ tl_object_ptr<telegram_api::inputEncryptedChat> 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;
|
||||
}
|
||||
|
@ -18210,19 +18210,12 @@ Result<MessagesManager::MessagePushNotificationInfo> 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);
|
||||
|
@ -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<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*/, 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();
|
||||
}
|
||||
|
||||
|
@ -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<td_api::NotificationType> 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<td_api::notificationTypeNewPushMessage>(sender_user_id, message_id_.get(), key_, arg_);
|
||||
return nullptr;
|
||||
// return td_api::make_object<td_api::notificationTypeNewPushMessage>(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<NotificationType> create_new_call_notification(CallId call_id) {
|
||||
return make_unique<NotificationTypeCall>(call_id);
|
||||
}
|
||||
|
||||
unique_ptr<NotificationType> create_new_push_message_notification(string sender_name, string sender_photo_path,
|
||||
MessageId message_id, string key, string arg) {
|
||||
return td::make_unique<NotificationTypePushMessage>(std::move(sender_name), std::move(sender_photo_path), message_id,
|
||||
std::move(key), std::move(arg));
|
||||
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, MessageId message_id,
|
||||
string key, string arg) {
|
||||
return td::make_unique<NotificationTypePushMessage>(sender_user_id, message_id, std::move(key), std::move(arg));
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -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<NotificationType> create_new_secret_chat_notification();
|
||||
|
||||
unique_ptr<NotificationType> create_new_call_notification(CallId call_id);
|
||||
|
||||
unique_ptr<NotificationType> create_new_push_message_notification(string sender_name, string sender_photo_path,
|
||||
MessageId message_id, string key, string arg);
|
||||
unique_ptr<NotificationType> create_new_push_message_notification(UserId sender_user_id, MessageId message_id,
|
||||
string key, string arg);
|
||||
|
||||
} // namespace td
|
||||
|
Reference in New Issue
Block a user