2022-01-20 06:37:27 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: status_edits
|
|
|
|
#
|
2022-03-09 17:06:17 +09: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
|
|
|
|
# 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-20 06:37:27 +09:00
|
|
|
#
|
|
|
|
|
|
|
|
class StatusEdit < ApplicationRecord
|
2022-03-10 04:06:51 +09:00
|
|
|
include RateLimitable
|
|
|
|
|
2022-03-09 17:06:17 +09:00
|
|
|
self.ignored_columns = %w(
|
|
|
|
media_attachments_changed
|
|
|
|
)
|
|
|
|
|
|
|
|
class PreservedMediaAttachment < ActiveModelSerializers::Model
|
|
|
|
attributes :media_attachment, :description
|
|
|
|
delegate :id, :type, :url, :preview_url, :remote_url, :preview_remote_url, :text_url, :meta, :blurhash, to: :media_attachment
|
|
|
|
end
|
|
|
|
|
2022-03-10 04:06:51 +09:00
|
|
|
rate_limit by: :account, family: :statuses
|
|
|
|
|
2022-01-20 06:37:27 +09:00
|
|
|
belongs_to :status
|
|
|
|
belongs_to :account, optional: true
|
|
|
|
|
|
|
|
default_scope { order(id: :asc) }
|
|
|
|
|
|
|
|
delegate :local?, to: :status
|
2022-02-09 09:17:07 +09:00
|
|
|
|
|
|
|
def emojis
|
|
|
|
return @emojis if defined?(@emojis)
|
|
|
|
@emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
|
|
|
|
end
|
2022-03-09 17:06:17 +09:00
|
|
|
|
|
|
|
def ordered_media_attachments
|
|
|
|
return @ordered_media_attachments if defined?(@ordered_media_attachments)
|
|
|
|
|
|
|
|
@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
|
|
|
|
end
|
2022-01-20 06:37:27 +09:00
|
|
|
end
|