1
0

status_edit.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: status_edits
  5. #
  6. # id :bigint(8) not null, primary key
  7. # status_id :bigint(8) not null
  8. # account_id :bigint(8)
  9. # text :text default(""), not null
  10. # spoiler_text :text default(""), not null
  11. # created_at :datetime not null
  12. # updated_at :datetime not null
  13. # ordered_media_attachment_ids :bigint(8) is an Array
  14. # media_descriptions :text is an Array
  15. # poll_options :string is an Array
  16. # sensitive :boolean
  17. #
  18. class StatusEdit < ApplicationRecord
  19. include RateLimitable
  20. self.ignored_columns += %w(
  21. media_attachments_changed
  22. )
  23. class PreservedMediaAttachment < ActiveModelSerializers::Model
  24. attributes :media_attachment, :description
  25. delegate :id, :type, :url, :preview_url, :remote_url,
  26. :preview_remote_url, :text_url, :meta, :blurhash,
  27. :not_processed?, :needs_redownload?, :local?,
  28. :file, :thumbnail, :thumbnail_remote_url,
  29. :shortcode, :video?, :audio?, to: :media_attachment
  30. end
  31. rate_limit by: :account, family: :statuses
  32. belongs_to :status
  33. belongs_to :account, optional: true
  34. scope :ordered, -> { order(id: :asc) }
  35. delegate :local?, :application, :edited?, :edited_at,
  36. :discarded?, :visibility, :language, to: :status
  37. def emojis
  38. return @emojis if defined?(@emojis)
  39. @emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
  40. end
  41. def ordered_media_attachments
  42. return @ordered_media_attachments if defined?(@ordered_media_attachments)
  43. @ordered_media_attachments = begin
  44. if ordered_media_attachment_ids.nil?
  45. []
  46. else
  47. map = status.media_attachments.index_by(&:id)
  48. ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
  49. end
  50. end.take(Status::MEDIA_ATTACHMENTS_LIMIT)
  51. end
  52. def proper
  53. self
  54. end
  55. def reblog?
  56. false
  57. end
  58. end