闭社主体 forked from https://github.com/tootsuite/mastodon
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.

59 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: stream_entries
  5. #
  6. # id :integer not null, primary key
  7. # account_id :integer
  8. # activity_id :integer
  9. # activity_type :string
  10. # created_at :datetime not null
  11. # updated_at :datetime not null
  12. # hidden :boolean default(FALSE), not null
  13. #
  14. class StreamEntry < ApplicationRecord
  15. include Paginable
  16. belongs_to :account, inverse_of: :stream_entries
  17. belongs_to :activity, polymorphic: true
  18. belongs_to :status, foreign_type: 'Status', foreign_key: 'activity_id', inverse_of: :stream_entry
  19. validates :account, :activity, presence: true
  20. STATUS_INCLUDES = [:account, :stream_entry, :media_attachments, :tags, mentions: :account, reblog: [:stream_entry, :account, :media_attachments, :tags, mentions: :account], thread: [:stream_entry, :account]].freeze
  21. default_scope { where(activity_type: 'Status') }
  22. scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) }
  23. delegate :target, :title, :content, :thread,
  24. to: :status,
  25. allow_nil: true
  26. def object_type
  27. orphaned? || targeted? ? :activity : status.object_type
  28. end
  29. def verb
  30. orphaned? ? :delete : status.verb
  31. end
  32. def targeted?
  33. [:follow, :request_friend, :authorize, :reject, :unfollow, :block, :unblock, :share, :favorite].include? verb
  34. end
  35. def threaded?
  36. (verb == :favorite || object_type == :comment) && !thread.nil?
  37. end
  38. def mentions
  39. orphaned? ? [] : status.mentions.map(&:account)
  40. end
  41. private
  42. def orphaned?
  43. status.nil?
  44. end
  45. end