diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index c9415cfa..70252ea8 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -2270,6 +2270,7 @@ Metamaps.Realtime = { invited: Metamaps.Active.Mapper.id, inviter: userid }); + $.post('/maps/' + Metamaps.Active.Map.id + '/events/conversation'); self.joinCall(); Metamaps.GlobalUI.clearNotify(); }, diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 131e5959..82b87ffb 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,7 +1,7 @@ class MapsController < ApplicationController - before_action :require_user, only: [:create, :update, :screenshot, :destroy] - after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :usermaps] + before_action :require_user, only: [:create, :update, :screenshot, :events, :destroy] + after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :usermaps, :events] after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :usermaps] respond_to :html, :json, :csv @@ -102,6 +102,24 @@ class MapsController < ApplicationController 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 def contains diff --git a/app/models/event.rb b/app/models/event.rb index 6dfb7e26..0ad350ea 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,5 +1,5 @@ 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 belongs_to :eventable, polymorphic: true diff --git a/app/models/events/conversation_started_on_map.rb b/app/models/events/conversation_started_on_map.rb new file mode 100644 index 00000000..f8a0ca2c --- /dev/null +++ b/app/models/events/conversation_started_on_map.rb @@ -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 diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 98503916..3337e320 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -37,7 +37,7 @@ Webhooks::Slack::Base = Struct.new(:event) do #end def view_map_on_metamaps(text = nil) - "<#{map_url(eventable.map)}|#{text || eventable.map.name}>" + "<#{map_url(event.map)}|#{text || event.map.name}>" end #def view_discussion_on_loomio(params = {}) diff --git a/app/models/webhooks/slack/conversation_started_on_map.rb b/app/models/webhooks/slack/conversation_started_on_map.rb new file mode 100644 index 00000000..489559c7 --- /dev/null +++ b/app/models/webhooks/slack/conversation_started_on_map.rb @@ -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 diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 5b4bbfa9..b1ece0e3 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -35,6 +35,10 @@ class MapPolicy < ApplicationPolicy show? end + def events? + show? + end + def contains? show? end diff --git a/config/routes.rb b/config/routes.rb index a9f82d9c..345547f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,14 +37,15 @@ Metamaps::Application.routes.draw do resources :maps, except: [:index, :new, :edit] 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/featured', to: 'maps#featuredmaps' get 'explore/mine', to: 'maps#mymaps' 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