mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: consolidate chat channel notification settings (#29080)
On the chat channel settings page, we want to show a single Send push notifications setting instead of the current Desktop notifications and Mobile push notifications settings. For existing users, use the Mobile push notifications setting value for the new Send push notifications setting.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Chat::Api::ChannelsCurrentUserNotificationsSettingsController < Chat::Api::ChannelsController
|
||||
MEMBERSHIP_EDITABLE_PARAMS = %i[muted desktop_notification_level mobile_notification_level]
|
||||
MEMBERSHIP_EDITABLE_PARAMS = %i[muted notification_level]
|
||||
|
||||
def update
|
||||
settings_params = params.require(:notifications_settings).permit(MEMBERSHIP_EDITABLE_PARAMS)
|
||||
|
@ -131,15 +131,12 @@ module Jobs
|
||||
def send_notifications(membership, mention_type)
|
||||
payload = build_payload_for(membership, identifier_type: mention_type)
|
||||
|
||||
if !membership.desktop_notifications_never? && !membership.muted?
|
||||
if !membership.notifications_never? && !membership.muted?
|
||||
::MessageBus.publish(
|
||||
"/chat/notification-alert/#{membership.user_id}",
|
||||
payload,
|
||||
user_ids: [membership.user_id],
|
||||
)
|
||||
end
|
||||
|
||||
if !membership.mobile_notifications_never? && !membership.muted?
|
||||
::PostAlerter.push_notification(membership.user, payload)
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ module Jobs
|
||||
.where(chat_channel_id: @chat_channel.id)
|
||||
.where(following: true)
|
||||
.where(
|
||||
"desktop_notification_level = :always OR mobile_notification_level = :always OR users.id IN (SELECT user_id FROM user_chat_thread_memberships WHERE thread_id = :thread_id AND notification_level = :watching)",
|
||||
"notification_level = :always OR users.id IN (SELECT user_id FROM user_chat_thread_memberships WHERE thread_id = :thread_id AND notification_level = :watching)",
|
||||
always: always_notification_level,
|
||||
thread_id: @chat_message.thread_id,
|
||||
watching: ::Chat::NotificationLevels.all[:watching],
|
||||
@ -95,7 +95,7 @@ module Jobs
|
||||
thread_membership && create_watched_thread_notification(thread_membership)
|
||||
end
|
||||
|
||||
if membership.desktop_notifications_always? && !membership.muted?
|
||||
if membership.notifications_always? && !membership.muted?
|
||||
send_notification =
|
||||
DiscoursePluginRegistry.push_notification_filters.all? do |filter|
|
||||
filter.call(user, payload)
|
||||
@ -107,9 +107,7 @@ module Jobs
|
||||
user_ids: [user.id],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if membership.mobile_notifications_always? && !membership.muted?
|
||||
::PostAlerter.push_notification(user, payload)
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,7 @@
|
||||
module Chat
|
||||
class UserChatChannelMembership < ActiveRecord::Base
|
||||
self.table_name = "user_chat_channel_memberships"
|
||||
self.ignored_columns = %w[desktop_notification_level mobile_notification_level] # TODO: Remove once 20241003122030_add_notification_level_to_user_chat_channel_memberships has been promoted to pre-deploy
|
||||
|
||||
NOTIFICATION_LEVELS = { never: 0, mention: 1, always: 2 }
|
||||
|
||||
@ -10,8 +11,7 @@ module Chat
|
||||
belongs_to :last_read_message, class_name: "Chat::Message", optional: true
|
||||
belongs_to :chat_channel, class_name: "Chat::Channel", foreign_key: :chat_channel_id
|
||||
|
||||
enum :desktop_notification_level, NOTIFICATION_LEVELS, prefix: :desktop_notifications
|
||||
enum :mobile_notification_level, NOTIFICATION_LEVELS, prefix: :mobile_notifications
|
||||
enum :notification_level, NOTIFICATION_LEVELS, prefix: :notifications
|
||||
enum :join_mode, { manual: 0, automatic: 1 }
|
||||
|
||||
def mark_read!(new_last_read_id = nil)
|
||||
@ -30,16 +30,15 @@ end
|
||||
# last_read_message_id :integer
|
||||
# following :boolean default(FALSE), not null
|
||||
# muted :boolean default(FALSE), not null
|
||||
# desktop_notification_level :integer default("mention"), not null
|
||||
# mobile_notification_level :integer default("mention"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# last_unread_mention_when_emailed_id :integer
|
||||
# join_mode :integer default("manual"), not null
|
||||
# last_viewed_at :datetime not null
|
||||
# notification_level :integer default("mention"), not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# user_chat_channel_memberships_index (user_id,chat_channel_id,desktop_notification_level,mobile_notification_level,following)
|
||||
# user_chat_channel_memberships_index (user_id,chat_channel_id,notification_level,following)
|
||||
# user_chat_channel_unique_memberships (user_id,chat_channel_id) UNIQUE
|
||||
#
|
||||
|
@ -4,8 +4,7 @@ module Chat
|
||||
class BaseChannelMembershipSerializer < ApplicationSerializer
|
||||
attributes :following,
|
||||
:muted,
|
||||
:desktop_notification_level,
|
||||
:mobile_notification_level,
|
||||
:notification_level,
|
||||
:chat_channel_id,
|
||||
:last_read_message_id,
|
||||
:last_viewed_at
|
||||
|
@ -74,8 +74,7 @@ module Chat
|
||||
chat_channel_id: channel.id,
|
||||
muted: false,
|
||||
following: true,
|
||||
desktop_notification_level: always_level,
|
||||
mobile_notification_level: always_level,
|
||||
notification_level: always_level,
|
||||
created_at: Time.zone.now,
|
||||
updated_at: Time.zone.now,
|
||||
}
|
||||
|
@ -105,8 +105,7 @@ module Chat
|
||||
chat_channel_id: channel.id,
|
||||
muted: false,
|
||||
following: false,
|
||||
desktop_notification_level: always_level,
|
||||
mobile_notification_level: always_level,
|
||||
notification_level: always_level,
|
||||
created_at: Time.zone.now,
|
||||
updated_at: Time.zone.now,
|
||||
}
|
||||
|
Reference in New Issue
Block a user