]> cat aescling's git repositories - mastodon.git/commitdiff
Make storing and displaying application used to toot opt-in
authorThibaut Girka <thib@sitedethib.com>
Mon, 21 Jan 2019 18:36:33 +0000 (19:36 +0100)
committerThibG <thib@sitedethib.com>
Sun, 27 Jan 2019 12:56:41 +0000 (13:56 +0100)
app/controllers/settings/preferences_controller.rb
app/lib/user_settings_decorator.rb
app/models/account.rb
app/models/user.rb
app/serializers/rest/status_serializer.rb
app/services/post_status_service.rb
app/views/settings/preferences/show.html.haml
app/views/stream_entries/_detailed_status.html.haml
config/locales/simple_form.en.yml
config/settings.yml

index d4932afd60f7a8e4a0adc4fd9705a1d86805cda8..241053261b895fe412062ece7eef23f8cb78323a 100644 (file)
@@ -45,6 +45,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_hide_network,
       :setting_hide_followers_count,
       :setting_aggregate_reblogs,
+      :setting_show_application,
       notification_emails: %i(follow follow_request reblog favourite mention digest report),
       interactions: %i(must_be_follower must_be_following)
     )
index 569255f6ea58cf4c5fe7b063aea13357bca92e2b..367ba9a83b67fb7e49b2262b553bdd68ece1a842 100644 (file)
@@ -35,6 +35,7 @@ class UserSettingsDecorator
     user.settings['skin']                = skin_preference if change?('setting_skin')
     user.settings['hide_network']        = hide_network_preference if change?('setting_hide_network')
     user.settings['aggregate_reblogs']   = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
+    user.settings['show_application']    = show_application_preference if change?('setting_show_application')
   end
 
   def merged_notification_emails
@@ -109,6 +110,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_hide_network'
   end
 
+  def show_application_preference
+    boolean_cast_setting 'setting_show_application'
+  end
+
   def default_language_preference
     settings['setting_default_language']
   end
index 1ee63c7388d3e2a8bca74b7fb7019de1d8e42b4d..c86c6fdb5a05113b2092806401234ae1a88e2a49 100644 (file)
@@ -113,6 +113,7 @@ class Account < ApplicationRecord
            :staff?,
            :locale,
            :hides_network?,
+           :shows_application?,
            to: :user,
            prefix: true,
            allow_nil: true
index fbb6545dbbca543c35368df91fb45e35603a5dd5..ce9ef2a137ffb661894577680fe3551cbd18b4f9 100644 (file)
@@ -100,7 +100,7 @@ class User < ApplicationRecord
 
   delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
            :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count,
-           :expand_spoilers, :default_language, :aggregate_reblogs, to: :settings, prefix: :setting, allow_nil: false
+           :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, to: :settings, prefix: :setting, allow_nil: false
 
   attr_reader :invite_code
 
@@ -244,6 +244,10 @@ class User < ApplicationRecord
     @aggregates_reblogs ||= settings.aggregate_reblogs
   end
 
+  def shows_application?
+    @shows_application ||= settings.shows_application
+  end
+
   def token_for_app(a)
     return nil if a.nil? || a.owner != self
     Doorkeeper::AccessToken
index dd8482eea28bb5f99fcfddfbf488bc6c1314d574..f2b5febaefd42f0cac4b935274eacbe4b8adf841 100644 (file)
@@ -14,7 +14,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
   attribute :local_only if :local?
 
   belongs_to :reblog, serializer: REST::StatusSerializer
-  belongs_to :application
+  belongs_to :application, if: :user_shows_application?
   belongs_to :account, serializer: REST::AccountSerializer
 
   has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
@@ -40,6 +40,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
     !current_user.nil?
   end
 
+  def user_shows_application?
+    object.account.user_shows_application?
+  end
+
   def visibility
     # This visibility is masked behind "private"
     # to avoid API changes because there are no
index e4b61ee35f8b54504c84c04bc4afa60d93f5755a..24a85337340aa39ed80a362943adf51107886c88 100644 (file)
@@ -22,6 +22,7 @@ class PostStatusService < BaseService
     @options     = options
     @text        = @options[:text] || ''
     @in_reply_to = @options[:thread]
+    @options.delete(:application) unless @account.user&.setting_show_application
 
     return idempotency_duplicate if idempotency_given? && idempotency_duplicate?
 
index 6510e0560b922fbdc4bb7be7b9371849d44f8e5c..c666bafb50c851619d6ad025c380c6d1ec00101c 100644 (file)
@@ -34,6 +34,9 @@
   .fields-group
     = f.input :setting_hide_network, as: :boolean, wrapper: :with_label
 
+  .fields-group
+    = f.input :setting_show_application, as: :boolean, wrapper: :with_label
+
   - unless Setting.hide_followers_count
     .fields-group
       = f.input :setting_hide_followers_count, as: :boolean, wrapper: :with_label
index 18265e1107126e25d4b03a5a460e2e04b0349ff7..e123d657fa74e16e3cd44321c33a3a8a634aed5b 100644 (file)
@@ -39,7 +39,7 @@
     = link_to TagManager.instance.url_for(status), class: 'detailed-status__datetime u-url u-uid', target: stream_link_target, rel: 'noopener' do
       %time.formatted{ datetime: status.created_at.iso8601, title: l(status.created_at) }= l(status.created_at)
     ยท
-    - if status.application
+    - if status.application && @account.user&.setting_show_application
       - if status.application.website.blank?
         %strong.detailed-status__application= status.application.name
       - else
index c75471658343d17627fa3c262ba3496d88b7bf11..674abff6338f1479a32a1a40e7279826187402d8 100644 (file)
@@ -33,6 +33,7 @@ en:
         setting_display_media_show_all: Always show media marked as sensitive
         setting_hide_network: Who you follow and who follows you will not be shown on your profile
         setting_noindex: Affects your public profile and status pages
+        setting_show_application: The application you use to toot will be displayed in the detailed view of your toots
         setting_skin: Reskins the selected Mastodon flavour
         username: Your username will be unique on %{domain}
         whole_word: When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word
@@ -102,6 +103,7 @@ en:
         setting_hide_network: Hide your network
         setting_noindex: Opt-out of search engine indexing
         setting_reduce_motion: Reduce motion in animations
+        setting_show_application: Disclose application used to send toots
         setting_skin: Skin
         setting_system_font_ui: Use system's default font
         setting_unfollow_modal: Show confirmation dialog before unfollowing someone
index 4f070240adfc0c5f636e984f44960ad98662f788..af596b738df64f6f8d05659fd3e083c5cd2e1b25 100644 (file)
@@ -27,6 +27,7 @@ defaults: &defaults
   expand_spoilers: false
   preview_sensitive_media: false
   reduce_motion: false
+  show_application: false
   system_font_ui: false
   noindex: false
   hide_followers_count: false