2022-01-19 22:37:27 +01:00
|
|
|
# frozen_string_literal: true
|
2023-02-20 06:58:28 +01:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: status_edits
|
|
|
|
#
|
2022-03-09 09:06:17 +01:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# status_id :bigint(8) not null
|
|
|
|
# account_id :bigint(8)
|
|
|
|
# text :text default(""), not null
|
|
|
|
# spoiler_text :text default(""), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2022-03-10 09:52:45 +01:00
|
|
|
# content_type :string
|
2022-03-09 09:06:17 +01:00
|
|
|
# ordered_media_attachment_ids :bigint(8) is an Array
|
|
|
|
# media_descriptions :text is an Array
|
|
|
|
# poll_options :string is an Array
|
|
|
|
# sensitive :boolean
|
2022-01-19 22:37:27 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
class StatusEdit < ApplicationRecord
|
2022-03-09 20:06:51 +01:00
|
|
|
include RateLimitable
|
|
|
|
|
2023-03-31 15:07:22 +02:00
|
|
|
self.ignored_columns += %w(
|
2022-03-09 09:06:17 +01:00
|
|
|
media_attachments_changed
|
|
|
|
)
|
|
|
|
|
|
|
|
class PreservedMediaAttachment < ActiveModelSerializers::Model
|
|
|
|
attributes :media_attachment, :description
|
2022-03-09 21:15:24 +01:00
|
|
|
|
|
|
|
delegate :id, :type, :url, :preview_url, :remote_url,
|
|
|
|
:preview_remote_url, :text_url, :meta, :blurhash,
|
|
|
|
:not_processed?, :needs_redownload?, :local?,
|
|
|
|
:file, :thumbnail, :thumbnail_remote_url,
|
2022-10-26 13:42:29 +02:00
|
|
|
:shortcode, :video?, :audio?, to: :media_attachment
|
2022-03-09 09:06:17 +01:00
|
|
|
end
|
|
|
|
|
2022-03-09 20:06:51 +01:00
|
|
|
rate_limit by: :account, family: :statuses
|
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
belongs_to :status
|
|
|
|
belongs_to :account, optional: true
|
|
|
|
|
2023-11-23 10:26:11 +01:00
|
|
|
scope :ordered, -> { order(id: :asc) }
|
2022-01-19 22:37:27 +01:00
|
|
|
|
2022-10-26 13:42:29 +02:00
|
|
|
delegate :local?, :application, :edited?, :edited_at,
|
2024-06-24 15:11:10 +02:00
|
|
|
:discarded?, :visibility, :language, to: :status
|
2022-02-09 01:17:07 +01:00
|
|
|
|
|
|
|
def emojis
|
|
|
|
return @emojis if defined?(@emojis)
|
2023-02-20 06:58:28 +01:00
|
|
|
|
2022-02-09 01:17:07 +01:00
|
|
|
@emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
|
|
|
|
end
|
2022-03-09 09:06:17 +01:00
|
|
|
|
|
|
|
def ordered_media_attachments
|
|
|
|
return @ordered_media_attachments if defined?(@ordered_media_attachments)
|
|
|
|
|
2024-07-08 09:41:50 +02:00
|
|
|
@ordered_media_attachments = begin
|
|
|
|
if ordered_media_attachment_ids.nil?
|
|
|
|
[]
|
|
|
|
else
|
|
|
|
map = status.media_attachments.index_by(&:id)
|
|
|
|
ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
|
|
|
|
end
|
|
|
|
end.take(Status::MEDIA_ATTACHMENTS_LIMIT)
|
2022-03-09 09:06:17 +01:00
|
|
|
end
|
2022-10-26 13:42:29 +02:00
|
|
|
|
|
|
|
def proper
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def reblog?
|
|
|
|
false
|
|
|
|
end
|
2022-01-19 22:37:27 +01:00
|
|
|
end
|