about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-01-13 16:07:40 +0100
committerGitHub <noreply@github.com>2020-01-13 16:07:40 +0100
commitddcf78d8d3e2a8cb9aa04f8ff42f9d8e185b0354 (patch)
tree14bcdbeac5f8d904cad3d13a469869c5baf9db99 /app/models
parent180f1383943ad171d8394ef9af7c7861bfc08056 (diff)
parent83f8bf48d91605fa63325b4d4acec717031da025 (diff)
Merge pull request #1263 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb4
-rw-r--r--app/models/concerns/attachmentable.rb2
-rw-r--r--app/models/concerns/status_threading_concern.rb12
-rw-r--r--app/models/domain_block.rb2
-rw-r--r--app/models/status.rb7
5 files changed, 10 insertions, 17 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 86f7295bc..9b9361670 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -316,10 +316,6 @@ class Account < ApplicationRecord
     self.fields = tmp
   end
 
-  def subscription(webhook_url)
-    @subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url)
-  end
-
   def save_with_optional_media!
     save!
   rescue ActiveRecord::RecordInvalid
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb
index 1e8c4806f..43ff8ac12 100644
--- a/app/models/concerns/attachmentable.rb
+++ b/app/models/concerns/attachmentable.rb
@@ -74,7 +74,7 @@ module Attachmentable
     self.class.attachment_definitions.each_key do |attachment_name|
       attachment = send(attachment_name)
 
-      next if attachment.blank?
+      next if attachment.blank? || attachment.queued_for_write[:original].blank?
 
       attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name))
     end
diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb
index 15eb695cd..a0ead1995 100644
--- a/app/models/concerns/status_threading_concern.rb
+++ b/app/models/concerns/status_threading_concern.rb
@@ -81,12 +81,12 @@ module StatusThreadingConcern
   end
 
   def find_statuses_from_tree_path(ids, account, promote: false)
-    statuses    = statuses_with_accounts(ids).to_a
+    statuses    = Status.with_accounts(ids).to_a
     account_ids = statuses.map(&:account_id).uniq
     domains     = statuses.map(&:account_domain).compact.uniq
     relations   = relations_map_for_account(account, account_ids, domains)
 
-    statuses.reject! { |status| filter_from_context?(status, account, relations) }
+    statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? }
 
     # Order ancestors/descendants by tree path
     statuses.sort_by! { |status| ids.index(status.id) }
@@ -125,12 +125,4 @@ module StatusThreadingConcern
       domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id),
     }
   end
-
-  def statuses_with_accounts(ids)
-    Status.where(id: ids).includes(:account)
-  end
-
-  def filter_from_context?(status, account, relations)
-    StatusFilter.new(status, account, relations).filtered?
-  end
 end
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index 4e865b850..f0a5bd296 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -54,7 +54,7 @@ class DomainBlock < ApplicationRecord
       segments = uri.normalized_host.split('.')
       variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
 
-      where(domain: variants[0..-2]).order(Arel.sql('char_length(domain) desc')).first
+      where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
     end
   end
 
diff --git a/app/models/status.rb b/app/models/status.rb
index c189d19bf..f4284f771 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -87,6 +87,7 @@ class Status < ApplicationRecord
   scope :remote, -> { where(local: false).where.not(uri: nil) }
   scope :local,  -> { where(local: true).or(where(uri: nil)) }
 
+  scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
   scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
   scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
   scope :with_public_visibility, -> { where(visibility: :public) }
@@ -200,8 +201,12 @@ class Status < ApplicationRecord
   def title
     if destroyed?
       "#{account.acct} deleted status"
+    elsif reblog?
+      preview = sensitive ? '<sensitive>' : text.slice(0, 10).split("\n")[0]
+      "#{account.acct} shared #{reblog.account.acct}'s: #{preview}"
     else
-      reblog? ? "#{account.acct} shared a status by #{reblog.account.acct}" : "New status by #{account.acct}"
+      preview = sensitive ? '<sensitive>' : text.slice(0, 20).split("\n")[0]
+      "#{account.acct}: #{preview}"
     end
   end