Handle updateReadDiscussion.
GitOrigin-RevId: 2cb783768934ee67bad98511edfc061ae6aa879b
This commit is contained in:
parent
2b5b6386fc
commit
7e6cb9a8e4
@ -58,17 +58,25 @@ bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
|
||||
}
|
||||
|
||||
bool MessageReplyInfo::update_max_message_ids(const MessageReplyInfo &other) {
|
||||
if (!is_comment || !other.is_comment) {
|
||||
if (!other.is_comment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return update_max_message_ids(other.max_message_id, other.max_read_message_id);
|
||||
}
|
||||
|
||||
bool MessageReplyInfo::update_max_message_ids(MessageId other_max_message_id, MessageId other_max_read_message_id) {
|
||||
if (!is_comment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (other.max_message_id > max_message_id) {
|
||||
max_message_id = other.max_message_id;
|
||||
if (other_max_message_id > max_message_id) {
|
||||
max_message_id = other_max_message_id;
|
||||
result = true;
|
||||
}
|
||||
if (other.max_read_message_id > max_read_message_id) {
|
||||
max_read_message_id = other.max_read_message_id;
|
||||
if (other_max_read_message_id > max_read_message_id) {
|
||||
max_read_message_id = other_max_read_message_id;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
@ -36,6 +36,8 @@ struct MessageReplyInfo {
|
||||
|
||||
bool need_update_to(const MessageReplyInfo &other) const;
|
||||
|
||||
bool update_max_message_ids(MessageId other_max_message_id, MessageId other_max_read_message_id);
|
||||
|
||||
bool update_max_message_ids(const MessageReplyInfo &other);
|
||||
|
||||
void add_reply(DialogId replier_dialog_id, MessageId reply_message_id);
|
||||
|
@ -397,20 +397,13 @@ class GetDialogUnreadMarksQuery : public Td::ResultHandler {
|
||||
};
|
||||
|
||||
class GetDiscussionMessageQuery : public Td::ResultHandler {
|
||||
public:
|
||||
struct Result {
|
||||
vector<FullMessageId> full_message_ids;
|
||||
MessageId max_message_id;
|
||||
MessageId max_read_message_id;
|
||||
};
|
||||
|
||||
private:
|
||||
Promise<Result> promise_;
|
||||
Promise<vector<FullMessageId>> promise_;
|
||||
DialogId dialog_id_;
|
||||
MessageId message_id_;
|
||||
|
||||
public:
|
||||
explicit GetDiscussionMessageQuery(Promise<Result> &&promise) : promise_(std::move(promise)) {
|
||||
explicit GetDiscussionMessageQuery(Promise<vector<FullMessageId>> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, MessageId message_id) {
|
||||
@ -432,21 +425,27 @@ class GetDiscussionMessageQuery : public Td::ResultHandler {
|
||||
LOG(INFO) << "Receive discussion message for " << message_id_ << " in " << dialog_id_ << ": " << to_string(ptr);
|
||||
td->contacts_manager_->on_get_users(std::move(ptr->users_), "GetDiscussionMessageQuery");
|
||||
td->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetDiscussionMessageQuery");
|
||||
Result result;
|
||||
|
||||
MessageId max_message_id;
|
||||
MessageId max_read_message_id;
|
||||
if ((ptr->flags_ & telegram_api::messages_discussionMessage::MAX_ID_MASK) != 0) {
|
||||
max_message_id = MessageId(ServerMessageId(ptr->max_id_));
|
||||
}
|
||||
if ((ptr->flags_ & telegram_api::messages_discussionMessage::READ_MAX_ID_MASK) != 0) {
|
||||
max_read_message_id = MessageId(ServerMessageId(ptr->read_max_id_));
|
||||
}
|
||||
td->messages_manager_->on_update_read_message_comments(dialog_id_, message_id_, max_message_id,
|
||||
max_read_message_id);
|
||||
|
||||
vector<FullMessageId> full_message_ids;
|
||||
for (auto &message : ptr->messages_) {
|
||||
auto full_message_id = td->messages_manager_->on_get_message(std::move(message), false, true, false, false, false,
|
||||
"GetDiscussionMessageQuery");
|
||||
if (full_message_id.get_message_id().is_valid()) {
|
||||
result.full_message_ids.push_back(full_message_id);
|
||||
full_message_ids.push_back(full_message_id);
|
||||
}
|
||||
}
|
||||
if ((ptr->flags_ & telegram_api::messages_discussionMessage::MAX_ID_MASK) != 0) {
|
||||
result.max_message_id = MessageId(ServerMessageId(ptr->max_id_));
|
||||
}
|
||||
if ((ptr->flags_ & telegram_api::messages_discussionMessage::READ_MAX_ID_MASK) != 0) {
|
||||
result.max_read_message_id = MessageId(ServerMessageId(ptr->read_max_id_));
|
||||
}
|
||||
promise_.set_value(std::move(result));
|
||||
promise_.set_value(std::move(full_message_ids));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
@ -6099,6 +6098,23 @@ void MessagesManager::on_update_read_channel_messages_contents(
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::on_update_read_message_comments(DialogId dialog_id, MessageId message_id,
|
||||
MessageId max_message_id, MessageId max_read_message_id) {
|
||||
Dialog *d = get_dialog_force(dialog_id);
|
||||
if (d == nullptr) {
|
||||
LOG(INFO) << "Ignore update of read message comments in unknown " << dialog_id << " in updateReadDiscussion";
|
||||
return;
|
||||
}
|
||||
|
||||
auto m = get_message_force(d, message_id, "on_update_read_message_comments");
|
||||
if (m == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m->reply_info.update_max_message_ids(max_message_id, max_read_message_id)) {
|
||||
on_message_changed(d, m, false, "on_update_read_message_comments");
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::on_update_channel_too_long(tl_object_ptr<telegram_api::updateChannelTooLong> &&update,
|
||||
bool force_apply) {
|
||||
ChannelId channel_id(update->channel_id_);
|
||||
@ -15555,13 +15571,12 @@ FullMessageId MessagesManager::get_discussion_message(DialogId dialog_id, Messag
|
||||
|
||||
auto query_promise =
|
||||
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, message_id,
|
||||
promise = std::move(promise)](Result<GetDiscussionMessageQuery::Result> result) mutable {
|
||||
promise = std::move(promise)](Result<vector<FullMessageId>> result) mutable {
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
send_closure(actor_id, &MessagesManager::on_get_discussion_message, dialog_id, message_id,
|
||||
std::move(result.ok_ref().full_message_ids), result.ok().max_message_id,
|
||||
result.ok().max_read_message_id, std::move(promise));
|
||||
send_closure(actor_id, &MessagesManager::on_get_discussion_message, dialog_id, message_id, result.move_as_ok(),
|
||||
std::move(promise));
|
||||
});
|
||||
|
||||
td_->create_handler<GetDiscussionMessageQuery>(std::move(query_promise))->send(dialog_id, message_id);
|
||||
@ -15570,8 +15585,7 @@ FullMessageId MessagesManager::get_discussion_message(DialogId dialog_id, Messag
|
||||
}
|
||||
|
||||
void MessagesManager::on_get_discussion_message(DialogId dialog_id, MessageId message_id,
|
||||
vector<FullMessageId> full_message_ids, MessageId max_message_id,
|
||||
MessageId max_read_message_id, Promise<Unit> &&promise) {
|
||||
vector<FullMessageId> full_message_ids, Promise<Unit> &&promise) {
|
||||
if (G()->close_flag()) {
|
||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||
}
|
||||
|
@ -334,6 +334,9 @@ class MessagesManager : public Actor {
|
||||
void on_update_read_channel_messages_contents(
|
||||
tl_object_ptr<telegram_api::updateChannelReadMessagesContents> &&update);
|
||||
|
||||
void on_update_read_message_comments(DialogId dialog_id, MessageId message_id, MessageId max_message_id,
|
||||
MessageId max_read_message_id);
|
||||
|
||||
void on_update_channel_too_long(tl_object_ptr<telegram_api::updateChannelTooLong> &&update, bool force_apply);
|
||||
|
||||
void on_update_message_view_count(FullMessageId full_message_id, int32 view_count);
|
||||
@ -557,7 +560,7 @@ class MessagesManager : public Actor {
|
||||
FullMessageId get_discussion_message(DialogId dialog_id, MessageId message_id, bool force, Promise<Unit> &&promise);
|
||||
|
||||
void on_get_discussion_message(DialogId dialog_id, MessageId message_id, vector<FullMessageId> full_message_ids,
|
||||
MessageId max_message_id, MessageId max_read_message_id, Promise<Unit> &&promise);
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
MessageId get_dialog_pinned_message(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
|
@ -1664,6 +1664,12 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelReadMess
|
||||
td_->messages_manager_->on_update_read_channel_messages_contents(std::move(update));
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadDiscussion> update, bool /*force_apply*/) {
|
||||
td_->messages_manager_->on_update_read_message_comments(DialogId(update->peer_),
|
||||
MessageId(ServerMessageId(update->msg_id_)), MessageId(),
|
||||
MessageId(ServerMessageId(update->read_max_id_)));
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelTooLong> update, bool force_apply) {
|
||||
td_->messages_manager_->on_update_channel_too_long(std::move(update), force_apply);
|
||||
}
|
||||
@ -2200,7 +2206,4 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelParticip
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTheme> update, bool /*force_apply*/) {
|
||||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadDiscussion> update, bool /*force_apply*/) {
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user