2016-09-24 11:00:46 +08:00
|
|
|
# frozen_string_literal: true
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2016-09-22 01:22:40 +08:00
|
|
|
class UserMap < ApplicationRecord
|
2016-04-24 11:50:35 -04:00
|
|
|
belongs_to :map
|
|
|
|
belongs_to :user
|
2017-02-09 16:53:19 -05:00
|
|
|
belongs_to :access_request
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-09 16:53:19 -05:00
|
|
|
after_create :after_created_async
|
2017-02-11 00:20:42 -05:00
|
|
|
before_destroy :before_destroyed
|
2016-12-09 11:59:24 -05:00
|
|
|
|
|
|
|
def mark_invite_notifications_as_read
|
2016-12-11 17:29:48 -05:00
|
|
|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
|
2016-12-09 11:59:24 -05:00
|
|
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
|
|
|
end
|
|
|
|
end
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-09 16:53:19 -05:00
|
|
|
protected
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-09 16:53:19 -05:00
|
|
|
def after_created_async
|
2017-02-11 00:20:42 -05:00
|
|
|
FollowService.follow(map, user, 'shared_on')
|
2017-02-09 16:53:19 -05:00
|
|
|
if access_request
|
2017-11-25 11:23:47 -08:00
|
|
|
NotificationService.access_approved(access_request)
|
2017-02-09 16:53:19 -05:00
|
|
|
else
|
|
|
|
NotificationService.invite_to_edit(self)
|
|
|
|
end
|
2017-02-11 00:20:42 -05:00
|
|
|
# NotificationService.notify_followers(map, 'map_collaborator_added', self, 'shared_on')
|
2017-02-09 16:53:19 -05:00
|
|
|
end
|
|
|
|
handle_asynchronously :after_created_async
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-11 00:20:42 -05:00
|
|
|
def before_destroyed
|
|
|
|
FollowService.remove_reason(map, user, 'shared_on')
|
|
|
|
end
|
2016-04-24 11:50:35 -04:00
|
|
|
end
|