treat cable sub/unsub as joined/left map. fixes #1035 (#1047)

This commit is contained in:
Connor Turland 2017-01-25 15:32:13 -08:00 committed by GitHub
parent 696ff396b0
commit 8330ef9679
5 changed files with 24 additions and 7 deletions

View file

@ -3,7 +3,15 @@ class MapChannel < ApplicationCable::Channel
# Called when the consumer has successfully
# become a subscriber of this channel.
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]}"
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

View file

@ -106,9 +106,6 @@ class MapsController < ApplicationController
if params[:event] == 'conversation'
Events::ConversationStartedOnMap.publish!(@map, current_user)
valid_event = true
elsif params[:event] == 'user_presence'
Events::UserPresentOnMap.publish!(@map, current_user)
valid_event = true
end
respond_to do |format|

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
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
synapse_added_to_map synapse_removed_from_map
topic_updated synapse_updated).freeze

View 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

View file

@ -149,8 +149,6 @@ const Visualize = {
self.mGraph.graph.empty()
}
if (self.type === 'ForceDirected' && Active.Mapper) $.post('/maps/' + Active.Map.id + '/events/user_presence')
function runAnimation() {
Loading.hide()
// load JSON data, if it's not empty