Skip to content

Commit 277dd3d

Browse files
committed
Do not add activity notification to message senders
If somebody sent a message he should already be aware of the message, no need for this.
1 parent 803bb55 commit 277dd3d

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

app/services/message_activity_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def fan_out_to_starring_users
3131
payload = build_payload
3232

3333
starring_user_ids.each do |user_id|
34-
read_at = (user_id == sender_user_id) ? Time.current : nil
34+
next if user_id == sender_user_id
3535

3636
Activity.create!(
3737
user_id: user_id,
3838
activity_type: "topic_message_received",
3939
subject: @message,
4040
payload: payload,
41-
read_at: read_at,
41+
read_at: nil,
4242
hidden: false
4343
)
4444
end

spec/services/message_activity_builder_spec.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,23 @@
6464
create(:topic_star, user: starring_user2, topic: topic)
6565
end
6666

67-
it "creates activities for all users who starred the topic" do
67+
it "creates activities for all users who starred the topic except the sender" do
6868
expect {
6969
builder.process!
70-
}.to change { Activity.count }.by(3) # 2 starring users + sender gets auto-starred
70+
}.to change { Activity.count }.by(2) # 2 starring users, sender is excluded
7171

7272
activities = Activity.where(activity_type: "topic_message_received")
73-
expect(activities.pluck(:user_id)).to match_array([starring_user1.id, starring_user2.id, sender_user.id])
73+
expect(activities.pluck(:user_id)).to match_array([starring_user1.id, starring_user2.id])
7474
end
7575

76-
it "marks sender's activity as read if they have topic starred" do
76+
it "does not create an activity for the sender even if they starred the topic" do
7777
# Sender also has the topic starred
7878
create(:topic_star, user: sender_user, topic: topic)
7979

8080
builder.process!
8181

8282
sender_activity = Activity.find_by(user: sender_user, subject: message)
83-
expect(sender_activity).to be_present
84-
expect(sender_activity.read_at).to be_present
85-
expect(sender_activity.read_at).to be_within(1.second).of(Time.current)
83+
expect(sender_activity).to be_nil
8684
end
8785

8886
it "does not mark other users' activities as read" do
@@ -130,13 +128,12 @@
130128
it "handles topic with no stars" do
131129
expect {
132130
builder.process!
133-
}.to change { Activity.count }.by(1)
131+
}.not_to change { Activity.count }
134132

135133
expect(TopicStar.exists?(user: sender_user, topic: topic)).to be true
136134

137135
activity = Activity.find_by(user: sender_user, subject: message)
138-
expect(activity).to be_present
139-
expect(activity.read_at).to be_present
136+
expect(activity).to be_nil
140137
end
141138

142139
it "handles sender who is not a registered user" do
@@ -166,10 +163,10 @@
166163

167164
expect {
168165
builder.process!
169-
}.to change { Activity.count }.by(2)
166+
}.to change { Activity.count }.by(1)
170167

171168
sender_activity = Activity.find_by(user: sender_user, subject: message)
172-
expect(sender_activity.read_at).to be_present
169+
expect(sender_activity).to be_nil
173170

174171
other_activity = Activity.find_by(user: other_user, subject: message)
175172
expect(other_activity.read_at).to be_nil

0 commit comments

Comments
 (0)