all the good changes

This commit is contained in:
Connor Turland 2017-02-09 21:47:41 +00:00
parent 915defcd1b
commit de0100a0b9
3 changed files with 30 additions and 1 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
module Events
class TopicAddedToMap < Event
# after_create :notify_users!
after_create :notify_users!
def self.publish!(topic, map, user, meta)
create!(kind: 'topic_added_to_map',
@ -10,5 +10,12 @@ module Events
user: user,
meta: meta)
end
def notify_users!
# in the future, notify followers of both the topic, and the map
NotificationService.notify_followers(eventable, 'topic_added_to_map', self)
# NotificationService.notify_followers(map, 'topic_added_to_map', self)
end
handle_asynchronously :notify_users!
end
end

View file

@ -14,7 +14,9 @@ class Mapping < ApplicationRecord
delegate :name, to: :user, prefix: true
after_create :after_created
after_create :after_created_async
after_update :after_updated
after_update :after_updated_async
before_destroy :before_destroyed
def user_image
@ -42,6 +44,11 @@ class Mapping < ApplicationRecord
)
end
end
def after_created_async
FollowService.follow(map, user, 'contributed')
end
handle_asynchronously :after_created_async
def after_updated
if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
@ -50,6 +57,13 @@ class Mapping < ApplicationRecord
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicMoved', id: mappable.id, mapping_id: id, x: xloc, y: yloc
end
end
def after_updated_async
if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
FollowService.follow(map, updated_by, 'contributed')
end
end
handle_asynchronously :after_updated_async
def before_destroyed
if mappable.defer_to_map
@ -66,5 +80,6 @@ class Mapping < ApplicationRecord
Events::SynapseRemovedFromMap.publish!(mappable, map, updated_by, meta)
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseRemoved', id: mappable.id, mapping_id: id
end
FollowService.follow(map, updated_by, 'contributed')
end
end

View file

@ -5,6 +5,7 @@ class UserMap < ApplicationRecord
belongs_to :access_request
after_create :after_created_async
before_destroy :before_destroyed
def mark_invite_notifications_as_read
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
@ -15,11 +16,17 @@ class UserMap < ApplicationRecord
protected
def after_created_async
FollowService.follow(map, user, 'shared_on')
if access_request
NotificationService.access_approved(self.access_request)
else
NotificationService.invite_to_edit(self)
end
# NotificationService.notify_followers(map, 'map_collaborator_added', self, 'shared_on')
end
handle_asynchronously :after_created_async
def before_destroyed
FollowService.remove_reason(map, user, 'shared_on')
end
end