2017-01-24 00:30:13 +00:00
|
|
|
# frozen_string_literal: true
|
2017-11-06 16:15:18 +00:00
|
|
|
|
2017-01-03 21:12:58 +00:00
|
|
|
class MapChannel < ApplicationCable::Channel
|
|
|
|
# Called when the consumer has successfully
|
|
|
|
# become a subscriber of this channel.
|
|
|
|
def subscribed
|
2017-01-25 23:32:13 +00:00
|
|
|
map = Map.find(params[:id])
|
|
|
|
return unless Pundit.policy(current_user, map).show?
|
2017-01-03 21:12:58 +00:00
|
|
|
stream_from "map_#{params[:id]}"
|
2017-01-25 23:32:13 +00:00
|
|
|
Events::UserPresentOnMap.publish!(map, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribed
|
|
|
|
map = Map.find(params[:id])
|
|
|
|
return unless Pundit.policy(current_user, map).show?
|
|
|
|
Events::UserNotPresentOnMap.publish!(map, current_user)
|
2017-01-03 21:12:58 +00:00
|
|
|
end
|
|
|
|
end
|