cleanup cruft and include slack notifs
This commit is contained in:
parent
f8e7bf6d31
commit
24aeebedf7
13 changed files with 32 additions and 136 deletions
|
@ -4,7 +4,6 @@ class Event < ApplicationRecord
|
|||
topic_added_to_map topic_moved_on_map topic_removed_from_map
|
||||
synapse_added_to_map synapse_removed_from_map).freeze
|
||||
|
||||
# has_many :notifications, dependent: :destroy
|
||||
belongs_to :eventable, polymorphic: true
|
||||
belongs_to :map
|
||||
belongs_to :user
|
||||
|
@ -16,18 +15,12 @@ class Event < ApplicationRecord
|
|||
validates :kind, inclusion: { in: KINDS }
|
||||
validates :eventable, presence: true
|
||||
|
||||
# def notify!(user)
|
||||
# notifications.create!(user: user)
|
||||
# end
|
||||
|
||||
def belongs_to?(this_user)
|
||||
user_id == this_user.id
|
||||
end
|
||||
|
||||
def notify_webhooks!
|
||||
# group = self.discussion.group
|
||||
map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
|
||||
# group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
|
||||
end
|
||||
handle_asynchronously :notify_webhooks!
|
||||
end
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
class Events::SynapseRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(mapping, user)
|
||||
def self.publish!(synapse, map, user)
|
||||
create!(kind: 'synapse_removed_from_map',
|
||||
eventable: mapping,
|
||||
map: mapping.map,
|
||||
eventable: synapse,
|
||||
map: map,
|
||||
user: user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
class Events::TopicRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(mapping, user)
|
||||
def self.publish!(topic, map, user)
|
||||
create!(kind: 'topic_removed_from_map',
|
||||
eventable: mapping,
|
||||
map: mapping.map,
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,9 +52,9 @@ class Mapping < ApplicationRecord
|
|||
end
|
||||
|
||||
if mappable_type == 'Topic'
|
||||
Events::TopicRemovedFromMap.publish!(self, user)
|
||||
Events::TopicRemovedFromMap.publish!(mappable, map, user)
|
||||
elsif mappable_type == 'Synapse'
|
||||
Events::SynapseRemovedFromMap.publish!(self, user)
|
||||
Events::SynapseRemovedFromMap.publish!(mappable, map, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,45 +18,14 @@ Webhooks::Slack::Base = Struct.new(:webhook, :event) do
|
|||
webhook.channel
|
||||
end
|
||||
|
||||
def attachments
|
||||
[{
|
||||
title: attachment_title,
|
||||
text: attachment_text,
|
||||
fields: attachment_fields,
|
||||
fallback: attachment_fallback
|
||||
}]
|
||||
end
|
||||
|
||||
alias_method :read_attribute_for_serialization, :send
|
||||
|
||||
private
|
||||
|
||||
# def motion_vote_field
|
||||
# {
|
||||
# title: "Vote on this proposal",
|
||||
# value: "#{proposal_link(eventable, "yes")} · " +
|
||||
# "#{proposal_link(eventable, "abstain")} · " +
|
||||
# "#{proposal_link(eventable, "no")} · " +
|
||||
# "#{proposal_link(eventable, "block")}"
|
||||
# }
|
||||
# end
|
||||
|
||||
def view_map_on_metamaps(text = nil)
|
||||
"<#{map_url(event.map)}|#{text || event.map.name}>"
|
||||
end
|
||||
|
||||
# def view_discussion_on_loomio(params = {})
|
||||
# { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) }
|
||||
# end
|
||||
|
||||
# def proposal_link(proposal, position = nil)
|
||||
# discussion_link position || proposal.name, { proposal: proposal.key, position: position }
|
||||
# end
|
||||
|
||||
# def discussion_link(text = nil, params = {})
|
||||
# "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>"
|
||||
# end
|
||||
|
||||
def eventable
|
||||
@eventable ||= event.eventable
|
||||
end
|
||||
|
@ -65,12 +34,3 @@ Webhooks::Slack::Base = Struct.new(:webhook, :event) do
|
|||
@author ||= eventable.author
|
||||
end
|
||||
end
|
||||
|
||||
# webhooks:
|
||||
# slack:
|
||||
# motion_closed: "*%{name}* has closed"
|
||||
# motion_closing_soon: "*%{name}* has a proposal closing in 24 hours"
|
||||
# motion_outcome_created: "*%{author}* published an outcome in *%{name}*"
|
||||
# motion_outcome_updated: "*%{author}* updated the outcome for *%{name}*"
|
||||
# new_motion: "*%{author}* started a new proposal in *%{name}*"
|
||||
# view_it_on_loomio: "View it on Loomio"
|
||||
|
|
|
@ -3,24 +3,4 @@ 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
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base
|
||||
def text
|
||||
"\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps}*"
|
||||
end
|
||||
|
||||
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]
|
||||
connector = eventable.mappable.desc.empty? ? '->' : eventable.mappable.desc
|
||||
"\"*#{eventable.mappable.topic1.name}* #{connector} *#{eventable.mappable.topic2.name}*\" was added as a connection by *#{event.user.name}* to the map *#{view_map_on_metamaps}*"
|
||||
end
|
||||
end
|
||||
|
|
8
app/models/webhooks/slack/synapse_removed_from_map.rb
Normal file
8
app/models/webhooks/slack/synapse_removed_from_map.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
class Webhooks::Slack::SynapseRemovedFromMap < Webhooks::Slack::Base
|
||||
def text
|
||||
connector = eventable.desc.empty? ? '->' : eventable.desc
|
||||
# todo express correct directionality of arrows when desc is empty
|
||||
"\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\" was removed by *#{event.user.name}* as a connection from the map *#{view_map_on_metamaps}*"
|
||||
end
|
||||
end
|
|
@ -1,26 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base
|
||||
def text
|
||||
"New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps}*"
|
||||
"*#{eventable.mappable.name}* was added by *#{event.user.name}* to the map *#{view_map_on_metamaps}*"
|
||||
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
|
||||
|
|
6
app/models/webhooks/slack/topic_moved_on_map.rb
Normal file
6
app/models/webhooks/slack/topic_moved_on_map.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
class Webhooks::Slack::TopicMovedOnMap < Webhooks::Slack::Base
|
||||
def text
|
||||
"*#{eventable.mappable.name}* was moved by *#{event.user.name}* on the map *#{view_map_on_metamaps}*"
|
||||
end
|
||||
end
|
6
app/models/webhooks/slack/topic_removed_from_map.rb
Normal file
6
app/models/webhooks/slack/topic_removed_from_map.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
class Webhooks::Slack::TopicRemovedFromMap < Webhooks::Slack::Base
|
||||
def text
|
||||
"*#{eventable.name}* was removed by *#{event.user.name}* from the map *#{view_map_on_metamaps}*"
|
||||
end
|
||||
end
|
|
@ -3,24 +3,4 @@ class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base
|
|||
def text
|
||||
"Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}"
|
||||
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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
class WebhookSerializer < ActiveModel::Serializer
|
||||
attributes :text, :username, :icon_url # , :attachments
|
||||
attributes :text, :username, :icon_url
|
||||
attribute :channel, if: :has_channel?
|
||||
|
||||
def has_channel?
|
||||
|
|
Loading…
Reference in a new issue