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
app
|
@ -132,6 +132,18 @@ class User < ApplicationRecord
|
||||||
stars.where(map_id: map.id).exists?
|
stars.where(map_id: map.id).exists?
|
||||||
end
|
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
|
def settings
|
||||||
self[:settings] = UserPreference.new if self[:settings].nil?
|
self[:settings] = UserPreference.new if self[:settings].nil?
|
||||||
if not self[:settings].respond_to?(:follow_topic_on_created)
|
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
|
# 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|
|
||||||
if entity.class == Map
|
case event_type
|
||||||
next unless MapPolicy.new(follow.user, entity).show?
|
when TOPIC_ADDED_TO_MAP
|
||||||
elsif entity.class == Topic
|
next unless TopicPolicy.new(follow.user, entity).show? && MapPolicy.new(follow.user, event.map).show?
|
||||||
next unless TopicPolicy.new(follow.user, entity).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
|
end
|
||||||
# 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, event.user)
|
follow.user.notify(settings[:subject], body, event, false, event_type, follow.user.emails_allowed, event.user)
|
||||||
|
|
Loading…
Reference in a new issue