2012-10-26 10:04:52 +00:00
|
|
|
class Mapping < ActiveRecord::Base
|
|
|
|
|
2013-01-01 22:45:35 +00:00
|
|
|
belongs_to :topic, :class_name => "Topic", :foreign_key => "topic_id"
|
2012-10-26 10:04:52 +00:00
|
|
|
belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id"
|
|
|
|
belongs_to :map, :class_name => "Map", :foreign_key => "map_id"
|
|
|
|
|
|
|
|
belongs_to :user
|
2014-08-12 16:01:01 +00:00
|
|
|
|
|
|
|
def user_name
|
|
|
|
self.user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_image
|
|
|
|
self.user.image.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json(options={})
|
|
|
|
super(:methods =>[:user_name, :user_image])
|
|
|
|
end
|
2013-04-26 04:07:29 +00:00
|
|
|
|
|
|
|
# sends push updates through redis to websockets for realtime updates
|
|
|
|
def message action, origin_user_id
|
|
|
|
if self.category == "Topic"
|
|
|
|
|
|
|
|
return if self.topic.permission == "private" and action == "create"
|
|
|
|
|
|
|
|
msg = { origin: origin_user_id,
|
|
|
|
mapid: self.map.id,
|
|
|
|
resource: self.category,
|
|
|
|
action: action,
|
|
|
|
id: self.topic.id,
|
|
|
|
obj: self.topic.selfonmap_as_json(self.map.id).html_safe }
|
|
|
|
elsif self.category == "Synapse"
|
|
|
|
|
|
|
|
return if self.synapse.permission == "private" and action == "create"
|
|
|
|
|
|
|
|
msg = { origin: origin_user_id,
|
|
|
|
mapid: self.map.id,
|
|
|
|
resource: self.category,
|
|
|
|
action: action,
|
|
|
|
id: self.synapse.id,
|
|
|
|
obj: self.synapse.self_as_json.html_safe }
|
|
|
|
end
|
|
|
|
$redis.publish 'maps', msg.to_json
|
|
|
|
end
|
|
|
|
|
2012-10-26 10:04:52 +00:00
|
|
|
end
|