|
|
@ -55,7 +55,7 @@ class Status < ApplicationRecord
|
|
|
|
validates_with StatusLengthValidator
|
|
|
|
validates_with StatusLengthValidator
|
|
|
|
validates :reblog, uniqueness: { scope: :account }, if: 'reblog?'
|
|
|
|
validates :reblog, uniqueness: { scope: :account }, if: 'reblog?'
|
|
|
|
|
|
|
|
|
|
|
|
default_scope { order('id desc') }
|
|
|
|
default_scope { order(id: :desc) }
|
|
|
|
|
|
|
|
|
|
|
|
scope :remote, -> { where.not(uri: nil) }
|
|
|
|
scope :remote, -> { where.not(uri: nil) }
|
|
|
|
scope :local, -> { where(uri: nil) }
|
|
|
|
scope :local, -> { where(uri: nil) }
|
|
|
@ -202,18 +202,22 @@ class Status < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def permitted_for(target_account, account)
|
|
|
|
def permitted_for(target_account, account)
|
|
|
|
return where.not(visibility: [:private, :direct]) if account.nil?
|
|
|
|
visibility = [:public, :unlisted]
|
|
|
|
|
|
|
|
|
|
|
|
if target_account.blocking?(account) # get rid of blocked peeps
|
|
|
|
if account.nil?
|
|
|
|
|
|
|
|
where(visibility: visibility)
|
|
|
|
|
|
|
|
elsif target_account.blocking?(account) # get rid of blocked peeps
|
|
|
|
none
|
|
|
|
none
|
|
|
|
elsif account.id == target_account.id # author can see own stuff
|
|
|
|
elsif account.id == target_account.id # author can see own stuff
|
|
|
|
all
|
|
|
|
all
|
|
|
|
elsif account.following?(target_account) # followers can see followers-only stuff, but also things they are mentioned in
|
|
|
|
else
|
|
|
|
joins('LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = ' + account.id.to_s)
|
|
|
|
# followers can see followers-only stuff, but also things they are mentioned in.
|
|
|
|
.where('statuses.visibility != ? OR mentions.id IS NOT NULL', Status.visibilities[:direct])
|
|
|
|
# non-followers can see everything that isn't private/direct, but can see stuff they are mentioned in.
|
|
|
|
else # non-followers can see everything that isn't private/direct, but can see stuff they are mentioned in
|
|
|
|
visibility.push(:private) if account.following?(target_account)
|
|
|
|
joins('LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = ' + account.id.to_s)
|
|
|
|
|
|
|
|
.where('statuses.visibility NOT IN (?) OR mentions.id IS NOT NULL', [Status.visibilities[:direct], Status.visibilities[:private]])
|
|
|
|
joins("LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = #{account.id}")
|
|
|
|
|
|
|
|
.where(arel_table[:visibility].in(visibility).or(Mention.arel_table[:id].not_eq(nil)))
|
|
|
|
|
|
|
|
.order(visibility: :desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|