diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-02-10 19:09:27 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-02-10 19:09:27 +0100 |
commit | f1a6f9062e00c0651680bf4d5d750ec0b078ac5a (patch) | |
tree | 30d40f0b5df56e955f80a91ae3b44090bd918ed9 /app/models | |
parent | d602c92b310545eb733a58caed49717341abe27c (diff) | |
parent | 3dc1e3cfc3928ce709c3e60e98ecbd1edd6e2a7d (diff) |
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`.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/media_attachment.rb | 4 | ||||
-rw-r--r-- | app/models/poll.rb | 6 | ||||
-rw-r--r-- | app/models/report.rb | 9 | ||||
-rw-r--r-- | app/models/status.rb | 10 |
4 files changed, 29 insertions, 0 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 14e6cabae..9eaacdc03 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -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 diff --git a/app/models/poll.rb b/app/models/poll.rb index 71b5e191f..ba08309a1 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -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 diff --git a/app/models/report.rb b/app/models/report.rb index ceb15133b..3dd8a6fdd 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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 diff --git a/app/models/status.rb b/app/models/status.rb index 9bb2b3746..e5a0beab6 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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 |