Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit e4905d6

Browse files
committed
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".
1 parent 6f3e8e3 commit e4905d6

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

lib/assigner.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ def assign(
312312
publish_assignment(assignment, assign_to, note, status)
313313

314314
if assignment.assigned_to_user?
315-
if !TopicUser.exists?(
316-
user_id: assign_to.id,
317-
topic_id: topic.id,
318-
notification_level: TopicUser.notification_levels[:watching],
319-
)
315+
notification_level =
316+
assign_to.user_option&.notification_level_when_replying ||
317+
TopicUser.notification_levels[:watching]
318+
319+
if !TopicUser.exists?(user_id: assign_to.id, topic_id: topic.id, notification_level:)
320320
TopicUser.change(
321321
assign_to.id,
322322
topic.id,
323-
notification_level: TopicUser.notification_levels[:watching],
323+
notification_level:,
324324
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed],
325325
)
326326
end

spec/lib/assigner_spec.rb

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,34 @@
3030
[topic],
3131
)
3232

33-
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
34-
TopicUser.notification_levels[:watching],
35-
)
33+
notification_level = moderator.user_option.notification_level_when_replying
34+
35+
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
3636

3737
expect_enqueued_with(job: :unassign_notification) { assigner.unassign }
3838

3939
expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to eq([])
4040

41+
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
42+
end
43+
44+
it "uses the notification_level_when_replying of the assignee" do
45+
moderator.user_option.update!(
46+
notification_level_when_replying: TopicUser.notification_levels[:regular],
47+
)
48+
49+
assigner.assign(moderator)
50+
51+
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
52+
TopicUser.notification_levels[:regular],
53+
)
54+
end
55+
56+
it "defaults the notification level to watching" do
57+
moderator.user_option.update!(notification_level_when_replying: nil)
58+
59+
assigner.assign(moderator)
60+
4161
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
4262
TopicUser.notification_levels[:watching],
4363
)
@@ -111,28 +131,26 @@
111131
end
112132

113133
it "does not update notification level if already watching" do
114-
TopicUser.change(
115-
moderator.id,
116-
topic.id,
117-
notification_level: TopicUser.notification_levels[:watching],
118-
)
134+
notification_level = moderator.user_option.notification_level_when_replying
135+
136+
TopicUser.change(moderator.id, topic.id, notification_level:)
119137

120138
expect do assigner_self.assign(moderator) end.to_not change {
121139
TopicUser.last.notifications_reason_id
122140
}
123141
end
124142

125143
it "does not update notification level when unassigned" do
144+
notification_level = moderator.user_option.notification_level_when_replying
145+
126146
assigner.assign(moderator)
127147

128-
expect(TopicUser.find_by(user: moderator).notification_level).to eq(
129-
TopicUser.notification_levels[:watching],
130-
)
148+
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
131149

132150
assigner.unassign
133151

134152
expect(TopicUser.find_by(user: moderator, topic: topic).notification_level).to eq(
135-
TopicUser.notification_levels[:watching],
153+
notification_level,
136154
)
137155
end
138156

0 commit comments

Comments
 (0)