Skip to content

Commit

Permalink
models: status: add support for quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniini committed Dec 25, 2022
1 parent 78e8693 commit b1bce9d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# edited_at :datetime
# trendable :boolean
# ordered_media_attachment_ids :bigint(8) is an Array
# quote_id :bigint(8)
#

class Status < ApplicationRecord
Expand Down Expand Up @@ -61,6 +62,7 @@ class Status < ApplicationRecord

belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
belongs_to :quote, foreign_key: 'quote_id', class_name: 'Status', inverse_of: :quote, optional: true

has_many :favourites, inverse_of: :status, dependent: :destroy
has_many :bookmarks, inverse_of: :status, dependent: :destroy
Expand All @@ -70,6 +72,7 @@ class Status < ApplicationRecord
has_many :mentions, dependent: :destroy, inverse_of: :status
has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status
has_many :media_attachments, dependent: :nullify
has_many :quoted, foreign_key: 'quote_id', class_name: 'Status', inverse_of: :quote, dependent: :nullify

has_and_belongs_to_many :tags
has_and_belongs_to_many :preview_cards
Expand Down Expand Up @@ -134,6 +137,17 @@ class Status < ApplicationRecord
account: [:account_stat, :user],
active_mentions: { account: :account_stat },
],
quote: [
:application,
:tags,
:preview_cards,
:media_attachments,
:conversation,
:status_stat,
:preloadable_poll,
account: [:account_stat, :user],
active_mentions: { account: :account_stat },
],
thread: { account: :account_stat }

delegate :domain, to: :account, prefix: true
Expand Down Expand Up @@ -195,6 +209,10 @@ def reblog?
!reblog_of_id.nil?
end

def quote?
!quote_id.nil? && quote
end

def within_realtime_window?
created_at >= REAL_TIME_WINDOW.ago
end
Expand Down Expand Up @@ -259,7 +277,7 @@ def emojis
fields = [spoiler_text, text]
fields += preloadable_poll.options unless preloadable_poll.nil?

@emojis = CustomEmoji.from_text(fields.join(' '), account.domain)
@emojis = CustomEmoji.from_text(fields.join(' '), account.domain) + (quote? ? CustomEmoji.from_text([quote.spoiler_text, quote.text].join(' '), quote.account.domain) : [])
end

def ordered_media_attachments
Expand Down

0 comments on commit b1bce9d

Please sign in to comment.