Skip to content

Commit 0d6c4f0

Browse files
authored
FIX: Prioritize watching notifications over follow notifications (#163)
Using the `post_alerter_after_save_post` event instead of `post_alerter_before_post` allows our post notification system to check for "watching" notifications eligibility prior to "follow" notifications which means if a user is eligible for both types, the "watching" notification is the one that will go through to the user. Internal topic: t/169094.
1 parent c7f5f1a commit 0d6c4f0

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

plugin.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ module ::Follow
9999
register_editable_user_custom_field(field)
100100
end
101101

102-
on(:post_alerter_before_post) do |post, new_record, notified|
103-
Follow::NotificationHandler.new(post, notified).handle if new_record
104-
end
105-
106-
# TODO(2022-08-30): Remove when post_alerter_before_post is available
107102
on(:post_alerter_after_save_post) do |post, new_record, notified|
108103
next if !new_record
109104
Follow::NotificationHandler.new(post, notified).handle

spec/integration/follow_notifications_spec.rb

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,14 @@ def follow_notification_assertions(notification, followed, post, topic)
8282
last_read_post_number: 1,
8383
notification_level: TopicUser.notification_levels[:watching],
8484
)
85-
@notification_post = create_post(topic: topic, user: followed)
8685
end
8786

88-
it "follower receives a notification that a followed user has posted" do
89-
notification =
90-
follower.notifications.find_by(
91-
topic_id: topic.id,
92-
notification_type: Notification.types[:following_replied],
93-
)
94-
follow_notification_assertions(notification, followed, @notification_post, topic)
95-
end
96-
97-
it "follower receives only 1 notification for the post" do
98-
expect(follower.notifications.count).to eq(1)
87+
it "follower receives only a watching notification" do
88+
expect { create_post(topic: topic, user: followed) }.to change {
89+
follower.notifications.count
90+
}.by(1).and change {
91+
follower.notifications.where(notification_type: Notification.types[:posted]).count
92+
}.by(1)
9993
end
10094
end
10195

@@ -138,20 +132,17 @@ def follow_notification_assertions(notification, followed, post, topic)
138132
CategoryUser.notification_levels[:watching],
139133
category.id,
140134
)
141-
@notification_post = create_post(topic: topic, user: followed)
142135
end
143136

144-
it "follower receives only a notification" do
145-
expect(follower.notifications.count).to eq(1)
146-
end
147-
148-
it "follower receives a notification for the post made by the followed user" do
149-
notification =
150-
follower.notifications.find_by(
151-
topic_id: topic.id,
152-
notification_type: Notification.types[:following_replied],
153-
)
154-
follow_notification_assertions(notification, followed, @notification_post, topic)
137+
it "follower receives only a watching notification" do
138+
expect { create_post(topic: topic, user: followed) }.to change {
139+
follower.notifications.count
140+
}.by(1).and change {
141+
follower
142+
.notifications
143+
.where(notification_type: Notification.types[:watching_category_or_tag])
144+
.count
145+
}.by(1)
155146
end
156147
end
157148

0 commit comments

Comments
 (0)