You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  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. self.ignored_columns = %w(
  20. media_attachments_changed
  21. )
  22. class PreservedMediaAttachment < ActiveModelSerializers::Model
  23. attributes :media_attachment, :description
  24. delegate :id, :type, :url, :preview_url, :remote_url, :preview_remote_url, :text_url, :meta, :blurhash, to: :media_attachment
  25. end
  26. belongs_to :status
  27. belongs_to :account, optional: true
  28. default_scope { order(id: :asc) }
  29. delegate :local?, to: :status
  30. def emojis
  31. return @emojis if defined?(@emojis)
  32. @emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
  33. end
  34. def ordered_media_attachments
  35. return @ordered_media_attachments if defined?(@ordered_media_attachments)
  36. @ordered_media_attachments = begin
  37. if ordered_media_attachment_ids.nil?
  38. []
  39. else
  40. map = status.media_attachments.index_by(&:id)
  41. ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
  42. end
  43. end
  44. end
  45. end