From 334368f6e22872a38835e5712ff4939e789a3691 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 4 Jan 2023 21:39:33 +0100 Subject: [PATCH] fix: allow to pick higher visibility than chosen before If you selected a lower visibility that one would then be used as the parent visibility. Instead it is necessary to use two separate variables, one for parent and one for the preselected visibility. --- packages/client/src/components/post-form.vue | 26 ++++++++++++++----- .../src/components/visibility-picker.vue | 5 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index a22235ee3..d929d8d32 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -133,6 +133,11 @@ let poll = $ref<{ let useCw = $ref(false); let showPreview = $ref(false); let cw = $ref(null); + +// these define the "maximum" these parameters can be set to and will be tightened further down +let parentLocalOnly = false; +let parentVisibility = 'public'; + let localOnly = $ref(props.initialLocalOnly ?? defaultStore.state.defaultNoteLocalOnly); let visibility = $ref(props.initialVisibility ?? defaultStore.state.defaultNoteVisibility as foundkey.NoteVisibility); let visibleUsers = $ref([]); @@ -251,12 +256,11 @@ if (props.reply && props.reply.text != null) { } if (props.channel) { - visibility = 'public'; - localOnly = true; // TODO: チャンネルが連合するようになった折には消す + parentLocalOnly = true; // TODO: remove when channels are federated } if (props.reply) { - visibility = foundkey.minVisibility(props.reply.visibility, visibility); + parentVisibility = foundkey.minVisibility(props.reply.visibility, parentVisibility); if (props.reply.visibility === 'specified') { os.api('users/show', { userIds: props.reply.visibleUserIds.filter(uid => uid !== $i.id && uid !== props.reply.userId), @@ -270,10 +274,11 @@ if (props.reply) { }); } } + parentLocalOnly ||= props.reply.localOnly; } if (props.renote) { - visibility = foundkey.minVisibility(props.renote.visibility, visibility); + parentVisibility = foundkey.minVisibility(props.renote.visibility, parentVisibility); if (props.renote.visibility === 'specified') { os.api('users/show', { userIds: props.renote.visibleUserIds.filter(uid => uid !== $i.id && uid !== props.renote.userId), @@ -287,13 +292,18 @@ if (props.renote) { }); } } + parentLocalOnly ||= props.renote.localOnly; } if (props.specified) { - visibility = 'specified'; + parentVisibility = 'specified'; pushVisibleUser(props.specified); } +// set visibility and local only defaults to minimum of preselected or allowed. +visibility = foundkey.minVisibility(visibility, parentVisibility); +localOnly ||= parentLocalOnly; + // keep cw when reply if (defaultStore.state.keepCw && props.reply && props.reply.cw) { useCw = true; @@ -393,8 +403,10 @@ function setVisibility() { } os.popup(defineAsyncComponent(() => import('./visibility-picker.vue')), { - parentVisibility: visibility, - parentLocalOnly: localOnly, + parentVisibility, + parentLocalOnly, + currentVisibility: visibility, + currentLocalOnly: localOnly, src: visibilityButton, }, { changeVisibility: v => { diff --git a/packages/client/src/components/visibility-picker.vue b/packages/client/src/components/visibility-picker.vue index 4321a6982..50a6ff667 100644 --- a/packages/client/src/components/visibility-picker.vue +++ b/packages/client/src/components/visibility-picker.vue @@ -53,6 +53,7 @@ const modal = $ref>(); const props = withDefaults(defineProps<{ parentVisibility: foundkey.NoteVisibility; parentLocalOnly: boolean; + currentVisibility: foundkey.NoteVisibility; currentLocalOnly: boolean; src?: HTMLElement; }>(), { @@ -64,8 +65,8 @@ const emit = defineEmits<{ (ev: 'closed'): void; }>(); -let v = $ref(props.parentVisibility); -let localOnly = $ref(props.parentLocalOnly); +let v = $ref(props.currentVisibility); +let localOnly = $ref(props.currentLocalOnly); const disabled = foundkey.noteVisibilities.reduce((acc, visibility) => { acc[visibility] = (visibility !== foundkey.minVisibility(visibility, props.parentVisibility));