FEATURE: move_to_inbox and archive_message events
This commit is contained in:
parent
3f5d8b8000
commit
ffd8fa7481
|
@ -4,15 +4,26 @@ class GroupArchivedMessage < ActiveRecord::Base
|
|||
|
||||
def self.move_to_inbox!(group_id, topic_id)
|
||||
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])
|
||||
end
|
||||
|
||||
def self.archive!(group_id, topic_id)
|
||||
GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all
|
||||
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])
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
DiscourseEvent.trigger(event, {group: group, topic: topic})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -10,14 +10,24 @@ class UserArchivedMessage < ActiveRecord::Base
|
|||
).exists?)
|
||||
|
||||
UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all
|
||||
trigger(:move_to_inbox, user_id, topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, user_ids: [user_id])
|
||||
end
|
||||
|
||||
def self.archive!(user_id, topic_id)
|
||||
UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all
|
||||
UserArchivedMessage.create!(user_id: user_id, topic_id: topic_id)
|
||||
trigger(:archive_message, user_id, topic_id)
|
||||
MessageBus.publish("/topic/#{topic_id}", {type: "archived"}, user_ids: [user_id])
|
||||
end
|
||||
|
||||
def self.trigger(event, user_id, topic_id)
|
||||
user = User.find_by(id: user_id)
|
||||
topic = Topic.find_by(id: topic_id)
|
||||
if user && topic
|
||||
DiscourseEvent.trigger(event, {user: user, topic: topic})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
Loading…
Reference in New Issue