parent
696ff396b0
commit
8330ef9679
5 changed files with 24 additions and 7 deletions
|
@ -3,7 +3,15 @@ class MapChannel < ApplicationCable::Channel
|
||||||
# Called when the consumer has successfully
|
# Called when the consumer has successfully
|
||||||
# become a subscriber of this channel.
|
# become a subscriber of this channel.
|
||||||
def subscribed
|
def subscribed
|
||||||
return unless Pundit.policy(current_user, Map.find(params[:id])).show?
|
map = Map.find(params[:id])
|
||||||
|
return unless Pundit.policy(current_user, map).show?
|
||||||
stream_from "map_#{params[:id]}"
|
stream_from "map_#{params[:id]}"
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,9 +106,6 @@ class MapsController < ApplicationController
|
||||||
if params[:event] == 'conversation'
|
if params[:event] == 'conversation'
|
||||||
Events::ConversationStartedOnMap.publish!(@map, current_user)
|
Events::ConversationStartedOnMap.publish!(@map, current_user)
|
||||||
valid_event = true
|
valid_event = true
|
||||||
elsif params[:event] == 'user_presence'
|
|
||||||
Events::UserPresentOnMap.publish!(@map, current_user)
|
|
||||||
valid_event = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class Event < ApplicationRecord
|
class Event < ApplicationRecord
|
||||||
KINDS = %w(user_present_on_map conversation_started_on_map
|
KINDS = %w(user_present_on_map user_not_present_on_map
|
||||||
|
conversation_started_on_map
|
||||||
topic_added_to_map topic_moved_on_map topic_removed_from_map
|
topic_added_to_map topic_moved_on_map topic_removed_from_map
|
||||||
synapse_added_to_map synapse_removed_from_map
|
synapse_added_to_map synapse_removed_from_map
|
||||||
topic_updated synapse_updated).freeze
|
topic_updated synapse_updated).freeze
|
||||||
|
|
13
app/models/events/user_not_present_on_map.rB
Normal file
13
app/models/events/user_not_present_on_map.rB
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
module Events
|
||||||
|
class UserNotPresentOnMap < Event
|
||||||
|
# after_create :notify_users!
|
||||||
|
|
||||||
|
def self.publish!(map, user)
|
||||||
|
create!(kind: 'user_not_present_on_map',
|
||||||
|
eventable: map,
|
||||||
|
map: map,
|
||||||
|
user: user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -149,8 +149,6 @@ const Visualize = {
|
||||||
self.mGraph.graph.empty()
|
self.mGraph.graph.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.type === 'ForceDirected' && Active.Mapper) $.post('/maps/' + Active.Map.id + '/events/user_presence')
|
|
||||||
|
|
||||||
function runAnimation() {
|
function runAnimation() {
|
||||||
Loading.hide()
|
Loading.hide()
|
||||||
// load JSON data, if it's not empty
|
// load JSON data, if it's not empty
|
||||||
|
|
Loading…
Add table
Reference in a new issue