lots of fixes

This commit is contained in:
Connor Turland 2017-02-11 04:47:21 +00:00
parent ce843c7ba0
commit b34264b138
8 changed files with 53 additions and 42 deletions

View file

@ -0,0 +1,13 @@
module MapMailerHelper
def access_approved_subject(map)
map.name + ' - access approved'
end
def access_request_subject(map)
map.name + ' - request to edit'
end
def invite_to_edit_subject(map)
map.name + ' - invited to edit'
end
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
module TopicMailerHelper
def added_to_map_subject(topic, map)
topic.name + ' was added to map ' + map.name
end
def connected_subject(topic)
'new synapse to topic ' + topic.name
end
end

View file

@ -1,31 +1,20 @@
# frozen_string_literal: true
class MapMailer < ApplicationMailer
include MapMailerHelper
default from: 'team@metamaps.cc'
def access_approved_subject(map)
map.name + ' - access approved'
end
def access_approved(request)
@request = request
@map = request.map
mail(to: request.user.email, subject: access_approved_subject(@map))
end
def access_request_subject(map)
map.name + ' - request to edit'
end
def access_request(request)
@request = request
@map = request.map
mail(to: @map.user.email, subject: access_request_subject(@map))
end
def invite_to_edit_subject(map)
map.name + ' - invited to edit'
end
def invite_to_edit(user_map)
@inviter = user_map.map.user
@map = user_map.map

View file

@ -1,21 +1,14 @@
# frozen_string_literal: true
class TopicMailer < ApplicationMailer
include TopicMailerHelper
default from: 'team@metamaps.cc'
def added_to_map_subject(topic, map)
topic.name + ' was added to map ' + map.name
end
def added_to_map(event, user)
@entity = event.eventable
@event = event
mail(to: user.email, subject: added_to_map_subject(@entity, event.map))
end
def connected_subject(topic)
'new synapse to topic ' + topic.name
end
def connected(synapse, topic, user)
@entity = topic
@event = synapse

View file

