fix permissions and don't send if has map open
This commit is contained in:
parent
5d0da4c5f1
commit
de4f51bb5c
2 changed files with 19 additions and 4 deletions
|
@ -132,6 +132,18 @@ class User < ApplicationRecord
|
|||
stars.where(map_id: map.id).exists?
|
||||
end
|
||||
|
||||
def has_map_open(map)
|
||||
latestEvent = Event.where(map: map, user: self)
|
||||
.where(kind: ['user_present_on_map', 'user_not_present_on_map'])
|
||||
.order(:created_at)
|
||||
.last
|
||||
latestEvent && latestEvent.kind == 'user_present_on_map'
|
||||
end
|
||||
|
||||
def has_map_with_synapse_open(synapse)
|
||||
synapse.maps.any?{|map| has_map_open(map)}
|
||||
end
|
||||
|
||||
def settings
|
||||
self[:settings] = UserPreference.new if self[:settings].nil?
|
||||
if not self[:settings].respond_to?(:follow_topic_on_created)
|
||||
|
|
|
@ -34,10 +34,13 @@ class NotificationService
|
|||
# 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)
|
||||
follows.each{|follow|
|
||||
if entity.class == Map
|
||||
next unless MapPolicy.new(follow.user, entity).show?
|
||||
elsif entity.class == Topic
|
||||
next unless TopicPolicy.new(follow.user, entity).show?
|
||||
case event_type
|
||||
when TOPIC_ADDED_TO_MAP
|
||||
next unless TopicPolicy.new(follow.user, entity).show? && MapPolicy.new(follow.user, event.map).show?
|
||||
next if follow.user.has_map_open(event.map)
|
||||
when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2
|
||||
next unless SynapsePolicy.new(follow.user, event).show?
|
||||
next if follow.user.has_map_with_synapse_open(event)
|
||||
end
|
||||
# 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, event.user)
|
||||
|
|
Loading…
Reference in a new issue