about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-02-10 23:38:29 +0000
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:21 -0500
commit1636a4e8ae8cfd0024f58c56521622a8609f12c4 (patch)
tree8ea5281c1112bfd182742dfc2bed0bdcaef9d319 /app/models
parenta7aa2544e4f5926414af75e5c0acaa06c2ec7873 (diff)
unlisted & private hashtags
Diffstat (limited to 'app/models')
-rw-r--r--app/models/status.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 0af3c45b5..29e8c7374 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -93,6 +93,8 @@ class Status < ApplicationRecord
   scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
   scope :reblogs, -> { where('statuses.reblog_of_id IS NOT NULL') } # all reblogs
   scope :with_public_visibility, -> { where(visibility: :public) }
+  scope :public_browsable, -> { where(visibility: [:public, :unlisted]) }
+  scope :visible_to, ->(account) { where(visibility: [:public, :unlisted]).or(where(account: [account] + account.following).where(visibility: :private)) }
   scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
   scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
   scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
@@ -371,7 +373,8 @@ class Status < ApplicationRecord
     end
 
     def as_tag_timeline(tag, account = nil, local_only = false)
-      query = timeline_scope(local_only).tagged_with(tag)
+      query = (account.nil?) ? browsable_timeline_scope(local_only) : user_timeline_scope(account, local_only)
+      query = query.tagged_with(tag)
 
       apply_timeline_filters(query, account, local_only)
     end
@@ -454,6 +457,20 @@ class Status < ApplicationRecord
       end
     end
 
+    def browsable_timeline_scope(local_only = false)
+      starting_scope = local_only ? Status.local : Status
+      starting_scope
+        .public_browsable
+        .without_reblogs
+    end
+
+    def user_timeline_scope(account, local_only = false)
+      starting_scope = local_only ? Status.local : Status
+      starting_scope
+        .visible_to(account)
+        .without_reblogs
+    end
+
     def apply_timeline_filters(query, account, local_only)
       if account.nil?
         filter_timeline_default(query)