Add readAllChatReactions.
This commit is contained in:
parent
d187d14660
commit
3150b3d491
@ -4799,6 +4799,9 @@ getExternalLink link:string allow_write_access:Bool = HttpUrl;
|
||||
//@description Marks all mentions in a chat as read @chat_id Chat identifier
|
||||
readAllChatMentions chat_id:int53 = Ok;
|
||||
|
||||
//@description Marks all reactions in a chat as read @chat_id Chat identifier
|
||||
readAllChatReactions chat_id:int53 = Ok;
|
||||
|
||||
|
||||
//@description Returns an existing chat corresponding to a given user @user_id User identifier @force If true, the chat will be created without network request. In this case all information about the chat except its type, title and photo can be incorrect
|
||||
createPrivateChat user_id:int53 force:Bool = Chat;
|
||||
|
@ -3043,6 +3043,40 @@ class ReadMentionsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class ReadReactionsQuery final : public Td::ResultHandler {
|
||||
Promise<AffectedHistory> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit ReadReactionsQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id) {
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
|
||||
if (input_peer == nullptr) {
|
||||
return promise_.set_error(Status::Error(400, "Chat is not accessible"));
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_readReactions(std::move(input_peer))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_readReactions>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(AffectedHistory(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReadReactionsQuery");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SaveDefaultSendAsActor final : public NetActorOnce {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
@ -10204,7 +10238,7 @@ void MessagesManager::on_get_dialog_messages_search_result(
|
||||
}
|
||||
if (filter == MessageSearchFilter::UnreadReaction) {
|
||||
d->unread_reaction_count = old_message_count;
|
||||
update_dialog_mention_notification_count(d);
|
||||
// update_dialog_mention_notification_count(d);
|
||||
send_update_chat_unread_reaction_count(d);
|
||||
}
|
||||
update_dialog = true;
|
||||
@ -11809,6 +11843,90 @@ void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uin
|
||||
get_erase_log_event_promise(log_event_id, std::move(promise)));
|
||||
}
|
||||
|
||||
void MessagesManager::read_all_dialog_reactions(DialogId dialog_id, Promise<Unit> &&promise) {
|
||||
Dialog *d = get_dialog_force(dialog_id, "read_all_dialog_reactions");
|
||||
if (d == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
LOG(INFO) << "Receive readAllChatReactions request in " << dialog_id << " with " << d->unread_reaction_count
|
||||
<< " unread reactions";
|
||||
if (!have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not accessible"));
|
||||
}
|
||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||
CHECK(d->unread_reaction_count == 0);
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
vector<MessageId> message_ids;
|
||||
find_messages(d->messages.get(), message_ids,
|
||||
[this, dialog_id](const Message *m) { return has_unread_message_reactions(dialog_id, m); });
|
||||
|
||||
LOG(INFO) << "Found " << message_ids.size() << " messages with unread reactions in memory";
|
||||
bool is_update_sent = false;
|
||||
for (auto message_id : message_ids) {
|
||||
auto m = get_message(d, message_id);
|
||||
CHECK(m != nullptr);
|
||||
CHECK(has_unread_message_reactions(dialog_id, m));
|
||||
CHECK(m->message_id == message_id);
|
||||
CHECK(m->message_id.is_valid());
|
||||
// remove_message_notification_id(d, m, true, false); // must be called before unread_reactions are cleared
|
||||
m->reactions->unread_reactions_.clear();
|
||||
|
||||
send_update_message_unread_reactions(dialog_id, m, 0);
|
||||
is_update_sent = true;
|
||||
on_message_changed(d, m, true, "read_all_dialog_reactions");
|
||||
}
|
||||
|
||||
if (d->unread_reaction_count != 0) {
|
||||
set_dialog_unread_reaction_count(d, 0);
|
||||
if (!is_update_sent) {
|
||||
send_update_chat_unread_reaction_count(d);
|
||||
} else {
|
||||
LOG(INFO) << "Update unread reaction message count in " << dialog_id << " to " << d->unread_reaction_count;
|
||||
on_dialog_updated(dialog_id, "read_all_dialog_reactions");
|
||||
}
|
||||
}
|
||||
// remove_message_dialog_notifications(d, MessageId::max(), true, "read_all_dialog_reactions");
|
||||
|
||||
read_all_dialog_reactions_on_server(dialog_id, 0, std::move(promise));
|
||||
}
|
||||
|
||||
class MessagesManager::ReadAllDialogReactionsOnServerLogEvent {
|
||||
public:
|
||||
DialogId dialog_id_;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
td::store(dialog_id_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
td::parse(dialog_id_, parser);
|
||||
}
|
||||
};
|
||||
|
||||
uint64 MessagesManager::save_read_all_dialog_reactions_on_server_log_event(DialogId dialog_id) {
|
||||
ReadAllDialogReactionsOnServerLogEvent log_event{dialog_id};
|
||||
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogReactionsOnServer,
|
||||
get_log_event_storer(log_event));
|
||||
}
|
||||
|
||||
void MessagesManager::read_all_dialog_reactions_on_server(DialogId dialog_id, uint64 log_event_id,
|
||||
Promise<Unit> &&promise) {
|
||||
if (log_event_id == 0 && G()->parameters().use_message_db) {
|
||||
log_event_id = save_read_all_dialog_reactions_on_server_log_event(dialog_id);
|
||||
}
|
||||
|
||||
AffectedHistoryQuery query = [td = td_](DialogId dialog_id, Promise<AffectedHistory> &&query_promise) {
|
||||
td->create_handler<ReadReactionsQuery>(std::move(query_promise))->send(dialog_id);
|
||||
};
|
||||
run_affected_history_query_until_complete(dialog_id, std::move(query), false,
|
||||
get_erase_log_event_promise(log_event_id, std::move(promise)));
|
||||
}
|
||||
|
||||
void MessagesManager::read_message_content_from_updates(MessageId message_id) {
|
||||
if (!message_id.is_valid() || !message_id.is_server()) {
|
||||
LOG(ERROR) << "Incoming update tries to read content of " << message_id;
|
||||
@ -15345,7 +15463,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
|
||||
}
|
||||
if (d->unread_reaction_count != dialog->unread_reactions_count_) {
|
||||
set_dialog_unread_reaction_count(d, dialog->unread_reactions_count_);
|
||||
update_dialog_mention_notification_count(d);
|
||||
// update_dialog_mention_notification_count(d);
|
||||
send_update_chat_unread_reaction_count(d);
|
||||
}
|
||||
}
|
||||
@ -22728,7 +22846,7 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo
|
||||
}
|
||||
if (filter == MessageSearchFilter::UnreadReaction) {
|
||||
d->unread_reaction_count = message_count;
|
||||
update_dialog_mention_notification_count(d);
|
||||
// update_dialog_mention_notification_count(d);
|
||||
send_update_chat_unread_reaction_count(d);
|
||||
}
|
||||
on_dialog_updated(dialog_id, "on_search_dialog_messages_db_result");
|
||||
@ -37656,7 +37774,7 @@ void MessagesManager::on_get_channel_dialog(DialogId dialog_id, MessageId last_m
|
||||
}
|
||||
if (d->unread_reaction_count != unread_reaction_count) {
|
||||
set_dialog_unread_reaction_count(d, unread_reaction_count);
|
||||
update_dialog_mention_notification_count(d);
|
||||
// update_dialog_mention_notification_count(d);
|
||||
send_update_chat_unread_reaction_count(d);
|
||||
}
|
||||
|
||||
@ -38747,6 +38865,25 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
||||
read_all_dialog_mentions_on_server(dialog_id, event.id_, Promise<Unit>());
|
||||
break;
|
||||
}
|
||||
case LogEvent::HandlerType::ReadAllDialogReactionsOnServer: {
|
||||
if (!G()->parameters().use_message_db) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
break;
|
||||
}
|
||||
|
||||
ReadAllDialogReactionsOnServerLogEvent log_event;
|
||||
log_event_parse(log_event, event.data_).ensure();
|
||||
|
||||
auto dialog_id = log_event.dialog_id_;
|
||||
Dialog *d = get_dialog_force(dialog_id, "ReadAllDialogReactionsOnServerLogEvent");
|
||||
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
break;
|
||||
}
|
||||
|
||||
read_all_dialog_reactions_on_server(dialog_id, event.id_, Promise<Unit>());
|
||||
break;
|
||||
}
|
||||
case LogEvent::HandlerType::ToggleDialogIsPinnedOnServer: {
|
||||
if (!G()->parameters().use_message_db) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
|
@ -386,6 +386,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void read_all_dialog_mentions(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
void read_all_dialog_reactions(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
Status add_recently_found_dialog(DialogId dialog_id) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Status remove_recently_found_dialog(DialogId dialog_id) TD_WARN_UNUSED_RESULT;
|
||||
@ -1699,6 +1701,7 @@ class MessagesManager final : public Actor {
|
||||
class ForwardMessagesLogEvent;
|
||||
class GetChannelDifferenceLogEvent;
|
||||
class ReadAllDialogMentionsOnServerLogEvent;
|
||||
class ReadAllDialogReactionsOnServerLogEvent;
|
||||
class ReadHistoryInSecretChatLogEvent;
|
||||
class ReadHistoryOnServerLogEvent;
|
||||
class ReadMessageContentsOnServerLogEvent;
|
||||
@ -2069,6 +2072,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 log_event_id, Promise<Unit> &&promise);
|
||||
|
||||
void read_all_dialog_reactions_on_server(DialogId dialog_id, uint64 log_event_id, Promise<Unit> &&promise);
|
||||
|
||||
void unpin_all_dialog_messages_on_server(DialogId dialog_id, uint64 log_event_id, Promise<Unit> &&promise);
|
||||
|
||||
using AffectedHistoryQuery = std::function<void(DialogId, Promise<AffectedHistory>)>;
|
||||
@ -3206,6 +3211,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
static uint64 save_read_all_dialog_mentions_on_server_log_event(DialogId dialog_id);
|
||||
|
||||
static uint64 save_read_all_dialog_reactions_on_server_log_event(DialogId dialog_id);
|
||||
|
||||
static uint64 save_toggle_dialog_is_pinned_on_server_log_event(DialogId dialog_id, bool is_pinned);
|
||||
|
||||
static uint64 save_reorder_pinned_dialogs_on_server_log_event(FolderId folder_id, const vector<DialogId> &dialog_ids);
|
||||
|
@ -5323,6 +5323,12 @@ void Td::on_request(uint64 id, const td_api::readAllChatMentions &request) {
|
||||
messages_manager_->read_all_dialog_mentions(DialogId(request.chat_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::readAllChatReactions &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->read_all_dialog_reactions(DialogId(request.chat_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getChatAvailableMessageSenders &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -665,6 +665,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::readAllChatMentions &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::readAllChatReactions &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getChatAvailableMessageSenders &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::setChatMessageSender &request);
|
||||
|
@ -120,6 +120,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
|
||||
case LogEvent::HandlerType::UnpinAllDialogMessagesOnServer:
|
||||
case LogEvent::HandlerType::DeleteAllCallMessagesOnServer:
|
||||
case LogEvent::HandlerType::DeleteDialogMessagesByDateOnServer:
|
||||
case LogEvent::HandlerType::ReadAllDialogReactionsOnServer:
|
||||
events.to_messages_manager.push_back(event.clone());
|
||||
break;
|
||||
case LogEvent::HandlerType::AddMessagePushNotification:
|
||||
|
@ -4341,6 +4341,10 @@ class CliClient final : public Actor {
|
||||
ChatId chat_id;
|
||||
get_args(args, chat_id);
|
||||
send_request(td_api::make_object<td_api::readAllChatMentions>(chat_id));
|
||||
} else if (op == "racr") {
|
||||
ChatId chat_id;
|
||||
get_args(args, chat_id);
|
||||
send_request(td_api::make_object<td_api::readAllChatReactions>(chat_id));
|
||||
} else if (op == "tre") {
|
||||
send_request(td_api::make_object<td_api::testReturnError>(
|
||||
args.empty() ? nullptr : td_api::make_object<td_api::error>(-1, args)));
|
||||
|
@ -100,6 +100,7 @@ class LogEvent {
|
||||
UnpinAllDialogMessagesOnServer = 0x121,
|
||||
DeleteAllCallMessagesOnServer = 0x122,
|
||||
DeleteDialogMessagesByDateOnServer = 0x123,
|
||||
ReadAllDialogReactionsOnServer = 0x124,
|
||||
GetChannelDifference = 0x140,
|
||||
AddMessagePushNotification = 0x200,
|
||||
EditMessagePushNotification = 0x201,
|
||||
|
Loading…
Reference in New Issue
Block a user