all the good changes
This commit is contained in:
parent
915defcd1b
commit
de0100a0b9
3 changed files with 30 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
module Events
|
module Events
|
||||||
class TopicAddedToMap < Event
|
class TopicAddedToMap < Event
|
||||||
# after_create :notify_users!
|
after_create :notify_users!
|
||||||
|
|
||||||
def self.publish!(topic, map, user, meta)
|
def self.publish!(topic, map, user, meta)
|
||||||
create!(kind: 'topic_added_to_map',
|
create!(kind: 'topic_added_to_map',
|
||||||
|
@ -10,5 +10,12 @@ module Events
|
||||||
user: user,
|
user: user,
|
||||||
meta: meta)
|
meta: meta)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,9 @@ class Mapping < ApplicationRecord
|
||||||
delegate :name, to: :user, prefix: true
|
delegate :name, to: :user, prefix: true
|
||||||
|
|
||||||
after_create :after_created
|
after_create :after_created
|
||||||
|
after_create :after_created_async
|
||||||
after_update :after_updated
|
after_update :after_updated
|
||||||
|
after_update :after_updated_async
|
||||||
before_destroy :before_destroyed
|
before_destroy :before_destroyed
|
||||||
|
|
||||||
def user_image
|
def user_image
|
||||||
|
@ -42,6 +44,11 @@ class Mapping < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def after_created_async
|
||||||
|
FollowService.follow(map, user, 'contributed')
|
||||||
|
end
|
||||||
|
handle_asynchronously :after_created_async
|
||||||
|
|
||||||
def after_updated
|
def after_updated
|
||||||
if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
|
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
|
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicMoved', id: mappable.id, mapping_id: id, x: xloc, y: yloc
|
||||||
end
|
end
|
||||||
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
|
def before_destroyed
|
||||||
if mappable.defer_to_map
|
if mappable.defer_to_map
|
||||||
|
@ -66,5 +80,6 @@ class Mapping < ApplicationRecord
|
||||||
Events::SynapseRemovedFromMap.publish!(mappable, map, updated_by, meta)
|
Events::SynapseRemovedFromMap.publish!(mappable, map, updated_by, meta)
|
||||||
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseRemoved', id: mappable.id, mapping_id: id
|
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseRemoved', id: mappable.id, mapping_id: id
|
||||||
end
|
end
|
||||||
|
FollowService.follow(map, updated_by, 'contributed')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class UserMap < ApplicationRecord
|
||||||
belongs_to :access_request
|
belongs_to :access_request
|
||||||
|
|
||||||
after_create :after_created_async
|
after_create :after_created_async
|
||||||
|
before_destroy :before_destroyed
|
||||||
|
|
||||||
def mark_invite_notifications_as_read
|
def mark_invite_notifications_as_read
|
||||||
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
|
||||||
|
@ -15,11 +16,17 @@ class UserMap < ApplicationRecord
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def after_created_async
|
def after_created_async
|
||||||
|
FollowService.follow(map, user, 'shared_on')
|
||||||
if access_request
|
if access_request
|
||||||
NotificationService.access_approved(self.access_request)
|
NotificationService.access_approved(self.access_request)
|
||||||
else
|
else
|
||||||
NotificationService.invite_to_edit(self)
|
NotificationService.invite_to_edit(self)
|
||||||
end
|
end
|
||||||
|
# NotificationService.notify_followers(map, 'map_collaborator_added', self, 'shared_on')
|
||||||
end
|
end
|
||||||
handle_asynchronously :after_created_async
|
handle_asynchronously :after_created_async
|
||||||
|
|
||||||
|
def before_destroyed
|
||||||
|
FollowService.remove_reason(map, user, 'shared_on')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue