Add notificationTypeNewMessage.show_preview.
This commit is contained in:
parent
1cbfec9de9
commit
80df1e2968
@ -3280,8 +3280,8 @@ pushMessageContentMediaAlbum total_count:int32 has_photos:Bool has_videos:Bool h
|
|||||||
|
|
||||||
//@class NotificationType @description Contains detailed information about a notification
|
//@class NotificationType @description Contains detailed information about a notification
|
||||||
|
|
||||||
//@description New message was received @message The message
|
//@description New message was received @message The message @show_preview True, if message content must be displayed in notifications
|
||||||
notificationTypeNewMessage message:message = NotificationType;
|
notificationTypeNewMessage message:message show_preview:Bool = NotificationType;
|
||||||
|
|
||||||
//@description New secret chat was created
|
//@description New secret chat was created
|
||||||
notificationTypeNewSecretChat = NotificationType;
|
notificationTypeNewSecretChat = NotificationType;
|
||||||
|
@ -29361,6 +29361,36 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MessagesManager::get_dialog_show_preview(const Dialog *d) const {
|
||||||
|
CHECK(!td_->auth_manager_->is_bot());
|
||||||
|
CHECK(d != nullptr);
|
||||||
|
if (d->notification_settings.use_default_show_preview) {
|
||||||
|
auto scope = get_dialog_notification_setting_scope(d->dialog_id);
|
||||||
|
return td_->notification_settings_manager_->get_scope_show_preview(scope);
|
||||||
|
} else {
|
||||||
|
return d->notification_settings.show_preview;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MessagesManager::is_message_preview_enabled(const Dialog *d, const Message *m, bool from_mentions) {
|
||||||
|
if (!get_dialog_show_preview(d)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!from_mentions) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto sender_dialog_id = get_message_sender(m);
|
||||||
|
if (!sender_dialog_id.is_valid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
d = get_dialog_force(sender_dialog_id, "is_message_preview_enabled");
|
||||||
|
if (d == nullptr) {
|
||||||
|
auto scope = get_dialog_notification_setting_scope(sender_dialog_id);
|
||||||
|
return td_->notification_settings_manager_->get_scope_show_preview(scope);
|
||||||
|
}
|
||||||
|
return get_dialog_show_preview(d);
|
||||||
|
}
|
||||||
|
|
||||||
bool MessagesManager::is_from_mention_notification_group(const Message *m) {
|
bool MessagesManager::is_from_mention_notification_group(const Message *m) {
|
||||||
return m->contains_mention && !m->is_mention_notification_disabled;
|
return m->contains_mention && !m->is_mention_notification_disabled;
|
||||||
}
|
}
|
||||||
@ -29400,7 +29430,7 @@ void MessagesManager::try_add_pinned_message_notification(Dialog *d, vector<Noti
|
|||||||
|
|
||||||
auto pos = res.size();
|
auto pos = res.size();
|
||||||
res.emplace_back(m->notification_id, m->date, m->disable_notification,
|
res.emplace_back(m->notification_id, m->date, m->disable_notification,
|
||||||
create_new_message_notification(message_id));
|
create_new_message_notification(message_id, is_message_preview_enabled(d, m, true)));
|
||||||
while (pos > 0 && res[pos - 1].type->get_message_id() < message_id) {
|
while (pos > 0 && res[pos - 1].type->get_message_id() < message_id) {
|
||||||
std::swap(res[pos - 1], res[pos]);
|
std::swap(res[pos - 1], res[pos]);
|
||||||
pos--;
|
pos--;
|
||||||
@ -29514,8 +29544,9 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
|
|||||||
|
|
||||||
if (is_correct) {
|
if (is_correct) {
|
||||||
// skip mention messages returned among unread messages
|
// skip mention messages returned among unread messages
|
||||||
res.emplace_back(m->notification_id, m->date, m->disable_notification,
|
res.emplace_back(
|
||||||
create_new_message_notification(m->message_id));
|
m->notification_id, m->date, m->disable_notification,
|
||||||
|
create_new_message_notification(m->message_id, is_message_preview_enabled(d, m, from_mentions)));
|
||||||
} else {
|
} else {
|
||||||
remove_message_notification_id(d, m, true, false);
|
remove_message_notification_id(d, m, true, false);
|
||||||
on_message_changed(d, m, false, "get_message_notifications_from_database_force");
|
on_message_changed(d, m, false, "get_message_notifications_from_database_force");
|
||||||
@ -29774,7 +29805,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog
|
|||||||
// skip mention messages returned among unread messages
|
// skip mention messages returned among unread messages
|
||||||
CHECK(m->date > 0);
|
CHECK(m->date > 0);
|
||||||
res.emplace_back(m->notification_id, m->date, m->disable_notification,
|
res.emplace_back(m->notification_id, m->date, m->disable_notification,
|
||||||
create_new_message_notification(m->message_id));
|
create_new_message_notification(m->message_id, is_message_preview_enabled(d, m, from_mentions)));
|
||||||
} else {
|
} else {
|
||||||
remove_message_notification_id(d, m, true, false);
|
remove_message_notification_id(d, m, true, false);
|
||||||
on_message_changed(d, m, false, "on_get_message_notifications_from_database");
|
on_message_changed(d, m, false, "on_get_message_notifications_from_database");
|
||||||
@ -30225,7 +30256,8 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f
|
|||||||
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id,
|
send_closure_later(G()->notification_manager(), &NotificationManager::add_notification, notification_group_id,
|
||||||
from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id,
|
from_mentions ? NotificationGroupType::Mentions : NotificationGroupType::Messages, d->dialog_id,
|
||||||
m->date, settings_dialog_id, m->disable_notification, is_silent ? 0 : ringtone_id, min_delay_ms,
|
m->date, settings_dialog_id, m->disable_notification, is_silent ? 0 : ringtone_id, min_delay_ms,
|
||||||
m->notification_id, create_new_message_notification(m->message_id),
|
m->notification_id,
|
||||||
|
create_new_message_notification(m->message_id, is_message_preview_enabled(d, m, from_mentions)),
|
||||||
"add_new_message_notification");
|
"add_new_message_notification");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -34343,8 +34375,11 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
|||||||
if (need_send_update && m->notification_id.is_valid() && is_message_notification_active(d, m)) {
|
if (need_send_update && m->notification_id.is_valid() && is_message_notification_active(d, m)) {
|
||||||
auto &group_info = get_notification_group_info(d, m);
|
auto &group_info = get_notification_group_info(d, m);
|
||||||
if (group_info.group_id.is_valid()) {
|
if (group_info.group_id.is_valid()) {
|
||||||
send_closure_later(G()->notification_manager(), &NotificationManager::edit_notification,
|
send_closure_later(
|
||||||
group_info.group_id, m->notification_id, create_new_message_notification(m->message_id));
|
G()->notification_manager(), &NotificationManager::edit_notification, group_info.group_id,
|
||||||
|
m->notification_id,
|
||||||
|
create_new_message_notification(
|
||||||
|
m->message_id, is_message_preview_enabled(d, m, is_from_mention_notification_group(m))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (need_send_update && m->is_pinned && d->pinned_message_notification_message_id.is_valid() &&
|
if (need_send_update && m->is_pinned && d->pinned_message_notification_message_id.is_valid() &&
|
||||||
@ -34353,9 +34388,10 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
|||||||
if (pinned_message != nullptr && pinned_message->notification_id.is_valid() &&
|
if (pinned_message != nullptr && pinned_message->notification_id.is_valid() &&
|
||||||
is_message_notification_active(d, pinned_message) &&
|
is_message_notification_active(d, pinned_message) &&
|
||||||
get_message_content_pinned_message_id(pinned_message->content.get()) == message_id) {
|
get_message_content_pinned_message_id(pinned_message->content.get()) == message_id) {
|
||||||
send_closure_later(G()->notification_manager(), &NotificationManager::edit_notification,
|
send_closure_later(
|
||||||
d->mention_notification_group.group_id, pinned_message->notification_id,
|
G()->notification_manager(), &NotificationManager::edit_notification,
|
||||||
create_new_message_notification(pinned_message->message_id));
|
d->mention_notification_group.group_id, pinned_message->notification_id,
|
||||||
|
create_new_message_notification(pinned_message->message_id, is_message_preview_enabled(d, m, true)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_message_count_by_index(d, -1, old_index_mask & ~new_index_mask);
|
update_message_count_by_index(d, -1, old_index_mask & ~new_index_mask);
|
||||||
|
@ -2383,6 +2383,10 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void send_update_new_message(const Dialog *d, const Message *m);
|
void send_update_new_message(const Dialog *d, const Message *m);
|
||||||
|
|
||||||
|
bool get_dialog_show_preview(const Dialog *d) const;
|
||||||
|
|
||||||
|
bool is_message_preview_enabled(const Dialog *d, const Message *m, bool from_mentions);
|
||||||
|
|
||||||
static bool is_from_mention_notification_group(const Message *m);
|
static bool is_from_mention_notification_group(const Message *m);
|
||||||
|
|
||||||
static bool is_message_notification_active(const Dialog *d, const Message *m);
|
static bool is_message_notification_active(const Dialog *d, const Message *m);
|
||||||
|
@ -582,6 +582,10 @@ const unique_ptr<NotificationSound> &NotificationSettingsManager::get_scope_noti
|
|||||||
return get_scope_notification_settings(scope)->sound;
|
return get_scope_notification_settings(scope)->sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NotificationSettingsManager::get_scope_show_preview(NotificationSettingsScope scope) const {
|
||||||
|
return get_scope_notification_settings(scope)->show_preview;
|
||||||
|
}
|
||||||
|
|
||||||
bool NotificationSettingsManager::get_scope_disable_pinned_message_notifications(
|
bool NotificationSettingsManager::get_scope_disable_pinned_message_notifications(
|
||||||
NotificationSettingsScope scope) const {
|
NotificationSettingsScope scope) const {
|
||||||
return get_scope_notification_settings(scope)->disable_pinned_message_notifications;
|
return get_scope_notification_settings(scope)->disable_pinned_message_notifications;
|
||||||
|
@ -44,6 +44,8 @@ class NotificationSettingsManager final : public Actor {
|
|||||||
|
|
||||||
const unique_ptr<NotificationSound> &get_scope_notification_sound(NotificationSettingsScope scope) const;
|
const unique_ptr<NotificationSound> &get_scope_notification_sound(NotificationSettingsScope scope) const;
|
||||||
|
|
||||||
|
bool get_scope_show_preview(NotificationSettingsScope scope) const;
|
||||||
|
|
||||||
bool get_scope_disable_pinned_message_notifications(NotificationSettingsScope scope) const;
|
bool get_scope_disable_pinned_message_notifications(NotificationSettingsScope scope) const;
|
||||||
|
|
||||||
bool get_scope_disable_mention_notifications(NotificationSettingsScope scope) const;
|
bool get_scope_disable_mention_notifications(NotificationSettingsScope scope) const;
|
||||||
|
@ -49,7 +49,7 @@ class NotificationTypeMessage final : public NotificationType {
|
|||||||
if (message_object == nullptr) {
|
if (message_object == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return td_api::make_object<td_api::notificationTypeNewMessage>(std::move(message_object));
|
return td_api::make_object<td_api::notificationTypeNewMessage>(std::move(message_object), show_preview_);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder &to_string_builder(StringBuilder &string_builder) const final {
|
StringBuilder &to_string_builder(StringBuilder &string_builder) const final {
|
||||||
@ -57,9 +57,11 @@ class NotificationTypeMessage final : public NotificationType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageId message_id_;
|
MessageId message_id_;
|
||||||
|
bool show_preview_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NotificationTypeMessage(MessageId message_id) : message_id_(message_id) {
|
NotificationTypeMessage(MessageId message_id, bool show_preview)
|
||||||
|
: message_id_(message_id), show_preview_(show_preview) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -380,8 +382,8 @@ class NotificationTypePushMessage final : public NotificationType {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
unique_ptr<NotificationType> create_new_message_notification(MessageId message_id) {
|
unique_ptr<NotificationType> create_new_message_notification(MessageId message_id, bool show_preview) {
|
||||||
return make_unique<NotificationTypeMessage>(message_id);
|
return make_unique<NotificationTypeMessage>(message_id, show_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<NotificationType> create_new_secret_chat_notification() {
|
unique_ptr<NotificationType> create_new_secret_chat_notification() {
|
||||||
|
@ -53,7 +53,7 @@ inline StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr
|
|||||||
return string_builder << *notification_type;
|
return string_builder << *notification_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<NotificationType> create_new_message_notification(MessageId message_id);
|
unique_ptr<NotificationType> create_new_message_notification(MessageId message_id, bool show_preview);
|
||||||
|
|
||||||
unique_ptr<NotificationType> create_new_secret_chat_notification();
|
unique_ptr<NotificationType> create_new_secret_chat_notification();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user