FIX: Publish live messages to both team inbox and archive on update.
This commit is contained in:
parent
5169be6080
commit
3045c589f6
|
@ -7,7 +7,7 @@ class GroupArchivedMessage < ActiveRecord::Base
|
|||
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
||||
trigger(:move_to_inbox, group_id, topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, group_ids: [group_id])
|
||||
publish_topic_tracking_state(topic, false)
|
||||
publish_topic_tracking_state(topic)
|
||||
end
|
||||
|
||||
def self.archive!(group_id, topic)
|
||||
|
@ -16,7 +16,7 @@ class GroupArchivedMessage < ActiveRecord::Base
|
|||
GroupArchivedMessage.create!(group_id: group_id, topic_id: topic_id)
|
||||
trigger(:archive_message, group_id, topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, group_ids: [group_id])
|
||||
publish_topic_tracking_state(topic, true)
|
||||
publish_topic_tracking_state(topic)
|
||||
end
|
||||
|
||||
def self.trigger(event, group_id, topic_id)
|
||||
|
@ -29,9 +29,9 @@ class GroupArchivedMessage < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
def self.publish_topic_tracking_state(topic, archived)
|
||||
def self.publish_topic_tracking_state(topic)
|
||||
TopicTrackingState.publish_private_message(
|
||||
topic, group_archived: archived
|
||||
topic, group_archive: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -246,7 +246,7 @@ SQL
|
|||
sql
|
||||
end
|
||||
|
||||
def self.publish_private_message(topic, user_id: user_id, user_archive: false, post: nil, group_archived: false)
|
||||
def self.publish_private_message(topic, user_id: user_id, user_archive: false, post: nil, group_archive: false)
|
||||
return unless topic.private_message?
|
||||
channels = {}
|
||||
|
||||
|
@ -266,9 +266,10 @@ SQL
|
|||
end
|
||||
else
|
||||
topic.allowed_groups.each do |group|
|
||||
channel = "/private-messages/group/#{group.name.downcase}"
|
||||
channel = "#{channel}/archive" if group_archived
|
||||
channels[channel] = group.users.pluck(:id)
|
||||
group_channels = []
|
||||
group_channels << "/private-messages/group/#{group.name.downcase}"
|
||||
group_channels << "#{group_channels.first}/archive" if group_archive
|
||||
group_channels.each { |channel| channels[channel] = group.users.pluck(:id) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -108,6 +108,8 @@ describe TopicTrackingState do
|
|||
)
|
||||
end
|
||||
|
||||
expect(messages.count).to eq(2)
|
||||
|
||||
[group1, group2].each do |group|
|
||||
message = messages.find do |message|
|
||||
message.channel == "/private-messages/group/#{group.name}"
|
||||
|
@ -117,6 +119,35 @@ describe TopicTrackingState do
|
|||
expect(message.user_ids).to eq(group.users.map(&:id))
|
||||
end
|
||||
end
|
||||
|
||||
describe "archiving topic" do
|
||||
it "should publish the right message" do
|
||||
messages = MessageBus.track_publish do
|
||||
TopicTrackingState.publish_private_message(
|
||||
private_message_topic,
|
||||
group_archive: true
|
||||
)
|
||||
end
|
||||
|
||||
expect(messages.count).to eq(4)
|
||||
|
||||
[group1, group2].each do |group|
|
||||
group_channel = "/private-messages/group/#{group.name}"
|
||||
|
||||
[
|
||||
group_channel,
|
||||
"#{group_channel}/archive"
|
||||
].each do |channel|
|
||||
message = messages.find do |message|
|
||||
message.channel == "/private-messages/group/#{group.name}"
|
||||
end
|
||||
|
||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||
expect(message.user_ids).to eq(group.users.map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'topic with new post' do
|
||||
|
|
Loading…
Reference in New Issue