diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/device.rb | 7 | ||||
-rw-r--r-- | app/models/favourite.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 18 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
4 files changed, 16 insertions, 15 deletions
diff --git a/app/models/device.rb b/app/models/device.rb deleted file mode 100644 index 2782a7f38..000000000 --- a/app/models/device.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Device < ApplicationRecord - belongs_to :account - - validates :account, :registration_id, presence: true -end diff --git a/app/models/favourite.rb b/app/models/favourite.rb index 147105e48..3f3616dce 100644 --- a/app/models/favourite.rb +++ b/app/models/favourite.rb @@ -5,7 +5,7 @@ class Favourite < ApplicationRecord include Streamable belongs_to :account, inverse_of: :favourites - belongs_to :status, inverse_of: :favourites, touch: true + belongs_to :status, inverse_of: :favourites has_one :notification, as: :activity, dependent: :destroy diff --git a/app/models/status.rb b/app/models/status.rb index 63f5d5fa4..6ef0b2bdd 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -14,7 +14,7 @@ class Status < ApplicationRecord belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account' belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies - belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, touch: true + belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs has_many :favourites, inverse_of: :status, dependent: :destroy has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy @@ -81,7 +81,7 @@ class Status < ApplicationRecord def ancestors(account = nil) ids = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', id]) - [self]).pluck(:id) - statuses = Status.where(id: ids).with_includes.group_by(&:id) + statuses = Status.where(id: ids).group_by(&:id) results = ids.map { |id| statuses[id].first } results = results.reject { |status| filter_from_context?(status, account) } @@ -90,7 +90,7 @@ class Status < ApplicationRecord def descendants(account = nil) ids = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, path) AS (SELECT id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, path || statuses.id FROM search_tree JOIN statuses ON statuses.in_reply_to_id = search_tree.id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path', id]) - [self]).pluck(:id) - statuses = Status.where(id: ids).with_includes.group_by(&:id) + statuses = Status.where(id: ids).group_by(&:id) results = ids.map { |id| statuses[id].first } results = results.reject { |status| filter_from_context?(status, account) } @@ -102,21 +102,25 @@ class Status < ApplicationRecord where(account: [account] + account.following) end - def as_public_timeline(account = nil) + def as_public_timeline(account = nil, local_only = false) query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) .where('(statuses.in_reply_to_id IS NULL OR statuses.in_reply_to_account_id = statuses.account_id)') .where('statuses.reblog_of_id IS NULL') + query = query.where('accounts.domain IS NULL') if local_only + account.nil? ? filter_timeline_default(query) : filter_timeline_default(filter_timeline(query, account)) end - def as_tag_timeline(tag, account = nil) + def as_tag_timeline(tag, account = nil, local_only = false) query = tag.statuses .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) .where('statuses.reblog_of_id IS NULL') + query = query.where('accounts.domain IS NULL') if local_only + account.nil? ? filter_timeline_default(query) : filter_timeline_default(filter_timeline(query, account)) end @@ -157,7 +161,7 @@ class Status < ApplicationRecord private def filter_timeline(query, account) - blocked = Block.where(account: account).pluck(:target_account_id) + blocked = Block.where(account: account).pluck(:target_account_id) + Block.where(target_account: account).pluck(:account_id) query = query.where('statuses.account_id NOT IN (?)', blocked) unless blocked.empty? query = query.where('accounts.silenced = TRUE') if account.silenced? query @@ -180,6 +184,6 @@ class Status < ApplicationRecord private def filter_from_context?(status, account) - account&.blocking?(status.account) || !status.permitted?(account) + account&.blocking?(status.account_id) || !status.permitted?(account) end end diff --git a/app/models/user.rb b/app/models/user.rb index b34144f2c..08aac2679 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,4 +21,8 @@ class User < ApplicationRecord def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end + + def setting_default_privacy + settings.default_privacy || (account.locked? ? 'private' : 'public') + end end |