added an event for conversations starting (#547)

* added an event for conversations starting

* switch to post
This commit is contained in:
Connor Turland 2016-04-14 14:35:28 -04:00
parent 317f0c245e
commit 7bb7f345f1
8 changed files with 75 additions and 6 deletions

View file

@ -2270,6 +2270,7 @@ Metamaps.Realtime = {
invited: Metamaps.Active.Mapper.id, invited: Metamaps.Active.Mapper.id,
inviter: userid inviter: userid
}); });
$.post('/maps/' + Metamaps.Active.Map.id + '/events/conversation');
self.joinCall(); self.joinCall();
Metamaps.GlobalUI.clearNotify(); Metamaps.GlobalUI.clearNotify();
}, },

View file

@ -1,7 +1,7 @@
class MapsController < ApplicationController class MapsController < ApplicationController
before_action :require_user, only: [:create, :update, :screenshot, :destroy] before_action :require_user, only: [:create, :update, :screenshot, :events, :destroy]
after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :usermaps] after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :usermaps, :events]
after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :usermaps] after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :usermaps]
respond_to :html, :json, :csv respond_to :html, :json, :csv
@ -102,6 +102,24 @@ class MapsController < ApplicationController
end end
end end
# POST maps/:id/events/:event
def events
map = Map.find(params[:id])
authorize map
valid_event = false
if params[:event] == 'conversation'
Events::ConversationStartedOnMap.publish!(map, current_user)
valid_event = true
end
respond_to do |format|
format.json {
head :ok if valid_event
head :bad_request if not valid_event
}
end
end
# GET maps/:id/contains # GET maps/:id/contains
def contains def contains

View file

@ -1,5 +1,5 @@
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
KINDS = %w[topic_added_to_map synapse_added_to_map] KINDS = %w[conversation_started_on_map topic_added_to_map synapse_added_to_map]
#has_many :notifications, dependent: :destroy #has_many :notifications, dependent: :destroy
belongs_to :eventable, polymorphic: true belongs_to :eventable, polymorphic: true

View file

@ -0,0 +1,18 @@
class Events::ConversationStartedOnMap < Event
#after_create :notify_users!
def self.publish!(map, user)
create!(kind: "conversation_started_on_map",
eventable: map,
map: map,
user: user)
end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end

View file

@ -37,7 +37,7 @@ Webhooks::Slack::Base = Struct.new(:event) do
#end #end
def view_map_on_metamaps(text = nil) def view_map_on_metamaps(text = nil)
"<#{map_url(eventable.map)}|#{text || eventable.map.name}>" "<#{map_url(event.map)}|#{text || event.map.name}>"
end end
#def view_discussion_on_loomio(params = {}) #def view_discussion_on_loomio(params = {})

View file

@ -0,0 +1,27 @@
class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base
def text
"There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}"
end
# todo: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n"
end
def attachment_title
"" #proposal_link(eventable)
end
def attachment_text
"" # "#{eventable.description}\n"
end
def attachment_fields
[{
title: "nothing",
value: "nothing"
}] #[motion_vote_field]
end
end

View file

@ -35,6 +35,10 @@ class MapPolicy < ApplicationPolicy
show? show?
end end
def events?
show?
end
def contains? def contains?
show? show?
end end

View file

@ -37,14 +37,15 @@ Metamaps::Application.routes.draw do
resources :maps, except: [:index, :new, :edit] resources :maps, except: [:index, :new, :edit]
get 'maps/:id/export', to: 'maps#export' get 'maps/:id/export', to: 'maps#export'
post 'maps/:id/events/:event', to: 'maps#events'
get 'maps/:id/contains', to: 'maps#contains', as: :contains
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
get 'explore/active', to: 'maps#activemaps' get 'explore/active', to: 'maps#activemaps'
get 'explore/featured', to: 'maps#featuredmaps' get 'explore/featured', to: 'maps#featuredmaps'
get 'explore/mine', to: 'maps#mymaps' get 'explore/mine', to: 'maps#mymaps'
get 'explore/mapper/:id', to: 'maps#usermaps' get 'explore/mapper/:id', to: 'maps#usermaps'
get 'maps/:id/contains', to: 'maps#contains', as: :contains
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions