FEATURE: don't move muted messages back into inbox

This commit is contained in:
Sam Saffron 2016-02-15 10:56:39 +11:00
parent 2c0b36cb72
commit 8e9a8472f4
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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