lots of fixes
This commit is contained in:
parent
ce843c7ba0
commit
b34264b138
8 changed files with 53 additions and 42 deletions
13
app/helpers/map_mailer_helper.rb
Normal file
13
app/helpers/map_mailer_helper.rb
Normal 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
|
10
app/helpers/topic_mailer_helper.rb
Normal file
10
app/helpers/topic_mailer_helper.rb
Normal 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
|
|
@ -1,31 +1,20 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class MapMailer < ApplicationMailer
|
class MapMailer < ApplicationMailer
|
||||||
|
include MapMailerHelper
|
||||||
default from: 'team@metamaps.cc'
|
default from: 'team@metamaps.cc'
|
||||||
|
|
||||||
def access_approved_subject(map)
|
|
||||||
map.name + ' - access approved'
|
|
||||||
end
|
|
||||||
|
|
||||||
def access_approved(request)
|
def access_approved(request)
|
||||||
@request = request
|
@request = request
|
||||||
@map = request.map
|
@map = request.map
|
||||||
mail(to: request.user.email, subject: access_approved_subject(@map))
|
mail(to: request.user.email, subject: access_approved_subject(@map))
|
||||||
end
|
end
|
||||||
|
|
||||||
def access_request_subject(map)
|
|
||||||
map.name + ' - request to edit'
|
|
||||||
end
|
|
||||||
|
|
||||||
def access_request(request)
|
def access_request(request)
|
||||||
@request = request
|
@request = request
|
||||||
@map = request.map
|
@map = request.map
|
||||||
mail(to: @map.user.email, subject: access_request_subject(@map))
|
mail(to: @map.user.email, subject: access_request_subject(@map))
|
||||||
end
|
end
|
||||||
|
|
||||||
def invite_to_edit_subject(map)
|
|
||||||
map.name + ' - invited to edit'
|
|
||||||
end
|
|
||||||
|
|
||||||
def invite_to_edit(user_map)
|
def invite_to_edit(user_map)
|
||||||
@inviter = user_map.map.user
|
@inviter = user_map.map.user
|
||||||
@map = user_map.map
|
@map = user_map.map
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class TopicMailer < ApplicationMailer
|
class TopicMailer < ApplicationMailer
|
||||||
|
include TopicMailerHelper
|
||||||
default from: 'team@metamaps.cc'
|
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)
|
def added_to_map(event, user)
|
||||||
@entity = event.eventable
|
@entity = event.eventable
|
||||||
@event = event
|
@event = event
|
||||||
mail(to: user.email, subject: added_to_map_subject(@entity, event.map))
|
mail(to: user.email, subject: added_to_map_subject(@entity, event.map))
|
||||||
end
|
end
|
||||||
|
|
||||||
def connected_subject(topic)
|
|
||||||
'new synapse to topic ' + topic.name
|
|
||||||
end
|
|
||||||
|
|
||||||
def connected(synapse, topic, user)
|
def connected(synapse, topic, user)
|
||||||
@entity = topic
|
@entity = topic
|
||||||
@event = synapse
|
@event = synapse
|
||||||
|
|
|
@ -29,11 +29,8 @@ class Mapping < ApplicationRecord
|
||||||
|
|
||||||
def after_created
|
def after_created
|
||||||
if mappable_type == 'Topic'
|
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
|
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicAdded', topic: mappable.filtered, mapping_id: id
|
||||||
elsif mappable_type == 'Synapse'
|
elsif mappable_type == 'Synapse'
|
||||||
Events::SynapseAddedToMap.publish!(mappable, map, user, meta)
|
|
||||||
ActionCable.server.broadcast(
|
ActionCable.server.broadcast(
|
||||||
'map_' + map.id.to_s,
|
'map_' + map.id.to_s,
|
||||||
type: 'synapseAdded',
|
type: 'synapseAdded',
|
||||||
|
@ -47,6 +44,12 @@ class Mapping < ApplicationRecord
|
||||||
|
|
||||||
def after_created_async
|
def after_created_async
|
||||||
FollowService.follow(map, user, 'contributed')
|
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
|
end
|
||||||
handle_asynchronously :after_created_async
|
handle_asynchronously :after_created_async
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class NotificationService
|
class NotificationService
|
||||||
|
extend TopicMailerHelper
|
||||||
|
extend MapMailerHelper
|
||||||
# for strip_tags
|
# for strip_tags
|
||||||
include ActionView::Helpers::SanitizeHelper
|
include ActionView::Helpers::SanitizeHelper
|
||||||
|
|
||||||
|
@ -13,13 +15,13 @@ class NotificationService
|
||||||
def self.get_settings_for_event(entity, event_type, event)
|
def self.get_settings_for_event(entity, event_type, event)
|
||||||
case event_type
|
case event_type
|
||||||
when TOPIC_ADDED_TO_MAP
|
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'
|
template = 'topic_mailer/added_to_map'
|
||||||
when TOPIC_CONNECTED_1
|
when TOPIC_CONNECTED_1
|
||||||
subject = TopicMailer.connected_subject(event.topic1)
|
subject = connected_subject(event.topic1)
|
||||||
template = 'topic_mailer/connected'
|
template = 'topic_mailer/connected'
|
||||||
when TOPIC_CONNECTED_2
|
when TOPIC_CONNECTED_2
|
||||||
TopicMailer.connected_subject(event.topic2)
|
subject = connected_subject(event.topic2)
|
||||||
template = 'topic_mailer/connected'
|
template = 'topic_mailer/connected'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,19 +32,19 @@ class NotificationService
|
||||||
return if follows.length == 0
|
return if follows.length == 0
|
||||||
settings = get_settings_for_event(entity, event_type, event)
|
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
|
# 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|
|
follows.each{|follow|
|
||||||
# this handles email and in-app notifications, in the future, include push
|
# 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
|
# 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
|
# the receipt from the notify call could be used to link to the full notification
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
|
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)
|
follows = follows.where.not(id: exclude_follows)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,19 +59,19 @@ class NotificationService
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.access_request(request)
|
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)
|
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)
|
request.map.user.notify(subject, body, request, false, MAP_ACCESS_REQUEST, true, request.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.access_approved(request)
|
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)
|
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)
|
request.user.notify(subject, body, request, false, MAP_ACCESS_APPROVED, true, request.map.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.invite_to_edit(user_map)
|
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)
|
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)
|
user_map.user.notify(subject, body, user_map, false, MAP_INVITE_TO_EDIT, true, user_map.map.user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<h2 class="title">Notifications</h4>
|
<h2 class="title">Notifications</h4>
|
||||||
</header>
|
</header>
|
||||||
<ul class="notifications">
|
<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 = @notifications.to_a.delete_if{|n| blacklist.include?(n.notification_code) && (n.notified_object.nil? || n.notified_object.map.nil?) }%>
|
||||||
<% notifications.each do |notification| %>
|
<% notifications.each do |notification| %>
|
||||||
<% receipt = @receipts.find_by(notification_id: notification.id) %>
|
<% receipt = @receipts.find_by(notification_id: notification.id) %>
|
||||||
|
@ -22,28 +22,29 @@
|
||||||
case notification.notification_code
|
case notification.notification_code
|
||||||
when MAP_ACCESS_APPROVED
|
when MAP_ACCESS_APPROVED
|
||||||
map = notification.notified_object.map
|
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
|
when MAP_ACCESS_REQUEST
|
||||||
map = notification.notified_object.map
|
map = notification.notified_object.map
|
||||||
'wants permission to map with you on <span class="in-bold">' + map.name + '</span> <div class="action">Offer a response</div>'
|
output = 'wants permission to map with you on <span class="in-bold">' + map.name + '</span> <div class="action">Offer a response</div>'
|
||||||
when MAP_INVITE_TO_EDIT
|
when MAP_INVITE_TO_EDIT
|
||||||
map = notification.notified_object.map
|
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
|
when TOPIC_ADDED_TO_MAP
|
||||||
topic = notification.notified_object.eventable
|
topic = notification.notified_object.eventable
|
||||||
map = notification.notified_object.map
|
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
|
when TOPIC_CONNECTED_1
|
||||||
topic1 = notification.notified_object.topic1
|
topic1 = notification.notified_object.topic1
|
||||||
topic2 = notification.notified_object.topic2
|
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
|
when TOPIC_CONNECTED_2
|
||||||
topic1 = notification.notified_object.topic1
|
topic1 = notification.notified_object.topic1
|
||||||
topic2 = notification.notified_object.topic2
|
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
|
when MESSAGE_FROM_DEVS
|
||||||
notification.subject
|
output = notification.subject
|
||||||
end
|
end
|
||||||
|
raw output
|
||||||
%>
|
%>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
connected topic <span style="font-weight: bold"><%= topic1.name %></span>
|
connected topic <span style="font-weight: bold"><%= topic1.name %></span>
|
||||||
to topic <span style="font-weight: bold"><%= topic2.name %></span>
|
to topic <span style="font-weight: bold"><%= topic2.name %></span>
|
||||||
<% if synapse.desc.length > 0 %>
|
<% if synapse.desc.length > 0 %>
|
||||||
with the description "<%= event.desc %>".
|
with the description "<%= synapse.desc %>".
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue