mirror of
https://github.com/discourse/discourse.git
synced 2025-06-20 11:11:31 +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:
@ -193,8 +193,7 @@ Fabricator(:user_chat_channel_membership_for_dm, from: :user_chat_channel_member
|
||||
user
|
||||
chat_channel
|
||||
following true
|
||||
desktop_notification_level 2
|
||||
mobile_notification_level 2
|
||||
notification_level 2
|
||||
end
|
||||
|
||||
Fabricator(:chat_draft, class_name: "Chat::Draft") do
|
||||
|
@ -164,7 +164,7 @@ describe Jobs::Chat::NotifyMentioned do
|
||||
it "skips desktop notifications based on user preferences" do
|
||||
message = create_chat_message
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
|
||||
desktop_notification =
|
||||
@ -176,7 +176,7 @@ describe Jobs::Chat::NotifyMentioned do
|
||||
it "skips push notifications based on user preferences" do
|
||||
message = create_chat_message
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
|
||||
PostAlerter.expects(:push_notification).never
|
||||
@ -191,7 +191,7 @@ describe Jobs::Chat::NotifyMentioned do
|
||||
it "skips desktop notifications based on user muting preferences" do
|
||||
message = create_chat_message
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
muted: true,
|
||||
)
|
||||
|
||||
@ -204,7 +204,7 @@ describe Jobs::Chat::NotifyMentioned do
|
||||
it "skips push notifications based on user muting preferences" do
|
||||
message = create_chat_message
|
||||
Chat::UserChatChannelMembership.find_by(chat_channel: public_channel, user: user_2).update!(
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
muted: true,
|
||||
)
|
||||
|
||||
|
@ -44,7 +44,7 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@ -76,10 +76,11 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
|
||||
before { channel.update!(threading_enabled: true) }
|
||||
|
||||
context "with channel notification_level is always" do
|
||||
context "when channel notification_level is always" do
|
||||
before do
|
||||
always = Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always]
|
||||
membership1.update!(desktop_notification_level: always, mobile_notification_level: always)
|
||||
membership1.update!(
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
it "creates a core notification when watching the thread" do
|
||||
@ -110,8 +111,14 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
end
|
||||
end
|
||||
|
||||
context "without channel notifications" do
|
||||
context "when channel notification_level is never" do
|
||||
before do
|
||||
membership1.update!(
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
membership2.update!(
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
)
|
||||
thread.membership_for(user1).update!(
|
||||
notification_level: Chat::NotificationLevels.all[:watching],
|
||||
)
|
||||
@ -181,15 +188,14 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
end
|
||||
end
|
||||
|
||||
context "when mobile_notification_level is always and desktop_notification_level is none" do
|
||||
context "when notification_level is always" do
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
it "sends a mobile notification" do
|
||||
it "sends push notifications and message bus notifications" do
|
||||
PostAlerter.expects(:push_notification).with(
|
||||
user2,
|
||||
has_entries(
|
||||
@ -208,7 +214,7 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
),
|
||||
)
|
||||
messages = notification_messages_for(user2)
|
||||
expect(messages.length).to be_zero
|
||||
expect(messages.length).to eq(1)
|
||||
end
|
||||
|
||||
context "when the channel is muted via membership preferences" do
|
||||
@ -280,7 +286,7 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
@ -313,15 +319,14 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
end
|
||||
end
|
||||
|
||||
context "when mobile_notification_level is always and desktop_notification_level is none" do
|
||||
context "when notification_level is always" do
|
||||
before do
|
||||
membership2.update!(
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:never],
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
it "sends a mobile notification" do
|
||||
it "sends both push notifications and message bus notifications" do
|
||||
PostAlerter.expects(:push_notification).with(
|
||||
user2,
|
||||
has_entries(
|
||||
@ -340,7 +345,7 @@ RSpec.describe Jobs::Chat::NotifyWatching do
|
||||
),
|
||||
)
|
||||
messages = notification_messages_for(user2)
|
||||
expect(messages.length).to be_zero
|
||||
expect(messages.length).to eq(1)
|
||||
end
|
||||
|
||||
context "when the channel is muted via membership preferences" do
|
||||
|
@ -121,8 +121,7 @@ describe Chat::ChannelFetcher do
|
||||
user: user1,
|
||||
chat_channel: direct_message_channel1,
|
||||
following: true,
|
||||
desktop_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
mobile_notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
notification_level: Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always],
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -54,8 +54,7 @@ RSpec.describe Chat::Api::ChannelsCurrentUserNotificationsSettingsController do
|
||||
params: {
|
||||
notifications_settings: {
|
||||
muted: true,
|
||||
desktop_notification_level: "always",
|
||||
mobile_notification_level: "never",
|
||||
notification_level: "always",
|
||||
},
|
||||
}
|
||||
|
||||
@ -67,8 +66,7 @@ RSpec.describe Chat::Api::ChannelsCurrentUserNotificationsSettingsController do
|
||||
membership = channel_1.membership_for(current_user)
|
||||
|
||||
expect(membership.muted).to eq(true)
|
||||
expect(membership.desktop_notification_level).to eq("always")
|
||||
expect(membership.mobile_notification_level).to eq("never")
|
||||
expect(membership.notification_level).to eq("always")
|
||||
end
|
||||
end
|
||||
|
||||
@ -123,8 +121,7 @@ RSpec.describe Chat::Api::ChannelsCurrentUserNotificationsSettingsController do
|
||||
params: {
|
||||
notifications_settings: {
|
||||
muted: true,
|
||||
desktop_notification_level: "always",
|
||||
mobile_notification_level: "never",
|
||||
notification_level: "always",
|
||||
},
|
||||
}
|
||||
|
||||
@ -136,8 +133,7 @@ RSpec.describe Chat::Api::ChannelsCurrentUserNotificationsSettingsController do
|
||||
membership = dm_channel_1.membership_for(current_user)
|
||||
|
||||
expect(membership.muted).to eq(true)
|
||||
expect(membership.desktop_notification_level).to eq("always")
|
||||
expect(membership.mobile_notification_level).to eq("never")
|
||||
expect(membership.notification_level).to eq("always")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,10 +46,9 @@ RSpec.describe Chat::StructuredChannelSerializer do
|
||||
.as_json,
|
||||
).to include(
|
||||
"chat_channel_id" => channel1.id,
|
||||
"desktop_notification_level" => "mention",
|
||||
"notification_level" => "mention",
|
||||
"following" => true,
|
||||
"last_read_message_id" => nil,
|
||||
"mobile_notification_level" => "mention",
|
||||
"muted" => false,
|
||||
)
|
||||
end
|
||||
@ -64,10 +63,9 @@ RSpec.describe Chat::StructuredChannelSerializer do
|
||||
.as_json,
|
||||
).to include(
|
||||
"chat_channel_id" => channel3.id,
|
||||
"desktop_notification_level" => "always",
|
||||
"notification_level" => "always",
|
||||
"following" => true,
|
||||
"last_read_message_id" => nil,
|
||||
"mobile_notification_level" => "always",
|
||||
"muted" => false,
|
||||
)
|
||||
end
|
||||
|
@ -69,8 +69,7 @@ RSpec.describe Chat::CreateDirectMessageChannel do
|
||||
expect(membership).to have_attributes(
|
||||
following: false,
|
||||
muted: false,
|
||||
desktop_notification_level: "always",
|
||||
mobile_notification_level: "always",
|
||||
notification_level: "always",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -12,8 +12,7 @@ RSpec.describe Chat::MessageDestroyer do
|
||||
chat_channel: message_1.chat_channel,
|
||||
last_read_message: message_1,
|
||||
following: true,
|
||||
desktop_notification_level: 2,
|
||||
mobile_notification_level: 2,
|
||||
notification_level: 2,
|
||||
)
|
||||
|
||||
described_class.new.destroy_in_batches(Chat::Message.where(id: message_1.id))
|
||||
@ -33,8 +32,7 @@ RSpec.describe Chat::MessageDestroyer do
|
||||
chat_channel: message_1.chat_channel,
|
||||
last_read_message: message_4,
|
||||
following: true,
|
||||
desktop_notification_level: 2,
|
||||
mobile_notification_level: 2,
|
||||
notification_level: 2,
|
||||
)
|
||||
|
||||
described_class.new.destroy_in_batches(Chat::Message.where(id: message_4.id))
|
||||
|
@ -9,8 +9,7 @@
|
||||
"muted": { "type": "boolean" },
|
||||
"unread_count": { "type": "number" },
|
||||
"unread_mentions": { "type": "number" },
|
||||
"desktop_notification_level": { "type": "string" },
|
||||
"mobile_notification_level": { "type": "string" },
|
||||
"notification_level": { "type": "string" },
|
||||
"following": { "type": "boolean" }
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@
|
||||
"chat_channel_id",
|
||||
"last_read_message_id",
|
||||
"muted",
|
||||
"desktop_notification_level",
|
||||
"mobile_notification_level",
|
||||
"notification_level",
|
||||
"following",
|
||||
"last_viewed_at"
|
||||
],
|
||||
@ -13,8 +12,7 @@
|
||||
"chat_channel_id": { "type": "number" },
|
||||
"last_read_message_id": { "type": ["number", "null"] },
|
||||
"muted": { "type": "boolean" },
|
||||
"desktop_notification_level": { "type": "string" },
|
||||
"mobile_notification_level": { "type": "string" },
|
||||
"notification_level": { "type": "string" },
|
||||
"following": { "type": "boolean" },
|
||||
"user": {
|
||||
"type": ["object", "null"],
|
||||
|
@ -122,36 +122,18 @@ RSpec.describe "Channel - Info - Settings page", type: :system do
|
||||
}.to change { membership.reload.muted }.from(false).to(true)
|
||||
end
|
||||
|
||||
it "can change desktop notification level" do
|
||||
it "can change notification level" do
|
||||
chat_page.visit_channel_settings(channel_1)
|
||||
membership = channel_1.membership_for(current_user)
|
||||
|
||||
expect {
|
||||
select_kit =
|
||||
PageObjects::Components::SelectKit.new(
|
||||
".c-channel-settings__desktop-notifications-selector",
|
||||
)
|
||||
PageObjects::Components::SelectKit.new(".c-channel-settings__notifications-selector")
|
||||
select_kit.expand
|
||||
select_kit.select_row_by_name("Never")
|
||||
|
||||
expect(toasts).to have_success(I18n.t("js.saved"))
|
||||
}.to change { membership.reload.desktop_notification_level }.from("mention").to("never")
|
||||
end
|
||||
|
||||
it "can change mobile notification level" do
|
||||
chat_page.visit_channel_settings(channel_1)
|
||||
membership = channel_1.membership_for(current_user)
|
||||
|
||||
expect {
|
||||
select_kit =
|
||||
PageObjects::Components::SelectKit.new(
|
||||
".c-channel-settings__mobile-notifications-selector",
|
||||
)
|
||||
select_kit.expand
|
||||
select_kit.select_row_by_name("Never")
|
||||
|
||||
expect(toasts).to have_success(I18n.t("js.saved"))
|
||||
}.to change { membership.reload.mobile_notification_level }.from("mention").to("never")
|
||||
}.to change { membership.reload.notification_level }.from("mention").to("never")
|
||||
end
|
||||
|
||||
it "can unfollow channel" do
|
||||
|
Reference in New Issue
Block a user