about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_suggestions/global_source.rb2
-rw-r--r--app/models/admin/status_batch_action.rb12
-rw-r--r--app/models/media_attachment.rb4
-rw-r--r--app/models/notification.rb6
-rw-r--r--app/models/poll.rb6
-rw-r--r--app/models/report.rb9
-rw-r--r--app/models/status.rb12
-rw-r--r--app/models/status_edit.rb6
-rw-r--r--app/models/trends/tags.rb7
-rw-r--r--app/models/user.rb4
10 files changed, 59 insertions, 9 deletions
diff --git a/app/models/account_suggestions/global_source.rb b/app/models/account_suggestions/global_source.rb
index ac764de50..7bca530d4 100644
--- a/app/models/account_suggestions/global_source.rb
+++ b/app/models/account_suggestions/global_source.rb
@@ -6,7 +6,7 @@ class AccountSuggestions::GlobalSource < AccountSuggestions::Source
   end
 
   def get(account, skip_account_ids: [], limit: 40)
-    account_ids = account_ids_for_locale(account.user_locale) - [account.id] - skip_account_ids
+    account_ids = account_ids_for_locale(I18n.locale.to_s.split(/[_-]/).first) - [account.id] - skip_account_ids
 
     as_ordered_suggestions(
       scope(account).where(id: account_ids),
diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb
index 85822214b..40f60f379 100644
--- a/app/models/admin/status_batch_action.rb
+++ b/app/models/admin/status_batch_action.rb
@@ -8,6 +8,12 @@ class Admin::StatusBatchAction
   attr_accessor :current_account, :type,
                 :status_ids, :report_id
 
+  attr_reader :send_email_notification
+
+  def send_email_notification=(value)
+    @send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
+  end
+
   def save!
     process_action!
   end
@@ -55,7 +61,7 @@ class Admin::StatusBatchAction
       statuses.each { |status| Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true) } unless target_account.local?
     end
 
-    UserMailer.warning(target_account.user, @warning).deliver_later! if target_account.local?
+    UserMailer.warning(target_account.user, @warning).deliver_later! if warnable?
     RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
   end
 
@@ -82,6 +88,10 @@ class Admin::StatusBatchAction
     !report.nil?
   end
 
+  def warnable?
+    send_email_notification && target_account.local?
+  end
+
   def target_account
     @target_account ||= statuses.first.account
   end
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/notification.rb b/app/models/notification.rb
index 3bf9dd483..c14eb8a7e 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -35,6 +35,7 @@ class Notification < ApplicationRecord
     follow_request
     favourite
     poll
+    update
   ).freeze
 
   TARGET_STATUS_INCLUDES_BY_TYPE = {
@@ -43,6 +44,7 @@ class Notification < ApplicationRecord
     mention: [mention: :status],
     favourite: [favourite: :status],
     poll: [poll: :status],
+    update: :status,
   }.freeze
 
   belongs_to :account, optional: true
@@ -76,7 +78,7 @@ class Notification < ApplicationRecord
 
   def target_status
     case type
-    when :status
+    when :status, :update
       status
     when :reblog
       status&.reblog
@@ -110,7 +112,7 @@ class Notification < ApplicationRecord
         cached_status = cached_statuses_by_id[notification.target_status.id]
 
         case notification.type
-        when :status
+        when :status, :update
           notification.status = cached_status
         when :reblog
           notification.status.reblog = cached_status
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..607b70712 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -65,6 +65,7 @@ class Status < ApplicationRecord
   has_many :favourites, inverse_of: :status, dependent: :destroy
   has_many :bookmarks, inverse_of: :status, dependent: :destroy
   has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy
+  has_many :reblogged_by_accounts, through: :reblogs, class_name: 'Account', source: :account
   has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread
   has_many :mentions, dependent: :destroy, inverse_of: :status
   has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status
@@ -215,6 +216,17 @@ 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,
+      content_type: content_type,
+      created_at: at_time || edited_at
+    )
+  end
+
   def edited?
     edited_at.present?
   end
diff --git a/app/models/status_edit.rb b/app/models/status_edit.rb
index a89df86c5..3d8098fe7 100644
--- a/app/models/status_edit.rb
+++ b/app/models/status_edit.rb
@@ -11,6 +11,7 @@
 #  media_attachments_changed :boolean          default(FALSE), not null
 #  created_at                :datetime         not null
 #  updated_at                :datetime         not null
+#  content_type              :string
 #
 
 class StatusEdit < ApplicationRecord
@@ -20,4 +21,9 @@ class StatusEdit < ApplicationRecord
   default_scope { order(id: :asc) }
 
   delegate :local?, to: :status
+
+  def emojis
+    return @emojis if defined?(@emojis)
+    @emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
+  end
 end
diff --git a/app/models/trends/tags.rb b/app/models/trends/tags.rb
index a425fd207..2ea4550df 100644
--- a/app/models/trends/tags.rb
+++ b/app/models/trends/tags.rb
@@ -11,12 +11,9 @@ class Trends::Tags < Trends::Base
   }
 
   def register(status, at_time = Time.now.utc)
-    original_status = status.reblog? ? status.reblog : status
+    return unless !status.reblog? && status.public_visibility? && !status.account.silenced?
 
-    return unless original_status.public_visibility? && status.public_visibility? &&
-                  !original_status.account.silenced? && !status.account.silenced?
-
-    original_status.tags.each do |tag|
+    status.tags.each do |tag|
       add(tag, status.account_id, at_time) if tag.usable?
     end
   end
diff --git a/app/models/user.rb b/app/models/user.rb
index 9afdc481d..ee20e293e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -245,6 +245,10 @@ class User < ApplicationRecord
     save!
   end
 
+  def preferred_posting_language
+    settings.default_language || locale
+  end
+
   def setting_default_privacy
     settings.default_privacy || (account.locked? ? 'private' : 'public')
   end