about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-27 19:33:04 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-27 19:33:04 +0200
commit909d0d5e88b046f8bb69c893c54944bb2aad12cf (patch)
tree00ffca4ac1316dbbe8fe94ffd7facc0101bbbf66
parente5565a7e4a817e7f86061355b77c98402b0ceac7 (diff)
Adding public timeline silencing
-rw-r--r--app/models/status.rb7
-rw-r--r--app/services/fan_out_on_write_service.rb1
-rw-r--r--db/migrate/20161027172456_add_silenced_to_accounts.rb5
-rw-r--r--db/schema.rb25
4 files changed, 25 insertions, 13 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 8b7c9c823..19c0488d0 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -86,7 +86,12 @@ class Status < ApplicationRecord
   end
 
   def self.as_public_timeline(account)
-    joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.reblog_of_id = reblogs.id').where('(reblogs.account_id IS NULL OR reblogs.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)) AND statuses.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)', account.id, account.id).with_includes.with_counters
+    joins('LEFT OUTER JOIN statuses AS reblogs ON statuses.reblog_of_id = reblogs.id')
+      .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
+      .where('accounts.silenced = FALSE')
+      .where('(reblogs.account_id IS NULL OR reblogs.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)) AND statuses.account_id NOT IN (SELECT target_account_id FROM blocks WHERE account_id = ?)', account.id, account.id)
+      .with_includes
+      .with_counters
   end
 
   def self.favourites_map(status_ids, account_id)
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 312994db5..707f74c35 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -30,6 +30,7 @@ class FanOutOnWriteService < BaseService
   end
 
   def deliver_to_public(status)
+    return if status.account.silenced?
     FeedManager.instance.broadcast(:public, id: status.id)
   end
 end
diff --git a/db/migrate/20161027172456_add_silenced_to_accounts.rb b/db/migrate/20161027172456_add_silenced_to_accounts.rb
new file mode 100644
index 000000000..cd3b9f8d0
--- /dev/null
+++ b/db/migrate/20161027172456_add_silenced_to_accounts.rb
@@ -0,0 +1,5 @@
+class AddSilencedToAccounts < ActiveRecord::Migration[5.0]
+  def change
+    add_column :accounts, :silenced, :boolean, null: false, default: false
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 773c6bf6a..0af5a6395 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,25 +10,25 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20161009120834) do
+ActiveRecord::Schema.define(version: 20161027172456) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
 
   create_table "accounts", force: :cascade do |t|
-    t.string   "username",                default: "", null: false
+    t.string   "username",                default: "",    null: false
     t.string   "domain"
-    t.string   "secret",                  default: "", null: false
+    t.string   "secret",                  default: "",    null: false
     t.text     "private_key"
-    t.text     "public_key",              default: "", null: false
-    t.string   "remote_url",              default: "", null: false
-    t.string   "salmon_url",              default: "", null: false
-    t.string   "hub_url",                 default: "", null: false
-    t.datetime "created_at",                           null: false
-    t.datetime "updated_at",                           null: false
-    t.text     "note",                    default: "", null: false
-    t.string   "display_name",            default: "", null: false
-    t.string   "uri",                     default: "", null: false
+    t.text     "public_key",              default: "",    null: false
+    t.string   "remote_url",              default: "",    null: false
+    t.string   "salmon_url",              default: "",    null: false
+    t.string   "hub_url",                 default: "",    null: false
+    t.datetime "created_at",                              null: false
+    t.datetime "updated_at",                              null: false
+    t.text     "note",                    default: "",    null: false
+    t.string   "display_name",            default: "",    null: false
+    t.string   "uri",                     default: "",    null: false
     t.string   "url"
     t.string   "avatar_file_name"
     t.string   "avatar_content_type"
@@ -40,6 +40,7 @@ ActiveRecord::Schema.define(version: 20161009120834) do
     t.datetime "header_updated_at"
     t.string   "avatar_remote_url"
     t.datetime "subscription_expires_at"
+    t.boolean  "silenced",                default: false, null: false
     t.index ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true, using: :btree
   end