about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-12-19 20:43:53 -0600
committermultiple creatures <dev@multiple-creature.party>2019-12-19 20:48:20 -0600
commit82f98a770b088a3ffb2c165fd22ccb0adadd57a7 (patch)
treea87c075a92305ef696cedc6c255c963bf283c0ec
parent32d998b62333a768af3a274d265fd02483ce15de (diff)
rework hide boosts / show only packmates options to work with timeline streaming
-rw-r--r--app/controllers/api/v1/timelines/home_controller.rb2
-rw-r--r--app/controllers/api/v1/timelines/list_controller.rb2
-rw-r--r--app/controllers/settings/preferences_controller.rb4
-rw-r--r--app/models/status.rb8
-rw-r--r--app/models/user.rb12
-rw-r--r--app/views/settings/preferences/show.html.haml4
-rw-r--r--config/locales/simple_form.en.yml4
-rw-r--r--db/migrate/20191220020429_add_hide_boosts_to_users.rb5
-rw-r--r--db/migrate/20191220020441_add_only_known_to_users.rb5
-rw-r--r--db/schema.rb4
-rw-r--r--streaming/index.js12
11 files changed, 38 insertions, 24 deletions
diff --git a/app/controllers/api/v1/timelines/home_controller.rb b/app/controllers/api/v1/timelines/home_controller.rb
index 01d4e3360..bd3bac0fe 100644
--- a/app/controllers/api/v1/timelines/home_controller.rb
+++ b/app/controllers/api/v1/timelines/home_controller.rb
@@ -23,7 +23,7 @@ class Api::V1::Timelines::HomeController < Api::BaseController
   end
 
   def cached_home_statuses
-    if current_account&.user&.hides_boosts?
+    if current_account&.user&.hide_boosts
       cache_collection home_statuses.without_reblogs, Status
     else
       cache_collection home_statuses, Status
diff --git a/app/controllers/api/v1/timelines/list_controller.rb b/app/controllers/api/v1/timelines/list_controller.rb
index 15934adb3..7eb656745 100644
--- a/app/controllers/api/v1/timelines/list_controller.rb
+++ b/app/controllers/api/v1/timelines/list_controller.rb
@@ -25,7 +25,7 @@ class Api::V1::Timelines::ListController < Api::BaseController
   end
 
   def cached_list_statuses
-    if current_account&.user&.hides_boosts?
+    if current_account&.user&.hide_boosts
       cache_collection list_statuses.without_reblogs, Status
     else
       cache_collection list_statuses, Status
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 3ea166c31..66e9033d3 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -27,6 +27,8 @@ class Settings::PreferencesController < Settings::BaseController
   def user_params
     params.require(:user).permit(
       :locale,
+      :hide_boosts,
+      :only_known,
       chosen_languages: []
     )
   end
@@ -51,8 +53,6 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_hide_mntions_blocked,
       :setting_hide_mntions_blocker,
       :setting_hide_mntions_packm8,
-      :setting_hide_boosts,
-      :setting_only_known,
       :setting_gently_kobolds,
       :setting_user_is_kobold,
       :setting_hide_mascot,
diff --git a/app/models/status.rb b/app/models/status.rb
index 8f618ed31..8a1680ccf 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -393,7 +393,7 @@ class Status < ApplicationRecord
 
     def as_home_timeline(account)
       query = where(account: [account] + account.following, visibility: [:public, :unlisted, :local, :private])
-      query = query.without_reblogs if account.present? && account&.user&.hides_boosts?
+      query = query.without_reblogs if account.present? && account&.user&.hide_boosts
       query
     end
 
@@ -448,8 +448,8 @@ class Status < ApplicationRecord
       query = query.without_replies unless Setting.show_replies_in_public_timelines
 
       if account.present? && account.local?
-        query = query.without_reblogs if account&.user&.hides_boosts?
-        query = query.only_followers_of(account) if account&.user&.shows_only_known?
+        query = query.without_reblogs if account&.user&.hide_boosts
+        query = query.only_followers_of(account) if account&.user&.only_known
       end
 
       apply_timeline_filters(query, account, local_only)
@@ -457,7 +457,7 @@ class Status < ApplicationRecord
 
     def as_tag_timeline(tag, account = nil, local_only = false, priv = false)
       query = tag_timeline_scope(account, local_only, priv).tagged_with(tag)
-      query = query.only_followers_of(account) if account.present? && account.local? && account&.user&.shows_only_known?
+      query = query.only_followers_of(account) if account.present? && account.local? && account&.user&.only_known?
       apply_timeline_filters(query, account, local_only, true)
     end
 
diff --git a/app/models/user.rb b/app/models/user.rb
index afea5be6d..59067cb36 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -39,6 +39,8 @@
 #  created_by_application_id :bigint(8)
 #  approved                  :boolean          default(TRUE), not null
 #  vars                      :jsonb            not null
+#  hide_boosts               :boolean
+#  only_known                :boolean
 #
 
 class User < ApplicationRecord
@@ -132,8 +134,6 @@ class User < ApplicationRecord
     :hide_mntions_blocker,
     :hide_mntions_packm8,
     :hide_mascot,
-    :hide_boosts,
-    :only_known,
     :hide_interactions,
     :hide_public_profile,
     :hide_public_outbox,
@@ -307,14 +307,6 @@ class User < ApplicationRecord
     @hides_mascot ||= (settings.hide_mascot || false)
   end
 
