You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

8 years ago
8 years ago
8 years ago
  1. class Account < ActiveRecord::Base
  2. # Local users
  3. has_one :user, inverse_of: :account
  4. # Timelines
  5. has_many :stream_entries, inverse_of: :account
  6. has_many :statuses, inverse_of: :account
  7. # Follow relations
  8. has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
  9. has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
  10. has_many :following, through: :active_relationships, source: :target_account
  11. has_many :followers, through: :passive_relationships, source: :account
  12. def follow!(other_account)
  13. self.active_relationships.create!(target_account: other_account)
  14. end
  15. def unfollow!(other_account)
  16. self.active_relationships.find_by(target_account: other_account).destroy
  17. end
  18. def following?(other_account)
  19. following.include?(other_account)
  20. end
  21. def local?
  22. self.domain.nil?
  23. end
  24. def keypair
  25. self.private_key.nil? ? OpenSSL::PKey::RSA.new(self.public_key) : OpenSSL::PKey::RSA.new(self.private_key)
  26. end
  27. def subscription(webhook_url)
  28. @subscription ||= OStatus2::Subscription.new(self.remote_url, secret: self.secret, token: self.verify_token, webhook: webhook_url, hub: self.hub_url)
  29. end
  30. end