@ -29,11 +29,8 @@ class Mapping < ApplicationRecord
def after_created
if mappable_type == 'Topic'
meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
Events::TopicAddedToMap.publish!(mappable, map, user, meta)
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicAdded', topic: mappable.filtered, mapping_id: id
elsif mappable_type == 'Synapse'
Events::SynapseAddedToMap.publish!(mappable, map, user, meta)
ActionCable.server.broadcast(
'map_' + map.id.to_s,
type: 'synapseAdded',
@ -47,6 +44,12 @@ class Mapping < ApplicationRecord
def after_created_async
FollowService.follow(map, user, 'contributed')
if mappable_type == 'Topic'
meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
Events::TopicAddedToMap.publish!(mappable, map, user, meta)
elsif mappable_type == 'Synapse'
Events::SynapseAddedToMap.publish!(mappable, map, user, nil)
end
end
handle_asynchronously :after_created_async

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
class NotificationService
extend TopicMailerHelper
extend MapMailerHelper
# for strip_tags
include ActionView::Helpers::SanitizeHelper
@ -13,13 +15,13 @@ class NotificationService
def self.get_settings_for_event(entity, event_type, event)
case event_type
when TOPIC_ADDED_TO_MAP
subject = TopicMailer.added_to_map_subject(entity, event.map)
subject = added_to_map_subject(entity, event.map)
template = 'topic_mailer/added_to_map'
when TOPIC_CONNECTED_1
subject = TopicMailer.connected_subject(event.topic1)
subject = connected_subject(event.topic1)
template = 'topic_mailer/connected'
when TOPIC_CONNECTED_2
TopicMailer.connected_subject(event.topic2)
subject = connected_subject(event.topic2)
template = 'topic_mailer/connected'
end
@ -30,19 +32,19 @@ class NotificationService
return if follows.length == 0
settings = get_settings_for_event(entity, event_type, event)
# we'll prbly want to put the body into the actual loop so we can pass the current user in as a local
body = renderer.render(template: settings.template, locals: { entity: entity, event: event }, layout: false)
body = renderer.render(template: settings[:template], locals: { entity: entity, event: event }, layout: false)
follows.each{|follow|
# this handles email and in-app notifications, in the future, include push
follow.user.notify(settings.subject, body, event, false, event_type, (follow.user.emails_allowed && follow.email), event.user)
follow.user.notify(settings[:subject], body, event, false, event_type, (follow.user.emails_allowed && follow.email), event.user)
# push could be handled with Actioncable to send transient notifications to the UI
# the receipt from the notify call could be used to link to the full notification
}
end
def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
follows = entity.follows.joins(:follow_type).where.not(user_id: event.user.id)
follows = entity.follows.where.not(user_id: event.user.id)
if exclude_follows
if !exclude_follows.nil?
follows = follows.where.not(id: exclude_follows)
end
@ -57,19 +59,19 @@ class NotificationService
end
def self.access_request(request)
subject = MapMailer.access_request_subject(request.map)
subject = access_request_subject(request.map)
body = renderer.render(template: 'map_mailer/access_request', locals: { map: request.map, request: request }, layout: false)
request.map.user.notify(subject, body, request, false, MAP_ACCESS_REQUEST, true, request.user)
end
def self.access_approved(request)
subject = MapMailer.access_approved_subject(request.map)
subject = access_approved_subject(request.map)
body = renderer.render(template: 'map_mailer/access_approved', locals: { map: request.map }, layout: false)
request.user.notify(subject, body, request, false, MAP_ACCESS_APPROVED, true, request.map.user)
end
def self.invite_to_edit(user_map)
subject = MapMailer.invite_to_edit_subject(user_map.map)
subject = invite_to_edit_subject(user_map.map)
body = renderer.render(template: 'map_mailer/invite_to_edit', locals: { map: user_map.map, inviter: user_map.map.user }, layout: false)
user_map.user.notify(subject, body, user_map, false, MAP_INVITE_TO_EDIT, true, user_map.map.user)
end

View file

@ -7,7 +7,7 @@
<h2 class="title">Notifications</h4>
</header>
<ul class="notifications">
<% blacklist = [MAILBOXER_CODE_ACCESS_REQUEST, MAILBOXER_CODE_ACCESS_APPROVED, MAILBOXER_CODE_INVITE_TO_EDIT] %>
<% blacklist = [MAP_ACCESS_REQUEST, MAP_ACCESS_APPROVED, MAP_INVITE_TO_EDIT] %>
<% notifications = @notifications.to_a.delete_if{|n| blacklist.include?(n.notification_code) && (n.notified_object.nil? || n.notified_object.map.nil?) }%>
<% notifications.each do |notification| %>
<% receipt = @receipts.find_by(notification_id: notification.id) %>
@ -22,28 +22,29 @@
case notification.notification_code
when MAP_ACCESS_APPROVED
map = notification.notified_object.map
'granted your request to edit map <span class="in-bold">' + map.name + '</span>'
output = 'granted your request to edit map <span class="in-bold">' + map.name + '</span>'
when MAP_ACCESS_REQUEST
map = notification.notified_object.map
'wants permission to map with you on <span class="in-bold">' + map.name + '</span>&nbsp;&nbsp;<div class="action">Offer a response</div>'
output = 'wants permission to map with you on <span class="in-bold">' + map.name + '</span>&nbsp;&nbsp;<div class="action">Offer a response</div>'
when MAP_INVITE_TO_EDIT
map = notification.notified_object.map
'gave you edit access to map <span class="in-bold">' + map.name + '</span>'
output = 'gave you edit access to map <span class="in-bold">' + map.name + '</span>'
when TOPIC_ADDED_TO_MAP
topic = notification.notified_object.eventable
map = notification.notified_object.map
'added topic <span class="in-bold">' + topic.name + '</span> to map <span class="in-bold">' + map.name + '</span>'
output = 'added topic <span class="in-bold">' + topic.name + '</span> to map <span class="in-bold">' + map.name + '</span>'
when TOPIC_CONNECTED_1
topic1 = notification.notified_object.topic1
topic2 = notification.notified_object.topic2
'connected <span class="in-bold">' + topic1.name + '</span> to <span class="in-bold">' + topic2.name + '</span>'
output = 'connected <span class="in-bold">' + topic1.name + '</span> to <span class="in-bold">' + topic2.name + '</span>'
when TOPIC_CONNECTED_2
topic1 = notification.notified_object.topic1
topic2 = notification.notified_object.topic2
'connected <span class="in-bold">' + topic2.name + '</span> to <span class="in-bold">' + topic1.name + '</span>'
output = 'connected <span class="in-bold">' + topic2.name + '</span> to <span class="in-bold">' + topic1.name + '</span>'
when MESSAGE_FROM_DEVS
notification.subject
output = notification.subject
end
raw output
%>
</div>
<% end %>

View file

@ -8,7 +8,7 @@
connected topic <span style="font-weight: bold"><%= topic1.name %></span>
to topic <span style="font-weight: bold"><%= topic2.name %></span>
<% if synapse.desc.length > 0 %>
with the description "<%= event.desc %>".
with the description "<%= synapse.desc %>".
<% end %>
</p>