app/models/federails/following.rb in federails-0.1.0 vs app/models/federails/following.rb in federails-0.2.0
- old
+ new
@@ -1,16 +1,19 @@
module Federails
class Following < ApplicationRecord
+ include Federails::HasUuid
+
enum status: { pending: 0, accepted: 1 }
validates :target_actor_id, uniqueness: { scope: [:actor_id, :target_actor_id] }
belongs_to :actor
belongs_to :target_actor, class_name: 'Federails::Actor'
# FIXME: Handle this with something like undelete
has_many :activities, as: :entity, dependent: :destroy
+ after_create :after_follow
after_create :create_activity
after_destroy :destroy_activity
scope :with_actor, ->(actor) { where(actor_id: actor.id).or(where(target_actor_id: actor.id)) }
@@ -29,9 +32,15 @@
new actor: actor, target_actor: target_actor
end
end
private
+
+ def after_follow
+ target_actor&.entity&.run_callbacks :followed, :after do
+ self
+ end
+ end
def create_activity
Activity.create! actor: actor, action: 'Create', entity: self
end