Add td_api::MessageSender class.
GitOrigin-RevId: 082a1e74188bffc590c4a4182793a9d94b60c148
This commit is contained in:
parent
d968fd0bed
commit
e32e1c66e7
@ -172,7 +172,7 @@ class TdExample {
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_user_name(std::int32_t user_id) {
|
||||
std::string get_user_name(std::int32_t user_id) const {
|
||||
auto it = users_.find(user_id);
|
||||
if (it == users_.end()) {
|
||||
return "unknown user";
|
||||
@ -180,6 +180,14 @@ class TdExample {
|
||||
return it->second->first_name_ + " " + it->second->last_name_;
|
||||
}
|
||||
|
||||
std::string get_chat_title(std::int64_t chat_id) const {
|
||||
auto it = chat_title_.find(chat_id);
|
||||
if (it == chat_title_.end()) {
|
||||
return "unknown chat";
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void process_update(td_api::object_ptr<td_api::Object> update) {
|
||||
td_api::downcast_call(
|
||||
*update, overloaded(
|
||||
@ -199,13 +207,21 @@ class TdExample {
|
||||
},
|
||||
[this](td_api::updateNewMessage &update_new_message) {
|
||||
auto chat_id = update_new_message.message_->chat_id_;
|
||||
auto sender_user_name = get_user_name(update_new_message.message_->sender_user_id_);
|
||||
std::string sender_name;
|
||||
td_api::downcast_call(*update_new_message.message_->sender_,
|
||||
overloaded(
|
||||
[this, &sender_name](td_api::messageSenderUser &user) {
|
||||
sender_name = get_user_name(user.user_id_);
|
||||
},
|
||||
[this, &sender_name](td_api::messageSenderChat &chat) {
|
||||
sender_name = get_chat_title(chat.chat_id_);
|
||||
}));
|
||||
std::string text;
|
||||
if (update_new_message.message_->content_->get_id() == td_api::messageText::ID) {
|
||||
text = static_cast<td_api::messageText &>(*update_new_message.message_->content_).text_->text_;
|
||||
}
|
||||
std::cout << "Got message: [chat_id:" << chat_id << "] [from:" << sender_user_name << "] ["
|
||||
<< text << "]" << std::endl;
|
||||
std::cout << "Got message: [chat_id:" << chat_id << "] [from:" << sender_name << "] [" << text
|
||||
<< "]" << std::endl;
|
||||
},
|
||||
[](auto &update) {}));
|
||||
}
|
||||
|
@ -613,15 +613,24 @@ secretChatStateClosed = SecretChatState;
|
||||
secretChat id:int32 user_id:int32 state:SecretChatState is_outbound:Bool ttl:int32 key_hash:bytes layer:int32 = SecretChat;
|
||||
|
||||
|
||||
//@class MessageSender @description Contains information about the sender of a message
|
||||
|
||||
//@description The message was sent by a known user @user_id Identifier of the user that sent the message
|
||||
messageSenderUser user_id:int32 = MessageSender;
|
||||
|
||||
//@description The message was sent on behalf of a chat @chat_id Identifier of the chat that sent the message
|
||||
messageSenderChat chat_id:int53 = MessageSender;
|
||||
|
||||
|
||||
//@class MessageForwardOrigin @description Contains information about the origin of a forwarded message
|
||||
|
||||
//@description The message was originally written by a known user @sender_user_id Identifier of the user that originally sent the message
|
||||
//@description The message was originally sent by a known user @sender_user_id Identifier of the user that originally sent the message
|
||||
messageForwardOriginUser sender_user_id:int32 = MessageForwardOrigin;
|
||||
|
||||
//@description The message was originally written by an anonymous chat administrator on behalf of the chat @sender_chat_id Identifier of the chat that originally sent the message
|
||||
//@description The message was originally sent by an anonymous chat administrator on behalf of the chat @sender_chat_id Identifier of the chat that originally sent the message
|
||||
messageForwardOriginChat sender_chat_id:int53 = MessageForwardOrigin;
|
||||
|
||||
//@description The message was originally written by a user, which is hidden by their privacy settings @sender_name Name of the sender
|
||||
//@description The message was originally sent by a user, which is hidden by their privacy settings @sender_name Name of the sender
|
||||
messageForwardOriginHiddenUser sender_name:string = MessageForwardOrigin;
|
||||
|
||||
//@description The message was originally a post in a channel
|
||||
@ -666,8 +675,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
|
||||
|
||||
//@description Describes a message
|
||||
//@id Message identifier; unique for the chat to which the message belongs
|
||||
//@sender_user_id Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts, for channel posts automatically forwarded to discussion group and for anonymously sent supergroup messages
|
||||
//@sender_chat_id Identifier of the chat on behalf of which the message was sent; 0 if none
|
||||
//@sender The sender of the message
|
||||
//@chat_id Chat identifier
|
||||
//@sending_state Information about the sending state of the message; may be null
|
||||
//@scheduling_state Information about the scheduling state of the message; may be null
|
||||
@ -695,7 +703,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
|
||||
//@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted
|
||||
//@content Content of the message
|
||||
//@reply_markup Reply markup for the message; may be null
|
||||
message id:int53 sender_user_id:int32 sender_chat_id:int53 chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_statistics:Bool can_get_message_thread:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_in_chat_id:int53 reply_to_message_id:int53 message_thread_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
|
||||
message id:int53 sender:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_statistics:Bool can_get_message_thread:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_in_chat_id:int53 reply_to_message_id:int53 message_thread_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
|
||||
|
||||
//@description Contains a list of messages @total_count Approximate total count of messages found @messages List of messages; messages may be null
|
||||
messages total_count:int32 messages:vector<message> = Messages;
|
||||
@ -2558,12 +2566,11 @@ 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, or as reply_to_message_id
|
||||
//@sender_user_id Sender of the message; 0 if unknown. Corresponding user may be inaccessible
|
||||
//@sender_chat_id Sender chat of the message; 0 if none
|
||||
//@sender The sender of the message. Corresponding user or chat may be inaccessible
|
||||
//@sender_name Name of the sender; can be different from the name of the sender user
|
||||
//@is_outgoing True, if the message is outgoing
|
||||
//@content Push message content
|
||||
notificationTypeNewPushMessage message_id:int53 sender_user_id:int32 sender_chat_id:int53 sender_name:string is_outgoing:Bool content:PushMessageContent = NotificationType;
|
||||
notificationTypeNewPushMessage message_id:int53 sender:MessageSender sender_name:string is_outgoing:Bool content:PushMessageContent = NotificationType;
|
||||
|
||||
|
||||
//@class NotificationGroupType @description Describes the type of notifications in a notification group
|
||||
|
Binary file not shown.
@ -5528,6 +5528,20 @@ void MessagesManager::on_preload_folder_dialog_list_timeout_callback(void *messa
|
||||
FolderId(narrow_cast<int32>(folder_id_int)));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(UserId user_id,
|
||||
DialogId dialog_id) const {
|
||||
if (dialog_id.is_valid()) {
|
||||
CHECK(have_dialog(dialog_id));
|
||||
return td_api::make_object<td_api::messageSenderChat>(dialog_id.get());
|
||||
}
|
||||
if (!user_id.is_valid()) {
|
||||
// can happen only if the server sends a message with wrong sender
|
||||
user_id = td_->contacts_manager_->add_service_notifications_user();
|
||||
}
|
||||
return td_api::make_object<td_api::messageSenderUser>(
|
||||
td_->contacts_manager_->get_user_id_object(user_id, "get_message_sender_object"));
|
||||
}
|
||||
|
||||
BufferSlice MessagesManager::get_dialog_database_value(const Dialog *d) {
|
||||
// can't use log_event_store, because it tries to parse stored Dialog
|
||||
LogEventStorerCalcLength storer_calc_length;
|
||||
@ -21709,13 +21723,13 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
|
||||
auto date = is_scheduled ? 0 : m->date;
|
||||
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
|
||||
return make_tl_object<td_api::message>(
|
||||
m->message_id.get(), td_->contacts_manager_->get_user_id_object(m->sender_user_id, "sender_user_id"),
|
||||
m->sender_dialog_id.get(), dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing,
|
||||
can_be_edited, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics,
|
||||
can_get_message_thread, m->is_channel_post, contains_unread_mention, date, edit_date,
|
||||
get_message_forward_info_object(m->forward_info), get_message_interaction_info_object(dialog_id, m),
|
||||
reply_in_dialog_id.get(), reply_to_message_id, top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id,
|
||||
m->author_signature, media_album_id, get_restriction_reason_description(m->restriction_reasons),
|
||||
m->message_id.get(), get_message_sender_object(m->sender_user_id, m->sender_dialog_id), dialog_id.get(),
|
||||
std::move(sending_state), std::move(scheduling_state), is_outgoing, can_be_edited, can_be_forwarded,
|
||||
can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread, m->is_channel_post,
|
||||
contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info),
|
||||
get_message_interaction_info_object(dialog_id, m), reply_in_dialog_id.get(), reply_to_message_id,
|
||||
top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id,
|
||||
get_restriction_reason_description(m->restriction_reasons),
|
||||
get_message_content_object(m->content.get(), td_, live_location_date, m->is_content_secret),
|
||||
get_reply_markup_object(m->reply_markup));
|
||||
}
|
||||
|
@ -190,6 +190,8 @@ class MessagesManager : public Actor {
|
||||
MessagesManager &operator=(MessagesManager &&) = delete;
|
||||
~MessagesManager() override;
|
||||
|
||||
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(UserId user_id, DialogId dialog_id) const;
|
||||
|
||||
static vector<MessageId> get_message_ids(const vector<int64> &input_message_ids);
|
||||
|
||||
static vector<int32> get_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
@ -318,10 +318,10 @@ 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");
|
||||
auto sender =
|
||||
G()->td().get_actor_unsafe()->messages_manager_->get_message_sender_object(sender_user_id_, sender_dialog_id_);
|
||||
return td_api::make_object<td_api::notificationTypeNewPushMessage>(
|
||||
message_id_.get(), sender_user_id, sender_dialog_id_.get(), sender_name_, is_outgoing_,
|
||||
message_id_.get(), std::move(sender), sender_name_, is_outgoing_,
|
||||
get_push_message_content_object(key_, arg_, photo_, document_));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user