2016-09-24 03:00:46 +00:00
|
|
|
# frozen_string_literal: true
|
2017-11-25 19:23:47 +00:00
|
|
|
|
|
|
|
class Star < ApplicationRecord
|
2016-08-31 20:58:49 +00:00
|
|
|
belongs_to :user
|
|
|
|
belongs_to :map
|
2016-10-05 14:36:03 +00:00
|
|
|
validates :map, uniqueness: { scope: :user, message: 'You have already starred this map' }
|
2017-02-11 05:20:42 +00:00
|
|
|
|
2017-11-25 19:23:47 +00:00
|
|
|
# after_create :after_created_async
|
|
|
|
# before_destroy :before_destroyed
|
|
|
|
|
2017-02-11 05:20:42 +00:00
|
|
|
protected
|
2017-11-25 19:23:47 +00:00
|
|
|
|
2017-02-11 05:20:42 +00:00
|
|
|
def after_created_async
|
|
|
|
FollowService.follow(map, user, 'starred')
|
|
|
|
NotificationService.notify_followers(map, 'map_starred', self, 'created')
|
|
|
|
end
|
|
|
|
handle_asynchronously :after_created_async
|
2017-11-25 19:23:47 +00:00
|
|
|
|
2017-02-11 05:20:42 +00:00
|
|
|
def before_destroyed
|
|
|
|
FollowService.remove_reason(map, user, 'starred')
|
|
|
|
end
|
2016-08-31 20:58:49 +00:00
|
|
|
end
|