@ -23,6 +23,7 @@
# account_id :integer not null
# account_id :integer not null
# application_id :integer
# application_id :integer
# in_reply_to_account_id :integer
# in_reply_to_account_id :integer
# local_only :boolean
#
#
class Status < ApplicationRecord
class Status < ApplicationRecord
@ -74,6 +75,8 @@ class Status < ApplicationRecord
scope :not_excluded_by_account , - > ( account ) { where . not ( account_id : account . excluded_from_timeline_account_ids ) }
scope :not_excluded_by_account , - > ( account ) { where . not ( account_id : account . excluded_from_timeline_account_ids ) }
scope :not_domain_blocked_by_account , - > ( account ) { account . excluded_from_timeline_domains . blank? ? left_outer_joins ( :account ) : left_outer_joins ( :account ) . where ( 'accounts.domain IS NULL OR accounts.domain NOT IN (?)' , account . excluded_from_timeline_domains ) }
scope :not_domain_blocked_by_account , - > ( account ) { account . excluded_from_timeline_domains . blank? ? left_outer_joins ( :account ) : left_outer_joins ( :account ) . where ( 'accounts.domain IS NULL OR accounts.domain NOT IN (?)' , account . excluded_from_timeline_domains ) }
scope :not_local_only , - > { where ( local_only : [ false , nil ] ) }
cache_associated :account , :application , :media_attachments , :tags , :stream_entry , mentions : :account , reblog : [ :account , :application , :stream_entry , :tags , :media_attachments , mentions : :account ] , thread : :account
cache_associated :account , :application , :media_attachments , :tags , :stream_entry , mentions : :account , reblog : [ :account , :application , :stream_entry , :tags , :media_attachments , mentions : :account ] , thread : :account
delegate :domain , to : :account , prefix : true
delegate :domain , to : :account , prefix : true
@ -138,6 +141,8 @@ class Status < ApplicationRecord
around_create Mastodon :: Snowflake :: Callbacks
around_create Mastodon :: Snowflake :: Callbacks
before_create :set_locality
before_validation :prepare_contents , if : :local?
before_validation :prepare_contents , if : :local?
before_validation :set_reblog
before_validation :set_reblog
before_validation :set_visibility
before_validation :set_visibility
@ -218,7 +223,7 @@ class Status < ApplicationRecord
visibility = [ :public , :unlisted ]
visibility = [ :public , :unlisted ]
if account . nil?
if account . nil?
where ( visibility : visibility )
where ( visibility : visibility ) . not_local_only
elsif target_account . blocking? ( account ) # get rid of blocked peeps
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
@ -257,7 +262,7 @@ class Status < ApplicationRecord
end
end
def filter_timeline_default ( query )
def filter_timeline_default ( query )
query . excluding_silenced_accounts
query . not_local_only. excluding_silenced_accounts
end
end
def account_silencing_filter ( account )
def account_silencing_filter ( account )
@ -269,9 +274,13 @@ class Status < ApplicationRecord
end
end
end
end
def local_only?
def marked_ local_only?
# match both with and without U+FE0F (the emoji variation selector)
# match both with and without U+FE0F (the emoji variation selector)
/ 👁 \ ufe0f? \ z / . match? ( content )
/ #{ local_only_emoji } \ ufe0f? \ z / . match? ( content )
end
def local_only_emoji
'👁'
end
end
private
private
@ -299,6 +308,12 @@ class Status < ApplicationRecord
self . sensitive = sensitive || spoiler_text . present?
self . sensitive = sensitive || spoiler_text . present?
end
end
def set_locality
if account . domain . nil? && ! attribute_changed? ( :local_only )
self . local_only = marked_local_only?
end
end
def set_conversation
def set_conversation
self . reply = ! ( in_reply_to_id . nil? && thread . nil? ) unless reply
self . reply = ! ( in_reply_to_id . nil? && thread . nil? ) unless reply