From 190d1bbf3c5aadc2d929c99056928b33e4834d5a Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Mon, 19 Oct 2020 14:46:55 +0900
Subject: デフォルト公開範囲が機能していない問題を修正
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/client/components/post-form.vue | 56 +++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

(limited to 'src/client/components/post-form.vue')

diff --git a/src/client/components/post-form.vue b/src/client/components/post-form.vue
index ba7770345a..ccca4b54a6 100644
--- a/src/client/components/post-form.vue
+++ b/src/client/components/post-form.vue
@@ -125,7 +125,7 @@ export default defineComponent({
 		},
 	},
 
-	emits: ['posted', 'done', 'esc'],
+	emits: ['posted', 'cancel', 'esc'],
 
 	data() {
 		return {
@@ -135,8 +135,8 @@ export default defineComponent({
 			poll: null,
 			useCw: false,
 			cw: null,
-			localOnly: false,
-			visibility: 'public',
+			localOnly: this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.localOnly : this.$store.state.settings.defaultNoteLocalOnly,
+			visibility: this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.visibility : this.$store.state.settings.defaultNoteVisibility,
 			visibleUsers: [],
 			autocomplete: null,
 			draghover: false,
@@ -202,12 +202,6 @@ export default defineComponent({
 		}
 	},
 
-	watch: {
-		localOnly() {
-			this.$store.commit('deviceUser/setLocalOnly', this.localOnly);
-		}
-	},
-
 	mounted() {
 		if (this.initialText) {
 			this.text = this.initialText;
@@ -239,11 +233,9 @@ export default defineComponent({
 			}
 		}
 
-		// デフォルト公開範囲
-		if (this.channel == null) {
-			this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.visibility : this.$store.state.settings.defaultNoteVisibility);
-
-			this.localOnly = this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.localOnly : this.$store.state.settings.defaultNoteLocalOnly;
+		if (this.channel) {
+			this.visibility = 'public';
+			this.localOnly = true; // TODO: チャンネルが連合するようになった折には消す
 		}
 
 		// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
@@ -295,7 +287,7 @@ export default defineComponent({
 					this.text = draft.data.text;
 					this.useCw = draft.data.useCw;
 					this.cw = draft.data.cw;
-					this.applyVisibility(draft.data.visibility);
+					this.visibility = draft.data.visibility;
 					this.localOnly = draft.data.localOnly;
 					this.files = (draft.data.files || []).filter(e => e);
 					if (draft.data.poll) {
@@ -398,18 +390,20 @@ export default defineComponent({
 				src: this.$refs.visibilityButton
 			}, {
 				changeVisibility: visibility => {
-					this.applyVisibility(visibility);
+					this.visibility = visibility;
+					if (this.$store.state.settings.rememberNoteVisibility) {
+						this.$store.commit('deviceUser/setVisibility', visibility);
+					}
 				},
 				changeLocalOnly: localOnly => {
 					this.localOnly = localOnly;
+					if (this.$store.state.settings.rememberNoteVisibility) {
+						this.$store.commit('deviceUser/setLocalOnly', localOnly);
+					}
 				}
 			}, 'closed');
 		},
 
-		applyVisibility(v: string) {
-			this.visibility = (noteVisibilities as unknown as string[]).includes(v) ? v : 'public'; // v11互換性のため
-		},
-
 		addVisibleUser() {
 			os.selectUser().then(user => {
 				this.visibleUsers.push(user);
@@ -556,23 +550,23 @@ export default defineComponent({
 			this.posting = true;
 			os.api('notes/create', data).then(() => {
 				this.clear();
-				this.deleteDraft();
-				this.$emit('posted');
+				this.$nextTick(() => {
+					this.deleteDraft();
+					this.$emit('posted');
+					if (this.text && this.text != '') {
+						const hashtags = parse(this.text).filter(x => x.node.type === 'hashtag').map(x => x.node.props.hashtag);
+						const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
+						localStorage.setItem('hashtags', JSON.stringify(unique(hashtags.concat(history))));
+					}
+					this.posting = false;
+				});
 			}).catch(err => {
-			}).then(() => {
 				this.posting = false;
-				this.$emit('done');
 			});
-
-			if (this.text && this.text != '') {
-				const hashtags = parse(this.text).filter(x => x.node.type === 'hashtag').map(x => x.node.props.hashtag);
-				const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
-				localStorage.setItem('hashtags', JSON.stringify(unique(hashtags.concat(history))));
-			}
 		},
 
 		cancel() {
-			this.$emit('done');
+			this.$emit('cancel');
 		},
 
 		insertMention() {
-- 
cgit v1.2.3-freya

