]> cat aescling's git repositories - mastodon.git/blob - app/models/form/status_batch.rb
Remove Form::StatusBatch::ACTION_TYPE unused (#9623)
[mastodon.git] / app / models / form / status_batch.rb
1 # frozen_string_literal: true
2
3 class Form::StatusBatch
4 include ActiveModel::Model
5 include AccountableConcern
6
7 attr_accessor :status_ids, :action, :current_account
8
9 def save
10 case action
11 when 'nsfw_on', 'nsfw_off'
12 change_sensitive(action == 'nsfw_on')
13 when 'delete'
14 delete_statuses
15 end
16 end
17
18 private
19
20 def change_sensitive(sensitive)
21 media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id)
22
23 ApplicationRecord.transaction do
24 Status.where(id: media_attached_status_ids).reorder(nil).find_each do |status|
25 status.update!(sensitive: sensitive)
26 log_action :update, status
27 end
28 end
29
30 true
31 rescue ActiveRecord::RecordInvalid
32 false
33 end
34
35 def delete_statuses
36 Status.where(id: status_ids).reorder(nil).find_each do |status|
37 RemovalWorker.perform_async(status.id)
38 log_action :destroy, status
39 end
40
41 true
42 end
43 end
This page took 0.079418 seconds and 4 git commands to generate.