Add reply_in_dialog_id and message_thread_id support.

GitOrigin-RevId: 4b8a21566fbf6d31a6f4ef2b19f787361e2d1a1a
This commit is contained in:
levlam 2020-09-10 16:29:10 +03:00
parent 643371aa2f
commit eb72b64c80
5 changed files with 102 additions and 40 deletions

View File

@ -676,7 +676,9 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@edit_date Point in time (Unix timestamp) when the message was last edited
//@forward_info Information about the initial message sender; may be null
//@interaction_info Information about interactions with the message; may be null
//@reply_in_chat_id If non-zero, the identifier of the chat to which the replied message belongs; Currently, only messages in the Replies chat can have different reply_in_chat_id and chat_id
//@reply_to_message_id If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message
//@message_thread_id If non-zero, the identifier of the message thread the message belongs to
//@ttl For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires
//@ttl_expires_in Time left before the message expires, in seconds
//@via_bot_user_id If non-zero, the user identifier of the bot through which this message was sent
@ -685,7 +687,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_replies:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_to_message_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_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_replies: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;
@ -2537,7 +2539,7 @@ notificationTypeNewSecretChat = NotificationType;
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
//@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_name Name of the sender; can be different from the name of the sender user

Binary file not shown.

View File

@ -4193,6 +4193,8 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool has_forward_count = forward_count > 0;
bool has_reply_info = !reply_info.is_empty();
bool has_sender_dialog_id = sender_dialog_id.is_valid();
bool has_reply_in_dialog_id = is_reply && reply_in_dialog_id.is_valid();
bool has_top_reply_message_id = is_reply && top_reply_message_id.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing);
@ -4244,6 +4246,8 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(has_forward_count);
STORE_FLAG(has_reply_info);
STORE_FLAG(has_sender_dialog_id);
STORE_FLAG(has_reply_in_dialog_id);
STORE_FLAG(has_top_reply_message_id);
END_STORE_FLAGS();
}
@ -4331,6 +4335,12 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (has_sender_dialog_id) {
store(sender_dialog_id, storer);
}
if (has_reply_in_dialog_id) {
store(reply_in_dialog_id, storer);
}
if (has_top_reply_message_id) {
store(top_reply_message_id, storer);
}
store_message_content(content.get(), storer);
if (has_reply_markup) {
store(reply_markup, storer);
@ -4367,6 +4377,8 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool has_forward_count = false;
bool has_reply_info = false;
bool has_sender_dialog_id = false;
bool has_reply_in_dialog_id = false;
bool has_top_reply_message_id = false;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing);
@ -4418,6 +4430,8 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(has_forward_count);
PARSE_FLAG(has_reply_info);
PARSE_FLAG(has_sender_dialog_id);
PARSE_FLAG(has_reply_in_dialog_id);
PARSE_FLAG(has_top_reply_message_id);
END_PARSE_FLAGS();
}
@ -4511,6 +4525,12 @@ void MessagesManager::Message::parse(ParserT &parser) {
if (has_sender_dialog_id) {
parse(sender_dialog_id, parser);
}
if (has_reply_in_dialog_id) {
parse(reply_in_dialog_id, parser);
}
if (has_top_reply_message_id) {
parse(top_reply_message_id, parser);
}
parse_message_content(content, parser);
if (has_reply_markup) {
parse(reply_markup, parser);
@ -11017,6 +11037,8 @@ void MessagesManager::on_message_ttl_expired_impl(Dialog *d, Message *m) {
update_message_contains_unread_mention(d, m, false, "on_message_ttl_expired_impl");
m->contains_mention = false;
m->reply_to_message_id = MessageId();
m->reply_in_dialog_id = DialogId();
m->top_reply_message_id = MessageId();
m->is_content_secret = false;
}
@ -12234,6 +12256,8 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->random_id = message_info.random_id;
message->forward_info = get_message_forward_info(std::move(message_info.forward_header));
message->reply_to_message_id = reply_to_message_id;
message->reply_in_dialog_id = reply_in_dialog_id;
message->top_reply_message_id = top_reply_message_id;
message->via_bot_user_id = via_bot_user_id;
message->restriction_reasons = std::move(message_info.restriction_reasons);
message->author_signature = std::move(message_info.author_signature);
@ -12267,6 +12291,8 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->reply_markup = nullptr;
}
message->reply_to_message_id = MessageId();
message->reply_in_dialog_id = DialogId();
message->top_reply_message_id = MessageId();
}
if (message_info.media_album_id != 0) {
@ -15206,13 +15232,16 @@ MessagesManager::Message *MessagesManager::get_message_force(FullMessageId full_
return get_message_force(d, full_message_id.get_message_id(), source);
}
MessageId MessagesManager::get_replied_message_id(const Message *m) {
FullMessageId MessagesManager::get_replied_message_id(DialogId dialog_id, const Message *m) {
auto message_id = get_message_content_replied_message_id(m->content.get());
if (message_id.is_valid()) {
CHECK(!m->reply_to_message_id.is_valid());
return message_id;
return {dialog_id, message_id};
}
return m->reply_to_message_id;
if (!m->reply_to_message_id.is_valid()) {
return {};
}
return {m->reply_in_dialog_id.is_valid() ? m->reply_in_dialog_id : dialog_id, m->reply_to_message_id};
}
void MessagesManager::get_message_force_from_server(Dialog *d, MessageId message_id, Promise<Unit> &&promise,
@ -15266,13 +15295,13 @@ void MessagesManager::get_message(FullMessageId full_message_id, Promise<Unit> &
get_message_force_from_server(d, full_message_id.get_message_id(), std::move(promise));
}
MessageId MessagesManager::get_replied_message(DialogId dialog_id, MessageId message_id, bool force,
Promise<Unit> &&promise) {
FullMessageId MessagesManager::get_replied_message(DialogId dialog_id, MessageId message_id, bool force,
Promise<Unit> &&promise) {
LOG(INFO) << "Get replied message to " << message_id << " in " << dialog_id;
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
promise.set_error(Status::Error(6, "Chat not found"));
return MessageId();
return FullMessageId();
}
auto m = get_message_force(d, message_id, "get_replied_message");
@ -15282,15 +15311,22 @@ MessageId MessagesManager::get_replied_message(DialogId dialog_id, MessageId mes
} else {
get_message_force_from_server(d, message_id, std::move(promise));
}
return MessageId();
return FullMessageId();
}
tl_object_ptr<telegram_api::InputMessage> input_message;
if (m->message_id.is_valid() && m->message_id.is_server()) {
input_message = make_tl_object<telegram_api::inputMessageReplyTo>(m->message_id.get_server_message_id().get());
}
auto replied_message_id = get_replied_message_id(m);
get_message_force_from_server(d, replied_message_id, std::move(promise), std::move(input_message));
auto replied_message_id = get_replied_message_id(dialog_id, m);
if (replied_message_id.get_dialog_id() != dialog_id) {
d = get_dialog_force(replied_message_id.get_dialog_id());
if (d == nullptr) {
promise.set_error(Status::Error(6, "Chat with replied message not found"));
return FullMessageId();
}
}
get_message_force_from_server(d, replied_message_id.get_message_id(), std::move(promise), std::move(input_message));
return replied_message_id;
}
@ -20334,7 +20370,9 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
bool can_get_replies = for_event_log || is_scheduled ? false : !m->reply_info.is_empty() && m->message_id.is_server();
auto via_bot_user_id = td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id");
auto media_album_id = for_event_log ? static_cast<int64>(0) : m->media_album_id;
auto reply_in_dialog_id = m->reply_in_dialog_id.is_valid() ? m->reply_in_dialog_id : dialog_id;
auto reply_to_message_id = for_event_log ? static_cast<int64>(0) : m->reply_to_message_id.get();
auto top_reply_message_id = for_event_log || is_scheduled ? static_cast<int64>(0) : m->top_reply_message_id.get();
bool contains_unread_mention = for_event_log ? false : m->contains_unread_mention;
auto live_location_date = m->is_failed_to_send ? 0 : m->date;
auto date = is_scheduled ? 0 : m->date;
@ -20345,8 +20383,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
can_be_edited, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics,
can_get_replies, 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_to_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id,
get_restriction_reason_description(m->restriction_reasons),
reply_in_dialog_id.get(), reply_to_message_id, top_reply_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));
}
@ -20886,6 +20924,13 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo
if (m->sender_dialog_id.is_valid() && dependencies.dialog_ids.insert(m->sender_dialog_id).second) {
add_dialog_dependencies(dependencies, m->sender_dialog_id);
}
if (m->reply_in_dialog_id.is_valid() && dependencies.dialog_ids.insert(m->reply_in_dialog_id).second) {
add_dialog_dependencies(dependencies, m->reply_in_dialog_id);
}
if (m->real_forward_from_dialog_id.is_valid() &&
dependencies.dialog_ids.insert(m->real_forward_from_dialog_id).second) {
add_dialog_dependencies(dependencies, m->real_forward_from_dialog_id);
}
dependencies.user_ids.insert(m->via_bot_user_id);
if (m->forward_info != nullptr) {
dependencies.user_ids.insert(m->forward_info->sender_user_id);
@ -28872,7 +28917,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
if (d->deleted_message_ids.count(message->reply_to_message_id)) {
// LOG(INFO) << "Remove reply to deleted " << message->reply_to_message_id << " in " << message_id << " from " << dialog_id << " from " << source;
// we don't want to lose information that the message was a reply for now
// we don't want to lose information that the message was a reply
// message->reply_to_message_id = MessageId();
}
@ -30158,7 +30203,30 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
<< old_message->reply_to_message_id << " to " << new_message->reply_to_message_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
dump_debug_message_op(d);
}
}
if (old_message->reply_in_dialog_id != new_message->reply_in_dialog_id) {
if (new_message->reply_in_dialog_id == DialogId() || replace_legacy) {
LOG(DEBUG) << "Drop message reply_in_dialog_id";
old_message->reply_in_dialog_id = DialogId();
need_send_update = true;
} else if (is_new_available && old_message->reply_in_dialog_id.is_valid()) {
LOG(ERROR) << message_id << " in " << dialog_id << " has changed dialog it is reply in from "
<< old_message->reply_in_dialog_id << " to " << new_message->reply_in_dialog_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
}
}
if (old_message->top_reply_message_id != new_message->top_reply_message_id) {
if (new_message->top_reply_message_id == MessageId()) {
LOG(DEBUG) << "Drop message top_reply_message_id";
old_message->reply_to_message_id = MessageId();
need_send_update = true;
} else if (is_new_available && old_message->top_reply_message_id.is_valid()) {
LOG(ERROR) << message_id << " in " << dialog_id << " has changed top message it is reply to from "
<< old_message->top_reply_message_id << " to " << new_message->top_reply_message_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
}
}
if (old_message->via_bot_user_id != new_message->via_bot_user_id) {
@ -30882,29 +30950,21 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
if (last_database_message != nullptr) {
int32 dependent_dialog_count = 0;
auto depend_on_dialog = [&](DialogId other_dialog_id) {
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id;
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++;
}
};
if (last_database_message->forward_info != nullptr) {
auto other_dialog_id = last_database_message->forward_info->sender_dialog_id;
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id;
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++;
}
other_dialog_id = last_database_message->forward_info->from_dialog_id;
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id;
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++;
}
other_dialog_id = last_database_message->sender_dialog_id;
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
<< other_dialog_id;
pending_add_dialog_last_database_message_dependent_dialogs_[other_dialog_id].push_back(dialog_id);
dependent_dialog_count++;
}
depend_on_dialog(last_database_message->forward_info->sender_dialog_id);
depend_on_dialog(last_database_message->forward_info->from_dialog_id);
}
depend_on_dialog(last_database_message->sender_dialog_id);
depend_on_dialog(last_database_message->reply_in_dialog_id);
depend_on_dialog(last_database_message->real_forward_from_dialog_id);
if (dependent_dialog_count == 0) {
add_dialog_last_database_message(d, std::move(last_database_message));

View File

@ -549,7 +549,7 @@ class MessagesManager : public Actor {
void get_message(FullMessageId full_message_id, Promise<Unit> &&promise);
MessageId get_replied_message(DialogId dialog_id, MessageId message_id, bool force, Promise<Unit> &&promise);
FullMessageId get_replied_message(DialogId dialog_id, MessageId message_id, bool force, Promise<Unit> &&promise);
MessageId get_dialog_pinned_message(DialogId dialog_id, Promise<Unit> &&promise);
@ -1718,7 +1718,7 @@ class MessagesManager : public Actor {
MessageId get_persistent_message_id(const Dialog *d, MessageId message_id) const;
static MessageId get_replied_message_id(const Message *m);
static FullMessageId get_replied_message_id(DialogId dialog_id, const Message *m);
MessageId get_reply_to_message_id(Dialog *d, MessageId message_id);

View File

@ -1032,7 +1032,7 @@ class GetRepliedMessageRequest : public RequestOnceActor {
DialogId dialog_id_;
MessageId message_id_;
MessageId replied_message_id_;
FullMessageId replied_message_id_;
void do_run(Promise<Unit> &&promise) override {
replied_message_id_ =
@ -1040,7 +1040,7 @@ class GetRepliedMessageRequest : public RequestOnceActor {
}
void do_send_result() override {
send_result(td->messages_manager_->get_message_object({dialog_id_, replied_message_id_}));
send_result(td->messages_manager_->get_message_object(replied_message_id_));
}
public: