diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 63913594234..8a64ea47be9 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -252,14 +252,18 @@ SQL allowed_user_ids = topic.allowed_users.pluck(:id) - if allowed_user_ids.include?(post&.user_id) + if post && allowed_user_ids.include?(post.user_id) channels["/private-messages/sent"] = [post.user_id] - end - - if user_archive + elsif user_archive user_ids = [user_id] - channels["/private-messages/archive"] = user_ids - channels["/private-messages/inbox"] = user_ids + + [ + "/private-messages/archive", + "/private-messages/inbox", + "/private-messages/sent", + ].each do |channel| + channels[channel] = user_ids + end else topic.allowed_groups.each do |group| channel = "/private-messages/group/#{group.name.downcase}" diff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rb index 4553c4cd0c7..8413fefd095 100644 --- a/spec/models/topic_tracking_state_spec.rb +++ b/spec/models/topic_tracking_state_spec.rb @@ -163,7 +163,13 @@ describe TopicTrackingState do ) end - ["/private-messages/archive", "/private-messages/inbox"].each do |channel| + expect(messages.count).to eq(3) + + [ + "/private-messages/archive", + "/private-messages/inbox", + "/private-messages/sent", + ].each do |channel| message = messages.find do |message| message.channel = channel end