From 2547caeb7d099a29d7e78fd17a132189c8896976 Mon Sep 17 00:00:00 2001
From: Mint <mint@plagu.ee>
Date: Thu, 24 Aug 2023 13:30:52 +0300
Subject: [PATCH] Revert recursive lockfagging

---
 src/boot/after_store.js                       |  1 +
 .../post_status_form/post_status_form.js      | 21 +++++++----------
 .../scope_selector/scope_selector.js          | 23 ++++---------------
 .../settings_modal/tabs/general_tab.vue       |  8 +++++++
 src/modules/config.js                         |  1 +
 src/modules/instance.js                       |  1 +
 6 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index d45584c0..ddbcb9dd 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -175,6 +175,7 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => {
   copyInstanceOption('showInstanceSpecificPanel')
   copyInstanceOption('hideMutedPosts')
   copyInstanceOption('collapseMessageWithSubject')
+  copyInstanceOption('scopeCopy')
   copyInstanceOption('subjectLineBehavior')
   copyInstanceOption('postContentType')
   copyInstanceOption('alwaysShowSubjectInput')
diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js
index 5647a9eb..ff2e80f1 100644
--- a/src/components/post_status_form/post_status_form.js
+++ b/src/components/post_status_form/post_status_form.js
@@ -133,11 +133,17 @@ const PostStatusForm = {
     const preset = this.$route.query.message
     let statusText = preset || ''

+    const { scopeCopy } = this.$store.getters.mergedConfig
+
     if (this.replyTo || this.quoteId) {
       const currentUser = this.$store.state.users.currentUser
       statusText = buildMentionsString({ user: this.repliedUser, attentions: this.attentions }, currentUser)
     }

+    const scope = ((this.copyMessageScope && scopeCopy) || this.copyMessageScope === 'direct')
+      ? this.copyMessageScope
+      : this.$store.state.users.currentUser.default_scope
+
     const { postContentType: contentType, sensitiveByDefault, sensitiveIfSubject, interfaceLanguage } = this.$store.getters.mergedConfig

     let statusParams = {
@@ -148,7 +154,7 @@ const PostStatusForm = {
       files: [],
       poll: {},
       mediaDescriptions: {},
-      visibility: this.suggestedVisibility(),
+      visibility: scope,
       language: interfaceLanguage,
       contentType
     }
@@ -163,7 +169,7 @@ const PostStatusForm = {
         files: this.statusFiles || [],
         poll: this.statusPoll || {},
         mediaDescriptions: this.statusMediaDescriptions || {},
-        visibility: this.statusScope || this.suggestedVisibility(),
+        visibility: this.statusScope,
         language: this.statusLanguage || interfaceLanguage,
         contentType: statusContentType
       }
@@ -714,17 +720,6 @@ const PostStatusForm = {
     },
     openProfileTab () {
       this.$store.dispatch('openSettingsModalTab', 'profile')
-    },
-    suggestedVisibility () {
-      if (this.copyMessageScope) {
-        if (this.copyMessageScope === 'direct') {
-          return this.copyMessageScope
-        }
-        if (this.copyMessageScope !== 'public' && this.$store.state.users.currentUser.default_scope !== 'private') {
-          return this.copyMessageScope
-        }
-      }
-      return this.$store.state.users.currentUser.default_scope
     }
   }
 }
diff --git a/src/components/scope_selector/scope_selector.js b/src/components/scope_selector/scope_selector.js
index 8ec7d332..ed37d933 100644
--- a/src/components/scope_selector/scope_selector.js
+++ b/src/components/scope_selector/scope_selector.js
@@ -13,17 +13,8 @@ library.add(
   faLockOpen
 )

-const SCOPE_LEVELS = {
-  'direct': 0,
-  'private': 1,
-  'local': 2,
-  'unlisted': 2,
-  'public': 3
-}
-
 const ScopeSelector = {
   props: [
-    'showAll',
     'userDefault',
     'originalScope',
     'initialScope',
@@ -65,15 +56,11 @@ const ScopeSelector = {
   },
   methods: {
     shouldShow (scope) {
-      if (!this.originalScope) {
-        return true
-      }
-
-      if (this.originalScope === 'local') {
-        return scope === 'direct' || scope === 'local'
-      }
-
-      return SCOPE_LEVELS[scope] <= SCOPE_LEVELS[this.originalScope]
+      return true ||
+        this.currentScope === scope ||
+        this.originalScope === scope ||
+        this.userDefault === scope ||
+        scope === 'direct'
     },
     changeVis (scope) {
       this.currentScope = scope
diff --git a/src/components/settings_modal/tabs/general_tab.vue b/src/components/settings_modal/tabs/general_tab.vue
index 7dc1c3f1..a550cd7a 100644
--- a/src/components/settings_modal/tabs/general_tab.vue
+++ b/src/components/settings_modal/tabs/general_tab.vue
@@ -561,6 +561,14 @@
             {{ $t('settings.sensitive_if_subject') }}
           </BooleanSetting>
         </li>
+        <li>
+          <BooleanSetting
+            path="scopeCopy"
+            expert="1"
+          >
+            {{ $t('settings.scope_copy') }}
+          </BooleanSetting>
+        </li>
         <li>
           <BooleanSetting
             path="alwaysShowSubjectInput"
diff --git a/src/modules/config.js b/src/modules/config.js
index ebb27929..3fa8c497 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -76,6 +76,7 @@ export const defaultState = {
   hideScopeNotice: false,
   useStreamingApi: false,
   sidebarRight: undefined, // instance default
+  scopeCopy: undefined, // instance default
   subjectLineBehavior: undefined, // instance default
   alwaysShowSubjectInput: undefined, // instance default
   postContentType: undefined, // instance default
diff --git a/src/modules/instance.js b/src/modules/instance.js
index 02cbe1f8..dffede8e 100644
--- a/src/modules/instance.js
+++ b/src/modules/instance.js
@@ -57,6 +57,7 @@ const defaultState = {
   postContentType: 'text/plain',
   redirectRootLogin: '/main/friends',
   redirectRootNoLogin: '/main/all',
+  scopeCopy: false,
   showFeaturesPanel: true,
   showInstanceSpecificPanel: false,
   showNavShortcuts: true,
--
2.41.0

