Add need_message_push_notification.

GitOrigin-RevId: 05ea09c326cc779b3eb57e574f6bdb8771bbb239
This commit is contained in:
levlam 2019-03-26 18:05:53 +03:00
parent 6888403d61
commit 29e7c2b690
3 changed files with 81 additions and 5 deletions

View File

@ -18174,6 +18174,41 @@ NotificationGroupId MessagesManager::get_dialog_notification_group_id(DialogId d
return group_info.group_id;
}
bool MessagesManager::need_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id,
bool &contains_mention, bool is_pinned) {
init();
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return false;
}
if (message_id.is_valid() && message_id.get() <= d->last_new_message_id.get()) {
return false;
}
if (random_id != 0) {
CHECK(dialog_id.get_type() == DialogType::SecretChat);
if (get_message_id_by_random_id(d, random_id, "need_message_push_notification").is_valid()) {
return false;
}
}
if (dialog_id == get_my_dialog_id() || td_->auth_manager_->is_bot()) {
return false;
}
if (is_dialog_message_notification_disabled(dialog_id, G()->unix_time())) {
return false;
}
if (is_pinned && is_dialog_pinned_message_notifications_disabled(d)) {
contains_mention = false;
}
if (contains_mention && is_dialog_mention_notifications_disabled(d)) {
contains_mention = false;
}
return true;
}
NotificationId MessagesManager::get_next_notification_id(Dialog *d, NotificationGroupId notification_group_id,
MessageId message_id) {
NotificationId notification_id;
@ -18789,22 +18824,26 @@ bool MessagesManager::is_message_notification_disabled(const Dialog *d, const Me
break;
}
switch (d->dialog_id.get_type()) {
return is_dialog_message_notification_disabled(d->dialog_id, m->date);
}
bool MessagesManager::is_dialog_message_notification_disabled(DialogId dialog_id, int32 message_date) const {
switch (dialog_id.get_type()) {
case DialogType::User:
break;
case DialogType::Chat:
if (!td_->contacts_manager_->get_chat_is_active(d->dialog_id.get_chat_id())) {
if (!td_->contacts_manager_->get_chat_is_active(dialog_id.get_chat_id())) {
return true;
}
break;
case DialogType::Channel:
if (!td_->contacts_manager_->get_channel_status(d->dialog_id.get_channel_id()).is_member() ||
m->date < td_->contacts_manager_->get_channel_date(d->dialog_id.get_channel_id())) {
if (!td_->contacts_manager_->get_channel_status(dialog_id.get_channel_id()).is_member() ||
message_date < td_->contacts_manager_->get_channel_date(dialog_id.get_channel_id())) {
return true;
}
break;
case DialogType::SecretChat:
if (td_->contacts_manager_->get_secret_chat_state(d->dialog_id.get_secret_chat_id()) == SecretChatState::Closed) {
if (td_->contacts_manager_->get_secret_chat_state(dialog_id.get_secret_chat_id()) == SecretChatState::Closed) {
return true;
}
break;

View File

@ -691,6 +691,9 @@ class MessagesManager : public Actor {
FileSourceId get_message_file_source_id(FullMessageId full_message_id);
bool need_message_push_notification(DialogId dialog_id, MessageId message_id, int64 random_id, bool &contains_mention,
bool is_pinned);
struct MessageNotificationGroup {
DialogId dialog_id;
NotificationGroupType type = NotificationGroupType::Calls;
@ -1611,6 +1614,8 @@ class MessagesManager : public Actor {
bool is_message_notification_disabled(const Dialog *d, const Message *m) const;
bool is_dialog_message_notification_disabled(DialogId dialog_id, int32 message_date) const;
bool may_need_message_notification(const Dialog *d, const Message *m) const;
bool add_new_message_notification(Dialog *d, Message *m, bool force);

View File

@ -2357,6 +2357,15 @@ Status NotificationManager::process_push_notification_payload(string payload) {
return Status::OK();
}
if (loc_key == "LOCKED_MESSAGE") {
return Status::OK();
}
if (loc_key == "AUTH_REGION" || loc_key == "AUTH_UNKNOWN") {
// TODO
return Status::OK();
}
DialogId dialog_id;
if (has_json_object_field(custom, "from_id")) {
TRY_RESULT(user_id_int, get_json_object_int_field(custom, "from_id"));
@ -2461,6 +2470,16 @@ Status NotificationManager::process_push_notification_payload(string payload) {
return Status::Error("Receive message ID in secret chat push");
}
if (begins_with(loc_key, "ENCRYPTION_")) {
// TODO new secret chat notification
return Status::OK();
}
if (begins_with(loc_key, "PHONE_CALL_")) {
// TODO phone call request/missed notification
return Status::OK();
}
return process_message_push_notification(dialog_id, sender_user_id, MessageId(server_message_id), random_id,
contains_mention, std::move(loc_key), std::move(loc_args));
}
@ -2469,6 +2488,19 @@ Status NotificationManager::process_message_push_notification(DialogId dialog_id
MessageId message_id, int64 random_id,
bool contains_mention, string loc_key,
vector<string> loc_args) {
auto is_pinned = begins_with(loc_key, "PINNED_");
if (is_pinned) {
contains_mention = true;
}
if (!td_->messages_manager_->need_message_push_notification(dialog_id, message_id, random_id, contains_mention,
is_pinned)) {
VLOG(notifications) << "Don't need message push notification for " << message_id << "/" << random_id << " from "
<< dialog_id;
return Status::OK();
}
VLOG(notifications) << "Process message push notification " << loc_key << " for " << message_id << "/" << random_id
<< " from " << dialog_id << ", sent by " << sender_user_id << " with args " << loc_args;
return Status::OK();
}