FEATURE: better notification level on assign

Use the "when I post in a topic, set that topic to..." user preference as the default notification level when a topic/post is assigned to a user instead of always setting it to "watching".
This commit is contained in:
Régis Hanol 2024-11-05 18:37:59 +01:00
parent 6f3e8e3b5c
commit e4905d6760
No known key found for this signature in database
2 changed files with 36 additions and 18 deletions

View File

@ -312,15 +312,15 @@ class ::Assigner
publish_assignment(assignment, assign_to, note, status)
if assignment.assigned_to_user?
if !TopicUser.exists?(
user_id: assign_to.id,
topic_id: topic.id,
notification_level: TopicUser.notification_levels[:watching],
)
notification_level =
assign_to.user_option&.notification_level_when_replying ||
TopicUser.notification_levels[:watching]
if !TopicUser.exists?(user_id: assign_to.id, topic_id: topic.id, notification_level:)
TopicUser.change(
assign_to.id,
topic.id,
notification_level: TopicUser.notification_levels[:watching],
notification_level:,
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed],
)
end

View File

@ -30,14 +30,34 @@ RSpec.describe Assigner do
[topic],
)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
notification_level = moderator.user_option.notification_level_when_replying
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
expect_enqueued_with(job: :unassign_notification) { assigner.unassign }
expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to eq([])
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
end
it "uses the notification_level_when_replying of the assignee" do
moderator.user_option.update!(
notification_level_when_replying: TopicUser.notification_levels[:regular],
)
assigner.assign(moderator)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:regular],
)
end
it "defaults the notification level to watching" do
moderator.user_option.update!(notification_level_when_replying: nil)
assigner.assign(moderator)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
@ -111,11 +131,9 @@ RSpec.describe Assigner do
end
it "does not update notification level if already watching" do
TopicUser.change(
moderator.id,
topic.id,
notification_level: TopicUser.notification_levels[:watching],
)
notification_level = moderator.user_option.notification_level_when_replying
TopicUser.change(moderator.id, topic.id, notification_level:)
expect do assigner_self.assign(moderator) end.to_not change {
TopicUser.last.notifications_reason_id
@ -123,16 +141,16 @@ RSpec.describe Assigner do
end
it "does not update notification level when unassigned" do
notification_level = moderator.user_option.notification_level_when_replying
assigner.assign(moderator)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
assigner.unassign
expect(TopicUser.find_by(user: moderator, topic: topic).notification_level).to eq(
TopicUser.notification_levels[:watching],
notification_level,
)
end