mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
f66007ec83
There are certain design decisions that were made in this commit. Private messages implements its own version of topic tracking state because there are significant differences between regular and private_message topics. Regular topics have to track categories and tags while private messages do not. It is much easier to design the new topic tracking state if we maintain two different classes, instead of trying to mash this two worlds together. One MessageBus channel per user and one MessageBus channel per group. This allows each user and each group to have their own channel backlog instead of having one global channel which requires the client to filter away unrelated messages.
54 lines
1.6 KiB
Ruby
54 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe UserArchivedMessage do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:user_2) { Fabricate(:user) }
|
|
|
|
fab!(:private_message) do
|
|
create_post(
|
|
user: user,
|
|
skip_validations: true,
|
|
target_usernames: [user_2.username, user.username].join(","),
|
|
archetype: Archetype.private_message
|
|
).topic
|
|
end
|
|
|
|
describe '.move_to_inbox!' do
|
|
it 'moves topic back to inbox correctly' do
|
|
UserArchivedMessage.archive!(user.id, private_message)
|
|
|
|
expect do
|
|
messages = MessageBus.track_publish(PrivateMessageTopicTrackingState.user_channel(user.id)) do
|
|
UserArchivedMessage.move_to_inbox!(user.id, private_message)
|
|
end
|
|
|
|
expect(messages.present?).to eq(true)
|
|
end.to change { private_message.message_archived?(user) }.from(true).to(false)
|
|
end
|
|
|
|
it 'does not move archived muted messages back to inbox' do
|
|
UserArchivedMessage.archive!(user.id, private_message)
|
|
|
|
expect(private_message.message_archived?(user)).to eq(true)
|
|
|
|
TopicUser.change(user.id, private_message.id, notification_level: TopicUser.notification_levels[:muted])
|
|
UserArchivedMessage.move_to_inbox!(user.id, private_message)
|
|
|
|
expect(private_message.message_archived?(user)).to eq(true)
|
|
end
|
|
end
|
|
|
|
describe '.archive' do
|
|
it 'archives message correctly' do
|
|
messages = MessageBus.track_publish(PrivateMessageTopicTrackingState.user_channel(user.id)) do
|
|
UserArchivedMessage.archive!(user.id, private_message)
|
|
end
|
|
|
|
expect(messages.present?).to eq(true)
|
|
end
|
|
end
|
|
|
|
end
|