The code powering m.abunchtell.com https://m.abunchtell.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

63 行
1.6 KiB

  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. has_many :favourites, inverse_of: :account
  8. # Follow relations
  9. has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
  10. has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
  11. has_many :following, through: :active_relationships, source: :target_account
  12. has_many :followers, through: :passive_relationships, source: :account
  13. MENTION_RE = /(?:^|\W)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
  14. def follow!(other_account)
  15. self.active_relationships.first_or_create!(target_account: other_account)
  16. end
  17. def unfollow!(other_account)
  18. self.active_relationships.find_by(target_account: other_account).destroy
  19. end
  20. def following?(other_account)
  21. following.include?(other_account)
  22. end
  23. def local?
  24. self.domain.nil?
  25. end
  26. def acct
  27. local? ? self.username : "#{self.username}@#{self.domain}"
  28. end
  29. def object_type
  30. :person
  31. end
  32. def title
  33. self.username
  34. end
  35. def content
  36. self.note
  37. end
  38. def subscribed?
  39. !(self.secret.blank? || self.verify_token.blank?)
  40. end
  41. def keypair
  42. self.private_key.nil? ? OpenSSL::PKey::RSA.new(self.public_key) : OpenSSL::PKey::RSA.new(self.private_key)
  43. end
  44. def subscription(webhook_url)
  45. @subscription ||= OStatus2::Subscription.new(self.remote_url, secret: self.secret, token: self.verify_token, webhook: webhook_url, hub: self.hub_url)
  46. end
  47. end