From 8e9a8472f4714a7e2e63e669aaa7b58c9c8cd0e8 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Mon, 15 Feb 2016 10:56:39 +1100 Subject: [PATCH] FEATURE: don't move muted messages back into inbox --- app/models/user_archived_message.rb | 6 ++++++ spec/models/user_archived_message_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/models/user_archived_message_spec.rb diff --git a/app/models/user_archived_message.rb b/app/models/user_archived_message.rb index 3a54b6ea6df..0617c76f0b5 100644 --- a/app/models/user_archived_message.rb +++ b/app/models/user_archived_message.rb @@ -3,6 +3,12 @@ class UserArchivedMessage < ActiveRecord::Base belongs_to :topic def self.move_to_inbox!(user_id, topic_id) + return if (TopicUser.where( + user_id: user_id, + topic_id: topic_id, + notification_level: TopicUser.notification_levels[:muted] + ).exists?) + UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, user_ids: [user_id]) end diff --git a/spec/models/user_archived_message_spec.rb b/spec/models/user_archived_message_spec.rb new file mode 100644 index 00000000000..cb3567b5db2 --- /dev/null +++ b/spec/models/user_archived_message_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +describe UserArchivedMessage do + it 'Does not move archived muted messages back to inbox' do + user = Fabricate(:admin) + user2 = Fabricate(:admin) + + topic = create_post(user: user, + skip_validations: true, + target_usernames: [user2.username,user.username].join(","), + archetype: Archetype.private_message).topic + + UserArchivedMessage.archive!(user.id, topic.id) + expect(topic.message_archived?(user)).to eq(true) + + TopicUser.change(user.id, topic.id, notification_level: TopicUser.notification_levels[:muted]) + UserArchivedMessage.move_to_inbox!(user.id, topic.id) + expect(topic.message_archived?(user)).to eq(true) + end +end +