-  def hides_boosts?
-    @hides_boosts ||= (settings.hide_boosts || false)
-  end
-
-  def shows_only_known?
-    @only_known ||= (settings.only_known || false)
-  end
-
   def hides_interactions?
     @hides_interactions ||= (settings.hide_interactions || false)
   end
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index f45d66724..81bfc7345 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -47,8 +47,8 @@
 
   .fields-group
     = f.input :setting_rawr_federated, as: :boolean, wrapper: :with_label
-    = f.input :setting_hide_boosts, as: :boolean, wrapper: :with_label
-    = f.input :setting_only_known, as: :boolean, wrapper: :with_label
+    = f.input :hide_boosts, as: :boolean, wrapper: :with_label
+    = f.input :only_known, as: :boolean, wrapper: :with_label
 
   %hr/
 
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 2dcc25187..6983d0867 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -155,8 +155,6 @@ en:
         setting_hide_mntions_packm8: Filter group chat branches addressed to participants you aren't a packmate of
         setting_hide_mascot: Don't show the mascot image
         setting_hide_interactions: Make your roar interaction lists private
-        setting_hide_boosts: Don't show boosts on any timeline
-        setting_only_known: Only show posts from packmates on all timelines
         setting_aggregate_reblogs: Group repeats in timelines
         setting_auto_play_gif: Auto-play animated GIFs
         setting_boost_modal: Show confirmation dialog before repeating
@@ -182,6 +180,8 @@ en:
         setting_system_font_ui: Use system's default font
         setting_theme: Site theme
         setting_unfollow_modal: Show confirmation dialog before unfollowing someone
+        hide_boosts: Don't show boosts on any timeline
+        only_known: Only show posts from packmates on all timelines
         severity: Severity
         type: Import type
         username: Username
diff --git a/db/migrate/20191220020429_add_hide_boosts_to_users.rb b/db/migrate/20191220020429_add_hide_boosts_to_users.rb
new file mode 100644
index 000000000..95c1889e5
--- /dev/null
+++ b/db/migrate/20191220020429_add_hide_boosts_to_users.rb
@@ -0,0 +1,5 @@
+class AddHideBoostsToUsers < ActiveRecord::Migration[5.2]
+  def change
+    add_column :users, :hide_boosts, :boolean
+  end
+end
diff --git a/db/migrate/20191220020441_add_only_known_to_users.rb b/db/migrate/20191220020441_add_only_known_to_users.rb
new file mode 100644
index 000000000..5646b675c
--- /dev/null
+++ b/db/migrate/20191220020441_add_only_known_to_users.rb
@@ -0,0 +1,5 @@
+class AddOnlyKnownToUsers < ActiveRecord::Migration[5.2]
+  def change
+    add_column :users, :only_known, :boolean
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 603203c4f..81fc11630 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2019_12_12_043419) do
+ActiveRecord::Schema.define(version: 2019_12_20_020441) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pg_trgm"
@@ -807,6 +807,8 @@ ActiveRecord::Schema.define(version: 2019_12_12_043419) do
     t.bigint "created_by_application_id"
     t.boolean "approved", default: true, null: false
     t.jsonb "vars", default: {}, null: false
+    t.boolean "hide_boosts"
+    t.boolean "only_known"
     t.index ["account_id"], name: "index_users_on_account_id"
     t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
     t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id"
diff --git a/streaming/index.js b/streaming/index.js
index f3d75f443..20ec00d9f 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -202,7 +202,7 @@ const startWorker = (workerId) => {
         return;
       }
 
-      client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id, users.chosen_languages, oauth_access_tokens.scopes FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 AND oauth_access_tokens.revoked_at IS NULL LIMIT 1', [token], (err, result) => {
+      client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id, users.chosen_languages, users.hide_boosts, users.only_known, oauth_access_tokens.scopes FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 AND oauth_access_tokens.revoked_at IS NULL LIMIT 1', [token], (err, result) => {
         done();
 
         if (err) {
@@ -230,6 +230,8 @@ const startWorker = (workerId) => {
 
         req.accountId = result.rows[0].account_id;
         req.chosenLanguages = result.rows[0].chosen_languages;
+        req.hideBoosts = result.rows[0].hide_boosts;
+        req.onlyKnown = result.rows[0].only_known;
         req.allowNotifications = scopes.some(scope => ['read', 'read:notifications'].includes(scope));
 
         next();
@@ -393,6 +395,10 @@ const startWorker = (workerId) => {
       const targetAccountIds = [unpackedPayload.account.id].concat(unpackedPayload.mentions.map(item => item.id));
       const accountDomain    = unpackedPayload.account.acct.split('@')[1];
 
+      if (req.hideBoosts && (unpackedPayload.in_reply_to !== undefined || unpackedPayload.in_reply_to !== null)) {
+        return;
+      }
+
       if (Array.isArray(req.chosenLanguages) && unpackedPayload.language !== null && req.chosenLanguages.indexOf(unpackedPayload.language) === -1) {
         log.silly(req.requestId, `Message ${unpackedPayload.id} filtered by language (${unpackedPayload.language})`);
         return;
@@ -424,6 +430,10 @@ const startWorker = (workerId) => {
           queries.push(client.query('SELECT 1 FROM account_domain_blocks WHERE account_id = $1 AND domain = $2', [req.accountId, accountDomain]));
         }
 
+        if (req.onlyKnown) {
+          queries.push(client.query('SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM follows WHERE account_id = $1 AND target_account_id = $2)', [req.accountId, unpackedPayload.account.id]));
+        }
+
         Promise.all(queries).then(values => {
           done();