mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2025-01-01 07:05:49 +01:00
Keep reply to the top thread message for external replies.
This commit is contained in:
parent
34ed6c3512
commit
0566e21f93
@ -1982,11 +1982,11 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const {
|
|||||||
}
|
}
|
||||||
object("forward_date", message_->initial_send_date);
|
object("forward_date", message_->initial_send_date);
|
||||||
}
|
}
|
||||||
if (need_reply_ && message_->reply_to_message != nullptr) {
|
if (need_reply_) {
|
||||||
auto reply_to_message_id = get_same_chat_reply_to_message_id(message_->reply_to_message.get());
|
auto reply_to_message_id =
|
||||||
|
get_same_chat_reply_to_message_id(message_->reply_to_message.get(), message_->message_thread_id);
|
||||||
if (reply_to_message_id > 0) {
|
if (reply_to_message_id > 0) {
|
||||||
// internal reply
|
// internal reply
|
||||||
CHECK(message_->reply_to_message->chat_id_ == message_->chat_id);
|
|
||||||
const MessageInfo *reply_to_message = client_->get_message(message_->chat_id, reply_to_message_id, true);
|
const MessageInfo *reply_to_message = client_->get_message(message_->chat_id, reply_to_message_id, true);
|
||||||
if (reply_to_message != nullptr) {
|
if (reply_to_message != nullptr) {
|
||||||
object("reply_to_message", JsonMessage(reply_to_message, false, "reply in " + source_, client_));
|
object("reply_to_message", JsonMessage(reply_to_message, false, "reply in " + source_, client_));
|
||||||
@ -1994,10 +1994,11 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const {
|
|||||||
LOG(INFO) << "Replied to unknown or deleted message " << reply_to_message_id << " in chat " << message_->chat_id
|
LOG(INFO) << "Replied to unknown or deleted message " << reply_to_message_id << " in chat " << message_->chat_id
|
||||||
<< " while storing " << source_ << ' ' << message_->id;
|
<< " while storing " << source_ << ' ' << message_->id;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// external reply
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (message_->reply_to_message != nullptr && message_->reply_to_message->origin_ != nullptr) {
|
||||||
|
// external reply
|
||||||
|
}
|
||||||
if (message_->media_album_id != 0) {
|
if (message_->media_album_id != 0) {
|
||||||
object("media_group_id", td::to_string(message_->media_album_id));
|
object("media_group_id", td::to_string(message_->media_album_id));
|
||||||
}
|
}
|
||||||
@ -4436,9 +4437,11 @@ void Client::on_get_reply_message(int64 chat_id, object_ptr<td_api::message> rep
|
|||||||
LOG(INFO) << "Can't find message " << reply_to_message_id << " in chat " << chat_id
|
LOG(INFO) << "Can't find message " << reply_to_message_id << " in chat " << chat_id
|
||||||
<< ". It is already deleted or inaccessible because of the chosen privacy mode";
|
<< ". It is already deleted or inaccessible because of the chosen privacy mode";
|
||||||
} else {
|
} else {
|
||||||
CHECK(chat_id == reply_to_message->chat_id_);
|
if (chat_id != reply_to_message->chat_id_ || reply_to_message_id != reply_to_message->id_) {
|
||||||
CHECK(reply_to_message_id == reply_to_message->id_);
|
LOG(ERROR) << "Expect to get replied message " << reply_to_message_id << " in " << chat_id << ", but receive "
|
||||||
LOG(INFO) << "Receive reply to message " << reply_to_message_id << " in chat " << chat_id;
|
<< reply_to_message->id_ << " in " << reply_to_message->chat_id_;
|
||||||
|
}
|
||||||
|
LOG(INFO) << "Receive reply to message " << reply_to_message->id_ << " in chat " << reply_to_message->chat_id_;
|
||||||
add_message(std::move(reply_to_message));
|
add_message(std::move(reply_to_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4475,7 +4478,8 @@ void Client::on_get_callback_query_message(object_ptr<td_api::message> message,
|
|||||||
process_new_callback_query_queue(user_id, state);
|
process_new_callback_query_queue(user_id, state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto reply_to_message_id = get_same_chat_reply_to_message_id(message_info->reply_to_message.get());
|
auto reply_to_message_id =
|
||||||
|
get_same_chat_reply_to_message_id(message_info->reply_to_message.get(), message_info->message_thread_id);
|
||||||
LOG(INFO) << "Can't find callback query reply to message " << reply_to_message_id << " in chat " << chat_id
|
LOG(INFO) << "Can't find callback query reply to message " << reply_to_message_id << " in chat " << chat_id
|
||||||
<< ". It may be already deleted";
|
<< ". It may be already deleted";
|
||||||
}
|
}
|
||||||
@ -10961,8 +10965,10 @@ void Client::process_new_callback_query_queue(int64 user_id, int state) {
|
|||||||
state = 1;
|
state = 1;
|
||||||
}
|
}
|
||||||
if (state == 1) {
|
if (state == 1) {
|
||||||
auto reply_to_message_id =
|
auto reply_to_message_id = message_info == nullptr
|
||||||
message_info == nullptr ? 0 : get_same_chat_reply_to_message_id(message_info->reply_to_message.get());
|
? 0
|
||||||
|
: get_same_chat_reply_to_message_id(message_info->reply_to_message.get(),
|
||||||
|
message_info->message_thread_id);
|
||||||
if (reply_to_message_id > 0 && get_message(chat_id, reply_to_message_id, false) == nullptr) {
|
if (reply_to_message_id > 0 && get_message(chat_id, reply_to_message_id, false) == nullptr) {
|
||||||
queue.has_active_request_ = true;
|
queue.has_active_request_ = true;
|
||||||
return send_request(make_object<td_api::getRepliedMessage>(chat_id, message_id),
|
return send_request(make_object<td_api::getRepliedMessage>(chat_id, message_id),
|
||||||
@ -10977,8 +10983,10 @@ void Client::process_new_callback_query_queue(int64 user_id, int state) {
|
|||||||
return send_request(make_object<td_api::getStickerSet>(message_sticker_set_id),
|
return send_request(make_object<td_api::getStickerSet>(message_sticker_set_id),
|
||||||
td::make_unique<TdOnGetStickerSetCallback>(this, message_sticker_set_id, user_id, 0));
|
td::make_unique<TdOnGetStickerSetCallback>(this, message_sticker_set_id, user_id, 0));
|
||||||
}
|
}
|
||||||
auto reply_to_message_id =
|
auto reply_to_message_id = message_info == nullptr
|
||||||
message_info == nullptr ? 0 : get_same_chat_reply_to_message_id(message_info->reply_to_message.get());
|
? 0
|
||||||
|
: get_same_chat_reply_to_message_id(message_info->reply_to_message.get(),
|
||||||
|
message_info->message_thread_id);
|
||||||
if (reply_to_message_id > 0) {
|
if (reply_to_message_id > 0) {
|
||||||
auto reply_to_message_info = get_message(chat_id, reply_to_message_id, true);
|
auto reply_to_message_info = get_message(chat_id, reply_to_message_id, true);
|
||||||
auto reply_sticker_set_id =
|
auto reply_sticker_set_id =
|
||||||
@ -11229,19 +11237,22 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr<td_api::me
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
td::int64 Client::get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to) {
|
td::int64 Client::get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to,
|
||||||
|
int64 message_thread_id) {
|
||||||
if (reply_to != nullptr && reply_to->origin_ == nullptr) {
|
if (reply_to != nullptr && reply_to->origin_ == nullptr) {
|
||||||
CHECK(reply_to->message_id_ > 0);
|
CHECK(reply_to->message_id_ > 0);
|
||||||
return reply_to->message_id_;
|
return reply_to->message_id_;
|
||||||
}
|
}
|
||||||
return 0;
|
return message_thread_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::MessageReplyTo> &reply_to) {
|
td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::MessageReplyTo> &reply_to,
|
||||||
|
int64 message_thread_id) {
|
||||||
if (reply_to != nullptr) {
|
if (reply_to != nullptr) {
|
||||||
switch (reply_to->get_id()) {
|
switch (reply_to->get_id()) {
|
||||||
case td_api::messageReplyToMessage::ID:
|
case td_api::messageReplyToMessage::ID:
|
||||||
return get_same_chat_reply_to_message_id(static_cast<const td_api::messageReplyToMessage *>(reply_to.get()));
|
return get_same_chat_reply_to_message_id(static_cast<const td_api::messageReplyToMessage *>(reply_to.get()),
|
||||||
|
message_thread_id);
|
||||||
case td_api::messageReplyToStory::ID:
|
case td_api::messageReplyToStory::ID:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -11249,7 +11260,7 @@ td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::Mes
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return message_thread_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::message> &message) {
|
td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::message> &message) {
|
||||||
@ -11273,10 +11284,7 @@ td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::mes
|
|||||||
CHECK(message->reply_to_ == nullptr);
|
CHECK(message->reply_to_ == nullptr);
|
||||||
return content_message_id;
|
return content_message_id;
|
||||||
}
|
}
|
||||||
if (message->reply_to_ != nullptr) {
|
return get_same_chat_reply_to_message_id(message->reply_to_, message->message_thread_id_);
|
||||||
return get_same_chat_reply_to_message_id(message->reply_to_);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::drop_internal_reply_to_message_in_another_chat(object_ptr<td_api::message> &message) {
|
void Client::drop_internal_reply_to_message_in_another_chat(object_ptr<td_api::message> &message) {
|
||||||
|
@ -837,9 +837,11 @@ class Client final : public WebhookActor::Callback {
|
|||||||
mutable bool is_content_changed = false;
|
mutable bool is_content_changed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int64 get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to);
|
static int64 get_same_chat_reply_to_message_id(const td_api::messageReplyToMessage *reply_to,
|
||||||
|
int64 message_thread_id);
|
||||||
|
|
||||||
static int64 get_same_chat_reply_to_message_id(const object_ptr<td_api::MessageReplyTo> &reply_to);
|
static int64 get_same_chat_reply_to_message_id(const object_ptr<td_api::MessageReplyTo> &reply_to,
|
||||||
|
int64 message_thread_id);
|
||||||
|
|
||||||
static int64 get_same_chat_reply_to_message_id(const object_ptr<td_api::message> &message);
|
static int64 get_same_chat_reply_to_message_id(const object_ptr<td_api::message> &message);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user