status_edit.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. default_scope { order(id: :asc) }
  35. delegate :local?, :application, :edited?, :edited_at,
  36. :discarded?, :visibility, 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
  51. end
  52. def proper
  53. self
  54. end
  55. def reblog?
  56. false
  57. end
  58. end