2015-12-22 18:09:17 -06:00
|
|
|
class GroupArchivedMessage < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :topic
|
2016-02-07 06:39:07 -06:00
|
|
|
|
2018-03-06 00:38:43 -06:00
|
|
|
def self.move_to_inbox!(group_id, topic)
|
|
|
|
topic_id = topic.id
|
2016-02-07 06:39:07 -06:00
|
|
|
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
2017-02-28 08:56:41 -06:00
|
|
|
trigger(:move_to_inbox, group_id, topic_id)
|
2017-07-27 20:20:09 -05:00
|
|
|
MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, group_ids: [group_id])
|
2018-03-07 00:01:20 -06:00
|
|
|
publish_topic_tracking_state(topic)
|
2016-02-07 06:39:07 -06:00
|
|
|
end
|
|
|
|
|
2018-03-06 00:38:43 -06:00
|
|
|
def self.archive!(group_id, topic)
|
|
|
|
topic_id = topic.id
|
2016-02-07 06:39:07 -06:00
|
|
|
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
|
|
|
GroupArchivedMessage.create!(group_id: group_id, topic_id: topic_id)
|
2017-02-28 08:56:41 -06:00
|
|
|
trigger(:archive_message, group_id, topic_id)
|
2017-07-27 20:20:09 -05:00
|
|
|
MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, group_ids: [group_id])
|
2018-03-07 00:01:20 -06:00
|
|
|
publish_topic_tracking_state(topic)
|
2016-02-07 06:39:07 -06:00
|
|
|
end
|
|
|
|
|
2017-02-28 08:56:41 -06:00
|
|
|
def self.trigger(event, group_id, topic_id)
|
|
|
|
group = Group.find_by(id: group_id)
|
|
|
|
topic = Topic.find_by(id: topic_id)
|
|
|
|
if group && topic
|
2017-07-27 20:20:09 -05:00
|
|
|
DiscourseEvent.trigger(event, group: group, topic: topic)
|
2017-02-28 08:56:41 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-06 00:38:43 -06:00
|
|
|
private
|
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
def self.publish_topic_tracking_state(topic)
|
|
|
|
TopicTrackingState.publish_private_message(
|
|
|
|
topic, group_archive: true
|
|
|
|
)
|
|
|
|
end
|
2015-12-22 18:09:17 -06:00
|
|
|
end
|
2016-01-11 00:30:56 -06:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: group_archived_messages
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# group_id :integer not null
|
|
|
|
# topic_id :integer not null
|
2018-02-20 00:28:58 -06:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2016-01-11 00:30:56 -06:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_group_archived_messages_on_group_id_and_topic_id (group_id,topic_id) UNIQUE
|
|
|
|
#
|