From 467170f4a095c5c794ae4d8f46b5d57205590013 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Fri, 8 Mar 2019 06:01:17 +0000 Subject: [PATCH] more local-only options --- app/controllers/settings/preferences_controller.rb | 1 + app/javascript/flavours/glitch/actions/compose.js | 2 +- app/javascript/flavours/glitch/reducers/compose.js | 10 +++++----- app/javascript/flavours/glitch/util/initial_state.js | 1 + app/lib/user_settings_decorator.rb | 5 +++++ app/models/status.rb | 8 ++------ app/models/user.rb | 6 +++++- app/serializers/initial_state_serializer.rb | 1 + app/views/settings/preferences/show.html.haml | 1 + config/locales/simple_form.en.yml | 5 +++-- 10 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index c75528ce4..bd2ab8113 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -31,6 +31,7 @@ class Settings::PreferencesController < Settings::BaseController params.require(:user).permit( :setting_default_privacy, :setting_default_local, + :setting_alwyas_local, :setting_default_sensitive, :setting_default_language, :setting_unfollow_modal, diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 2fb97fa17..103d7aefa 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -144,7 +144,7 @@ export function submitCompose(routerHistory) { dispatch(submitComposeRequest()); if (getState().getIn(['compose', 'advanced_options', 'do_not_federate'])) { - status = status + ' 👁️'; + status = status + ' #!'; } api(getState).post('/api/v1/statuses', { status, diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index 8bb1aa642..e9d59e366 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -45,7 +45,7 @@ import { REDRAFT } from 'flavours/glitch/actions/statuses'; import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; import uuid from 'flavours/glitch/util/uuid'; import { privacyPreference } from 'flavours/glitch/util/privacy_preference'; -import { me, defaultContentType, defaultLocal } from 'flavours/glitch/util/initial_state'; +import { me, defaultContentType, defaultLocal, alwaysLoal } from 'flavours/glitch/util/initial_state'; import { overwrite } from 'flavours/glitch/util/js_helpers'; import { unescapeHTML } from 'flavours/glitch/util/html'; import { recoverHashtags } from 'flavours/glitch/util/hashtag'; @@ -59,7 +59,7 @@ const glitchProbability = 1 - 0.0420215528; const initialState = ImmutableMap({ mounted: false, advanced_options: ImmutableMap({ - do_not_federate: defaultLocal, + do_not_federate: defaultLocal || alwaysLocal, threaded_mode: false, }), sensitive: false, @@ -82,7 +82,7 @@ const initialState = ImmutableMap({ suggestion_token: null, suggestions: ImmutableList(), default_advanced_options: ImmutableMap({ - do_not_federate: null, + do_not_federate: alwaysLocal || null, threaded_mode: null, // Do not reset }), default_privacy: 'public', @@ -177,7 +177,7 @@ function continueThread (state, status) { map.set('in_reply_to', status.id); map.update( 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate: /👁\ufe0f?\u200b?(?:<\/p>)?$/.test(status.content) })) + map => map.merge(new ImmutableMap({ do_not_federate: /#!\u200b?(?:<\/p>)?$/.test(status.content) })) ); map.set('privacy', status.visibility); map.set('sensitive', false); @@ -331,7 +331,7 @@ export default function compose(state = initialState, action) { map.set('privacy', privacyPreference(action.status.get('visibility'), state.get('default_privacy'))); map.update( 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate: /👁\ufe0f?\u200b?(?:<\/p>)?$/.test(action.status.get('content')) })) + map => map.merge(new ImmutableMap({ do_not_federate: /#!(?:<\/p>)?$/.test(action.status.get('content')) })) ); map.set('focusDate', new Date()); map.set('caretPosition', null); diff --git a/app/javascript/flavours/glitch/util/initial_state.js b/app/javascript/flavours/glitch/util/initial_state.js index 7a60d21b2..ce361051f 100644 --- a/app/javascript/flavours/glitch/util/initial_state.js +++ b/app/javascript/flavours/glitch/util/initial_state.js @@ -21,6 +21,7 @@ export const favouriteModal = getMeta('favourite_modal'); export const deleteModal = getMeta('delete_modal'); export const me = getMeta('me'); export const defaultLocal = getMeta('default_local'); +export const alwaysLocal = getMeta('always_local'); export const searchEnabled = getMeta('search_enabled'); export const maxChars = (initialState && initialState.max_toot_chars) || 500; export const pollLimits = (initialState && initialState.poll_limits); diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 9358dad68..8ae5664dd 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -19,6 +19,7 @@ class UserSettingsDecorator user.settings['interactions'] = merged_interactions if change?('interactions') user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy') user.settings['default_local'] = default_local_preference if change?('setting_default_local') + user.settings['always_local'] = always_local_preference if change?('setting_always_local') user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive') user.settings['default_language'] = default_language_preference if change?('setting_default_language') user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal') @@ -56,6 +57,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_default_local' end + def always_local_preference + boolean_cast_setting 'setting_always_local' + end + def default_sensitive_preference boolean_cast_setting 'setting_default_sensitive' end diff --git a/app/models/status.rb b/app/models/status.rb index cbb89bd16..4dd889485 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -508,11 +508,7 @@ class Status < ApplicationRecord def marked_local_only? # match both with and without U+FE0F (the emoji variation selector) - /#{local_only_emoji}\ufe0f?\z/.match?(content) - end - - def local_only_emoji - '👁' + /#!\z/.match?(content) end def marked_no_replies? @@ -560,7 +556,7 @@ class Status < ApplicationRecord def set_locality if account.domain.nil? && !attribute_changed?(:local_only) - self.local_only = marked_local_only? + self.local_only = marked_local_only? || account.user.setting_always_local end end diff --git a/app/models/user.rb b/app/models/user.rb index b1da03d02..ebf3fa422 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -102,7 +102,7 @@ class User < ApplicationRecord has_many :session_activations, dependent: :destroy - delegate :auto_play_gif, :default_local, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal, + delegate :auto_play_gif, :default_local, :always_local, :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, :show_application, :default_content_type, to: :settings, prefix: :setting, allow_nil: false @@ -192,6 +192,10 @@ class User < ApplicationRecord settings.default_local || false end + def setting_always_local + settings.always_local || false + end + def allows_digest_emails? settings.notification_emails['digest'] end diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 6146ff32e..b951696da 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -39,6 +39,7 @@ class InitialStateSerializer < ActiveModel::Serializer if object.current_account store[:me] = object.current_account.id.to_s store[:default_local] = object.current_account.user.setting_default_local + store[:always_local] = object.current_account.user.setting_always_local store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal store[:boost_modal] = object.current_account.user.setting_boost_modal store[:favourite_modal] = object.current_account.user.setting_favourite_modal diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index a55d427db..2ed325b19 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -28,6 +28,7 @@ = f.input :setting_default_content_type, collection: ['text/plain', 'text/markdown', 'text/html'], wrapper: :with_label, include_blank: false, label_method: lambda { |item| safe_join([t("simple_form.labels.defaults.setting_default_content_type_#{item.split('/')[1]}"), content_tag(:span, t("simple_form.hints.defaults.setting_default_content_type_#{item.split('/')[1]}"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' = f.input :setting_default_local, as: :boolean, wrapper: :with_label + = f.input :setting_always_local, as: :boolean, wrapper: :with_label = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label %hr#settings_other/ diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index df5f4d3c6..e13a77902 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -102,7 +102,8 @@ en: setting_default_content_type_plain: Plain text setting_default_language: Posting language setting_default_privacy: Post privacy - setting_default_local: Default to local only + setting_default_local: Default to Monsterpit-only roars (in Glitch flavour) + setting_always_local: Don't send your roars outside Monsterpit setting_default_sensitive: Always mark media as sensitive setting_delete_modal: Show confirmation dialog before deleting a roar setting_display_media: Media display @@ -110,7 +111,7 @@ en: setting_display_media_hide_all: Hide all setting_display_media_show_all: Show all setting_expand_spoilers: Always expand roars marked with content warnings - setting_favourite_modal: Show confirmation dialog before admiring (applies to Glitch flavour only) + setting_favourite_modal: Show confirmation dialog before admiring (in Glitch flavour) setting_hide_followers_count: Hide your packmates count setting_hide_network: Hide your packmates setting_noindex: Opt-out of search engine indexing