Add additional delay for somw service message notifications.
GitOrigin-RevId: 181e4e4d8eab72b161ae9cc1ab5961f80a0b5d99
This commit is contained in:
parent
2dae55013c
commit
42d59ba6b3
@ -21,7 +21,6 @@
|
||||
#include "td/telegram/MessageEntity.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/Photo.h"
|
||||
#include "td/telegram/ReplyMarkup.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
@ -4551,6 +4551,24 @@ bool need_reget_message_content(const MessageContent *content) {
|
||||
}
|
||||
}
|
||||
|
||||
bool need_delay_message_content_notification(const MessageContent *content, UserId my_user_id) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::ChatChangeTitle:
|
||||
case MessageContentType::ChatChangePhoto:
|
||||
case MessageContentType::ChatDeletePhoto:
|
||||
case MessageContentType::ChatJoinedByLink:
|
||||
return true;
|
||||
case MessageContentType::ChatAddUsers: {
|
||||
auto &added_user_ids = static_cast<const MessageChatAddUsers *>(content)->user_ids;
|
||||
return std::find(added_user_ids.begin(), added_user_ids.end(), my_user_id) == added_user_ids.end();
|
||||
}
|
||||
case MessageContentType::ChatDeleteUser:
|
||||
return static_cast<const MessageChatDeleteUser *>(content)->user_id != my_user_id;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void update_expired_message_content(unique_ptr<MessageContent> &content) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Photo:
|
||||
|
@ -220,6 +220,8 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
|
||||
|
||||
bool need_reget_message_content(const MessageContent *content);
|
||||
|
||||
bool need_delay_message_content_notification(const MessageContent *content, UserId my_user_id);
|
||||
|
||||
void update_expired_message_content(unique_ptr<MessageContent> &content);
|
||||
|
||||
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content);
|
||||
|
@ -18352,9 +18352,11 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
|
||||
}
|
||||
VLOG(notifications) << "Create " << m->notification_id << " with " << m->message_id << " in " << group_info.group_id
|
||||
<< '/' << d->dialog_id;
|
||||
int32 min_delay_ms =
|
||||
need_delay_message_content_notification(m->content.get(), td_->contacts_manager_->get_my_id()) ? 3000 : 0;
|
||||
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id,
|
||||
from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id,
|
||||
m->date, settings_dialog_id, m->disable_notification, m->notification_id,
|
||||
m->date, settings_dialog_id, m->disable_notification, min_delay_ms, m->notification_id,
|
||||
create_new_message_notification(m->message_id));
|
||||
return true;
|
||||
}
|
||||
@ -22107,7 +22109,7 @@ void MessagesManager::force_create_dialog(DialogId dialog_id, const char *source
|
||||
VLOG(notifications) << "Create " << d->new_secret_chat_notification_id << " with " << secret_chat_id;
|
||||
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification,
|
||||
notification_group_id, NotificationGroupType::SecretChat, dialog_id, date, dialog_id,
|
||||
false, d->new_secret_chat_notification_id, create_new_secret_chat_notification());
|
||||
false, 0, d->new_secret_chat_notification_id, create_new_secret_chat_notification());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -578,16 +578,16 @@ NotificationGroupKey NotificationManager::get_last_updated_group_key() const {
|
||||
return it->first;
|
||||
}
|
||||
|
||||
int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id,
|
||||
const PendingNotification ¬ification) const {
|
||||
auto delay_ms = [&]() {
|
||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||
return 0; // there is no reason to delay notifications in secret chats
|
||||
}
|
||||
if (!notification.type->can_be_delayed()) {
|
||||
return 0;
|
||||
}
|
||||
int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, const PendingNotification ¬ification,
|
||||
int32 min_delay_ms) const {
|
||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||
return MIN_NOTIFICATION_DELAY_MS; // there is no reason to delay notifications in secret chats
|
||||
}
|
||||
if (!notification.type->can_be_delayed()) {
|
||||
return MIN_NOTIFICATION_DELAY_MS;
|
||||
}
|
||||
|
||||
auto delay_ms = [&]() {
|
||||
auto online_info = td_->contacts_manager_->get_my_online_status();
|
||||
if (!online_info.is_online_local && online_info.is_online_remote) {
|
||||
// If we are offline, but online from some other client then delay notification
|
||||
@ -613,12 +613,12 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id,
|
||||
}();
|
||||
|
||||
auto passed_time_ms = max(0, static_cast<int32>((G()->server_time_cached() - notification.date - 1) * 1000));
|
||||
return max(delay_ms - passed_time_ms, MIN_NOTIFICATION_DELAY_MS);
|
||||
return max(max(min_delay_ms, delay_ms) - passed_time_ms, MIN_NOTIFICATION_DELAY_MS);
|
||||
}
|
||||
|
||||
void NotificationManager::add_notification(NotificationGroupId group_id, NotificationGroupType group_type,
|
||||
DialogId dialog_id, int32 date, DialogId notification_settings_dialog_id,
|
||||
bool is_silent, NotificationId notification_id,
|
||||
bool is_silent, int32 min_delay_ms, NotificationId notification_id,
|
||||
unique_ptr<NotificationType> type) {
|
||||
if (is_disabled() || max_notification_group_count_ == 0) {
|
||||
return;
|
||||
@ -649,7 +649,7 @@ void NotificationManager::add_notification(NotificationGroupId group_id, Notific
|
||||
notification.notification_id = notification_id;
|
||||
notification.type = std::move(type);
|
||||
|
||||
auto delay_ms = get_notification_delay_ms(dialog_id, notification);
|
||||
auto delay_ms = get_notification_delay_ms(dialog_id, notification, min_delay_ms);
|
||||
VLOG(notifications) << "Delay " << notification_id << " for " << delay_ms << " milliseconds";
|
||||
auto flush_time = delay_ms * 0.001 + Time::now();
|
||||
|
||||
@ -1769,7 +1769,7 @@ void NotificationManager::add_call_notification(DialogId dialog_id, CallId call_
|
||||
}
|
||||
active_notifications.push_back(ActiveCallNotification{call_id, notification_id});
|
||||
|
||||
add_notification(group_id, NotificationGroupType::Calls, dialog_id, G()->unix_time() + 120, dialog_id, false,
|
||||
add_notification(group_id, NotificationGroupType::Calls, dialog_id, G()->unix_time() + 120, dialog_id, false, 0,
|
||||
notification_id, create_new_call_notification(call_id));
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ class NotificationManager : public Actor {
|
||||
void load_group_force(NotificationGroupId group_id);
|
||||
|
||||
void add_notification(NotificationGroupId group_id, NotificationGroupType group_type, DialogId dialog_id, int32 date,
|
||||
DialogId notification_settings_dialog_id, bool is_silent, NotificationId notification_id,
|
||||
unique_ptr<NotificationType> type);
|
||||
DialogId notification_settings_dialog_id, bool is_silent, int32 min_delay_ms,
|
||||
NotificationId notification_id, unique_ptr<NotificationType> type);
|
||||
|
||||
void edit_notification(NotificationGroupId group_id, NotificationId notification_id,
|
||||
unique_ptr<NotificationType> type);
|
||||
@ -195,7 +195,8 @@ class NotificationManager : public Actor {
|
||||
|
||||
void send_add_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group);
|
||||
|
||||
int32 get_notification_delay_ms(DialogId dialog_id, const PendingNotification ¬ification) const;
|
||||
int32 get_notification_delay_ms(DialogId dialog_id, const PendingNotification ¬ification,
|
||||
int32 min_delay_ms) const;
|
||||
|
||||
void do_flush_pending_notifications(NotificationGroupKey &group_key, NotificationGroup &group,
|
||||
vector<PendingNotification> &pending_notifications);
|
||||
|
Reference in New Issue
Block a user