From 35db61f1b4f00640f26d31135b91d42543795825 Mon Sep 17 00:00:00 2001
From: MeiMei <30769358+mei23@users.noreply.github.com>
Date: Sat, 17 Nov 2018 13:21:40 +0900
Subject: [PATCH] To able to store local only visibilities (#3298)

---
 .../desktop/views/components/post-form.vue    | 25 +++++++++------
 .../app/desktop/views/components/settings.vue |  3 ++
 .../app/mobile/views/components/post-form.vue | 32 ++++++++-----------
 .../app/mobile/views/pages/settings.vue       |  3 ++
 4 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/client/app/desktop/views/components/post-form.vue b/src/client/app/desktop/views/components/post-form.vue
index 2a3b9c1511..128470a0d6 100644
--- a/src/client/app/desktop/views/components/post-form.vue
+++ b/src/client/app/desktop/views/components/post-form.vue
@@ -111,7 +111,7 @@ export default Vue.extend({
 			useCw: false,
 			cw: null,
 			geo: null,
-			visibility: this.$store.state.settings.rememberNoteVisibility ? (this.$store.state.device.visibility || this.$store.state.settings.defaultNoteVisibility) : this.$store.state.settings.defaultNoteVisibility,
+			visibility: 'public',
 			visibleUsers: [],
 			localOnly: false,
 			autocomplete: null,
@@ -195,6 +195,9 @@ export default Vue.extend({
 			});
 		}
 
+		// デフォルト公開範囲
+		this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? (this.$store.state.device.visibility || this.$store.state.settings.defaultNoteVisibility) : this.$store.state.settings.defaultNoteVisibility);
+
 		// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
 		if (this.reply && ['home', 'followers', 'specified', 'private'].includes(this.reply.visibility)) {
 			this.visibility = this.reply.visibility;
@@ -365,17 +368,21 @@ export default Vue.extend({
 				source: this.$refs.visibilityButton
 			});
 			w.$once('chosen', v => {
-				const m = v.match(/^local-(.+)/);
-				if (m) {
-					this.localOnly = true;
-					this.visibility = m[1];
-				} else {
-					this.localOnly = false;
-					this.visibility = v;
-				}
+				this.applyVisibility(v);
 			});
 		},
 
+		applyVisibility(v :string) {
+			const m = v.match(/^local-(.+)/);
+			if (m) {
+				this.localOnly = true;
+				this.visibility = m[1];
+			} else {
+				this.localOnly = false;
+				this.visibility = v;
+			}
+		},
+
 		addVisibleUser() {
 			this.$input({
 				title: this.$t('enter-username')
diff --git a/src/client/app/desktop/views/components/settings.vue b/src/client/app/desktop/views/components/settings.vue
index 1c3f0e8cc4..62106768b5 100644
--- a/src/client/app/desktop/views/components/settings.vue
+++ b/src/client/app/desktop/views/components/settings.vue
@@ -85,6 +85,9 @@
 						<option value="followers">{{ $t('@.note-visibility.followers') }}</option>
 						<option value="specified">{{ $t('@.note-visibility.specified') }}</option>
 						<option value="private">{{ $t('@.note-visibility.private') }}</option>
+						<option value="local-public">{{ $t('@.note-visibility.local-public') }}</option>
+						<option value="local-home">{{ $t('@.note-visibility.local-home') }}</option>
+						<option value="local-followers">{{ $t('@.note-visibility.local-followers') }}</option>
 					</ui-select>
 				</section>
 			</section>
diff --git a/src/client/app/mobile/views/components/post-form.vue b/src/client/app/mobile/views/components/post-form.vue
index f941c59d9f..de389baf69 100644
--- a/src/client/app/mobile/views/components/post-form.vue
+++ b/src/client/app/mobile/views/components/post-form.vue
@@ -100,7 +100,7 @@ export default Vue.extend({
 			files: [],
 			poll: false,
 			geo: null,
-			visibility: this.$store.state.settings.rememberNoteVisibility ? (this.$store.state.device.visibility || this.$store.state.settings.defaultNoteVisibility) : this.$store.state.settings.defaultNoteVisibility,
+			visibility: 'public',
 			visibleUsers: [],
 			localOnly: false,
 			useCw: false,
@@ -184,6 +184,9 @@ export default Vue.extend({
 			});
 		}
 
+		// デフォルト公開範囲
+		this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? (this.$store.state.device.visibility || this.$store.state.settings.defaultNoteVisibility) : this.$store.state.settings.defaultNoteVisibility);
+
 		// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
 		if (this.reply && ['home', 'followers', 'specified', 'private'].includes(this.reply.visibility)) {
 			this.visibility = this.reply.visibility;
@@ -275,26 +278,19 @@ export default Vue.extend({
 				compact: true
 			});
 			w.$once('chosen', v => {
-				const m = v.match(/^local-(.+)/);
-				if (m) {
-					this.localOnly = true;
-					this.visibility = m[1];
-				} else {
-					this.localOnly = false;
-					this.visibility = v;
-				}
+				this.applyVisibility(v);
 			});
 		},
 
-		addVisibleUser() {
-			this.$input({
-				title: this.$t('username-prompt')
-			}).then(acct => {
-				if (acct.startsWith('@')) acct = acct.substr(1);
-				this.$root.api('users/show', parseAcct(acct)).then(user => {
-					this.visibleUsers.push(user);
-				});
-			});
+		applyVisibility(v :string) {
+			const m = v.match(/^local-(.+)/);
+			if (m) {
+				this.localOnly = true;
+				this.visibility = m[1];
+			} else {
+				this.localOnly = false;
+				this.visibility = v;
+			}
 		},
 
 		removeVisibleUser(user) {
diff --git a/src/client/app/mobile/views/pages/settings.vue b/src/client/app/mobile/views/pages/settings.vue
index 0d61f39bb7..0f54933925 100644
--- a/src/client/app/mobile/views/pages/settings.vue
+++ b/src/client/app/mobile/views/pages/settings.vue
@@ -80,6 +80,9 @@
 							<option value="followers">{{ $t('@.note-visibility.followers') }}</option>
 							<option value="specified">{{ $t('@.note-visibility.specified') }}</option>
 							<option value="private">{{ $t('@.note-visibility.private') }}</option>
+							<option value="local-public">{{ $t('@.note-visibility.local-public') }}</option>
+							<option value="local-home">{{ $t('@.note-visibility.local-home') }}</option>
+							<option value="local-followers">{{ $t('@.note-visibility.local-followers') }}</option>
 						</ui-select>
 					</section>
 				</section>