Merge branch 'main' into glitch-soc/merge-upstream

Conflicts:
- `app/controllers/api/v1/statuses_controller.rb`:
  Upstream moved things around in a place where glitch-soc had support for
  an extra parameter (`content_type`).
  Follow upstream but reintroduce `content_type`.
This commit is contained in:
Claire
2022-02-10 19:09:27 +01:00
35 changed files with 973 additions and 121 deletions

View File

@ -208,6 +208,10 @@ class MediaAttachment < ApplicationRecord
file.blank? && remote_url.present?
end
def significantly_changed?
description_previously_changed? || thumbnail_updated_at_previously_changed? || file_meta_previously_changed?
end
def larger_media_format?
video? || gifv? || audio?
end

View File

@ -83,6 +83,12 @@ class Poll < ApplicationRecord
end
end
def reset_votes!
self.cached_tallies = options.map { 0 }
self.votes_count = 0
votes.delete_all unless new_record?
end
private
def prepare_cached_tallies

View File

@ -39,6 +39,9 @@ class Report < ApplicationRecord
scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with({ user: [:invite_request, :invite] })) }
validates :comment, length: { maximum: 1_000 }
validates :rule_ids, absence: true, unless: :violation?
validate :validate_rule_ids
enum category: {
other: 0,
@ -122,4 +125,10 @@ class Report < ApplicationRecord
def set_uri
self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
end
def validate_rule_ids
return unless violation?
errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids.size
end
end

View File

@ -215,6 +215,16 @@ class Status < ApplicationRecord
public_visibility? || unlisted_visibility?
end
def snapshot!(media_attachments_changed: false, account_id: nil, at_time: nil)
edits.create!(
text: text,
spoiler_text: spoiler_text,
media_attachments_changed: media_attachments_changed,
account_id: account_id || self.account_id,
created_at: at_time || edited_at
)
end
def edited?
edited_at.present?
end