2016-09-24 03:00:46 +00:00
|
|
|
# frozen_string_literal: true
|
2016-09-21 17:22:40 +00:00
|
|
|
class Event < ApplicationRecord
|
2016-07-26 00:14:23 +00:00
|
|
|
KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze
|
2016-03-12 23:36:38 +00:00
|
|
|
|
2016-07-26 00:14:23 +00:00
|
|
|
# has_many :notifications, dependent: :destroy
|
2016-03-12 23:36:38 +00:00
|
|
|
belongs_to :eventable, polymorphic: true
|
|
|
|
belongs_to :map
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
scope :chronologically, -> { order('created_at asc') }
|
|
|
|
|
|
|
|
after_create :notify_webhooks!, if: :map
|
|
|
|
|
2016-07-26 00:14:23 +00:00
|
|
|
validates :kind, inclusion: { in: KINDS }
|
|
|
|
validates :eventable, presence: true
|
2016-03-12 23:36:38 +00:00
|
|
|
|
2016-07-26 00:14:23 +00:00
|
|
|
# def notify!(user)
|
2016-03-12 23:36:38 +00:00
|
|
|
# notifications.create!(user: user)
|
2016-07-26 00:14:23 +00:00
|
|
|
# end
|
2016-03-12 23:36:38 +00:00
|
|
|
|
|
|
|
def belongs_to?(this_user)
|
2016-07-26 00:14:23 +00:00
|
|
|
user_id == this_user.id
|
2016-03-12 23:36:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def notify_webhooks!
|
2016-07-26 00:14:23 +00:00
|
|
|
# group = self.discussion.group
|
|
|
|
map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
|
|
|
|
# group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
|
2016-03-12 23:36:38 +00:00
|
|
|
end
|
|
|
|
handle_asynchronously :notify_webhooks!
|
|
|
|
end
|