Implement new chat action rules.
GitOrigin-RevId: 12214755c86adfee0a7b3ec5f6e39024364cdb99
This commit is contained in:
parent
32f2338bd1
commit
d968fd0bed
@ -12272,9 +12272,9 @@ Result<BotData> ContactsManager::get_bot_data(UserId user_id) const {
|
|||||||
return bot_data;
|
return bot_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContactsManager::is_user_online(UserId user_id) const {
|
bool ContactsManager::is_user_online(UserId user_id, int32 tolerance) const {
|
||||||
int32 was_online = get_user_was_online(get_user(user_id), user_id);
|
int32 was_online = get_user_was_online(get_user(user_id), user_id);
|
||||||
return was_online > G()->unix_time();
|
return was_online > G()->unix_time() - tolerance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContactsManager::is_user_status_exact(UserId user_id) const {
|
bool ContactsManager::is_user_status_exact(UserId user_id) const {
|
||||||
|
@ -429,7 +429,7 @@ class ContactsManager : public Actor {
|
|||||||
bool is_user_bot(UserId user_id) const;
|
bool is_user_bot(UserId user_id) const;
|
||||||
Result<BotData> get_bot_data(UserId user_id) const TD_WARN_UNUSED_RESULT;
|
Result<BotData> get_bot_data(UserId user_id) const TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
bool is_user_online(UserId user_id) const;
|
bool is_user_online(UserId user_id, int32 tolerance = 0) const;
|
||||||
|
|
||||||
bool is_user_status_exact(UserId user_id) const;
|
bool is_user_status_exact(UserId user_id) const;
|
||||||
|
|
||||||
|
@ -6834,12 +6834,32 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, MessageId top_th
|
|||||||
if (td_->auth_manager_->is_bot() || !user_id.is_valid() || is_broadcast_channel(dialog_id)) {
|
if (td_->auth_manager_->is_bot() || !user_id.is_valid() || is_broadcast_channel(dialog_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!td_->messages_manager_->have_dialog(dialog_id)) {
|
||||||
|
LOG(DEBUG) << "Ignore typing in unknown " << dialog_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!td_->contacts_manager_->have_min_user(user_id)) {
|
||||||
|
LOG(DEBUG) << "Ignore typing of unknown " << user_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (top_thread_message_id != MessageId() && !top_thread_message_id.is_valid()) {
|
||||||
|
LOG(ERROR) << "Ignore typing in the message thread of " << top_thread_message_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_canceled = action == DialogAction();
|
bool is_canceled = action == DialogAction();
|
||||||
if (!is_canceled || message_content_type != MessageContentType::None) {
|
if (!is_canceled || message_content_type != MessageContentType::None) {
|
||||||
td_->contacts_manager_->on_update_user_local_was_online(user_id, date);
|
td_->contacts_manager_->on_update_user_local_was_online(user_id, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto dialog_type = dialog_id.get_type();
|
||||||
|
if (dialog_type == DialogType::User || dialog_type == DialogType::SecretChat) {
|
||||||
|
if (!td_->contacts_manager_->is_user_bot(user_id) && !td_->contacts_manager_->is_user_status_exact(user_id) &&
|
||||||
|
!get_dialog(dialog_id)->is_opened) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_canceled) {
|
if (is_canceled) {
|
||||||
auto actions_it = active_dialog_actions_.find(dialog_id);
|
auto actions_it = active_dialog_actions_.find(dialog_id);
|
||||||
if (actions_it == active_dialog_actions_.end()) {
|
if (actions_it == active_dialog_actions_.end()) {
|
||||||
@ -28864,12 +28884,14 @@ bool MessagesManager::is_dialog_action_unneeded(DialogId dialog_id) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!td_->auth_manager_->is_bot() && !td_->contacts_manager_->is_user_online(user_id)) {
|
if (!td_->auth_manager_->is_bot()) {
|
||||||
return true;
|
if (td_->contacts_manager_->is_user_status_exact(user_id)) {
|
||||||
}
|
if (!td_->contacts_manager_->is_user_online(user_id, 30)) {
|
||||||
|
return true;
|
||||||
if (!td_->auth_manager_->is_bot() && !td_->contacts_manager_->is_user_status_exact(user_id)) {
|
}
|
||||||
// return true;
|
} else {
|
||||||
|
// return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1836,74 +1836,31 @@ int32 UpdatesManager::get_short_update_date() const {
|
|||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserTyping> update, bool /*force_apply*/) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserTyping> update, bool /*force_apply*/) {
|
||||||
UserId user_id(update->user_id_);
|
UserId user_id(update->user_id_);
|
||||||
if (!td_->contacts_manager_->have_min_user(user_id)) {
|
td_->messages_manager_->on_user_dialog_action(DialogId(user_id), MessageId(), user_id,
|
||||||
LOG(DEBUG) << "Ignore user typing of unknown " << user_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DialogId dialog_id(user_id);
|
|
||||||
if (!td_->messages_manager_->have_dialog(dialog_id)) {
|
|
||||||
LOG(DEBUG) << "Ignore user typing in unknown " << dialog_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
td_->messages_manager_->on_user_dialog_action(dialog_id, MessageId(), user_id,
|
|
||||||
DialogAction(std::move(update->action_)), get_short_update_date());
|
DialogAction(std::move(update->action_)), get_short_update_date());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatUserTyping> update, bool /*force_apply*/) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChatUserTyping> update, bool /*force_apply*/) {
|
||||||
UserId user_id(update->user_id_);
|
td_->messages_manager_->on_user_dialog_action(DialogId(ChatId(update->chat_id_)), MessageId(),
|
||||||
if (!td_->contacts_manager_->have_min_user(user_id)) {
|
UserId(update->user_id_), DialogAction(std::move(update->action_)),
|
||||||
LOG(DEBUG) << "Ignore user chat typing of unknown " << user_id;
|
get_short_update_date());
|
||||||
return;
|
|
||||||
}
|
|
||||||
DialogId dialog_id(ChatId(update->chat_id_));
|
|
||||||
if (!td_->messages_manager_->have_dialog(dialog_id)) {
|
|
||||||
LOG(DEBUG) << "Ignore user chat typing in unknown " << dialog_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
td_->messages_manager_->on_user_dialog_action(dialog_id, MessageId(), user_id,
|
|
||||||
DialogAction(std::move(update->action_)), get_short_update_date());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelUserTyping> update, bool /*force_apply*/) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelUserTyping> update, bool /*force_apply*/) {
|
||||||
UserId user_id(update->user_id_);
|
|
||||||
if (!td_->contacts_manager_->have_min_user(user_id)) {
|
|
||||||
LOG(DEBUG) << "Ignore user channel typing of unknown " << user_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DialogId dialog_id(ChannelId(update->channel_id_));
|
|
||||||
if (!td_->messages_manager_->have_dialog(dialog_id)) {
|
|
||||||
LOG(DEBUG) << "Ignore user channel typing in unknown " << dialog_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MessageId top_thread_message_id;
|
MessageId top_thread_message_id;
|
||||||
if ((update->flags_ & telegram_api::updateChannelUserTyping::TOP_MSG_ID_MASK) != 0) {
|
if ((update->flags_ & telegram_api::updateChannelUserTyping::TOP_MSG_ID_MASK) != 0) {
|
||||||
top_thread_message_id = MessageId(ServerMessageId(update->top_msg_id_));
|
top_thread_message_id = MessageId(ServerMessageId(update->top_msg_id_));
|
||||||
if (!top_thread_message_id.is_valid() && top_thread_message_id != MessageId()) {
|
|
||||||
LOG(ERROR) << "Ignore user channel typing in the message thread of " << top_thread_message_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
td_->messages_manager_->on_user_dialog_action(dialog_id, top_thread_message_id, user_id,
|
td_->messages_manager_->on_user_dialog_action(DialogId(ChannelId(update->channel_id_)), top_thread_message_id,
|
||||||
DialogAction(std::move(update->action_)), get_short_update_date());
|
UserId(update->user_id_), DialogAction(std::move(update->action_)),
|
||||||
|
get_short_update_date());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedChatTyping> update, bool /*force_apply*/) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedChatTyping> update, bool /*force_apply*/) {
|
||||||
SecretChatId secret_chat_id(update->chat_id_);
|
SecretChatId secret_chat_id(update->chat_id_);
|
||||||
DialogId dialog_id(secret_chat_id);
|
|
||||||
|
|
||||||
if (!td_->messages_manager_->have_dialog(dialog_id)) {
|
|
||||||
LOG(DEBUG) << "Ignore secret chat typing in unknown " << dialog_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserId user_id = td_->contacts_manager_->get_secret_chat_user_id(secret_chat_id);
|
UserId user_id = td_->contacts_manager_->get_secret_chat_user_id(secret_chat_id);
|
||||||
if (!td_->contacts_manager_->have_user_force(user_id)) {
|
td_->messages_manager_->on_user_dialog_action(DialogId(secret_chat_id), MessageId(), user_id,
|
||||||
LOG(DEBUG) << "Ignore secret chat typing of unknown " << user_id;
|
DialogAction::get_typing_action(), get_short_update_date());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
td_->messages_manager_->on_user_dialog_action(dialog_id, MessageId(), user_id, DialogAction::get_typing_action(),
|
|
||||||
get_short_update_date());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserStatus> update, bool /*force_apply*/) {
|
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserStatus> update, bool /*force_apply*/) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user