A platform for community discussion. Free, open, simple.
FIX: Set invited PM users to watch so they receive notifications (#35722)
Loïc Guitaut7c03bddc9590
diff --git a/app/models/topic.rb b/app/models/topic.rbindex 4fcc1e68542..f6f895b2a58 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -2196,6 +2196,14 @@ class Topic < ActiveRecord::Basetopic_allowed_users.create!(user_id: target_user.id)end+ # Set the invited user to watch the PM so they receive notifications for new messages+ # even if they haven’t opened the PM yet.+ TopicUser.change(+ target_user,+ self,+ notification_level: TopicUser.notification_levels[:watching],+ )+user_in_allowed_group = (user.group_ids & topic_allowed_groups.map(&:group_id)).present?add_small_action(invited_by, "invited_user", target_user.username) if !user_in_allowed_groupdiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex ff834f0fead..60635b0bafc 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -1,7 +1,6 @@-# encoding: utf-8# frozen_string_literal: true-describe Topic do+RSpec.describe Topic dolet(:now) { Time.zone.local(2013, 11, 20, 8, 0) }fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }fab!(:user1) { Fabricate(:user, refresh_auto_groups: true) }@@ -996,6 +995,12 @@ describe Topic do).and not_change { Post.where(post_type: Post.types[:small_action]).count }end+ it "sets invited user to watch the PM" do+ expect { topic.invite(user, user1.username) }.to change {+ TopicUser.get(topic, user1).try(:notification_level)+ }.to TopicUser.notification_levels[:watching]+ end+context "when from a muted user" dobefore { Fabricate(:muted_user, user: user1, muted_user: user) }