From bfc95ccf730602e44d312a1d561229123f33611c Mon Sep 17 00:00:00 2001 From: nullobsi Date: Tue, 1 Feb 2022 04:49:34 -0800 Subject: [PATCH] fix: ensure that specified users does not get duplicates (#8233) * ensure that specified users does not get duplicates * Update packages/client/src/components/post-form.vue Co-authored-by: syuilo Co-authored-by: syuilo --- packages/client/src/components/post-form.vue | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index 6db4d926da..535218ecf9 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -135,7 +135,10 @@ let showPreview = $ref(false); let cw = $ref(null); let localOnly = $ref(props.initialLocalOnly ?? defaultStore.state.rememberNoteVisibility ? defaultStore.state.localOnly : defaultStore.state.defaultNoteLocalOnly); let visibility = $ref(props.initialVisibility ?? (defaultStore.state.rememberNoteVisibility ? defaultStore.state.visibility : defaultStore.state.defaultNoteVisibility) as typeof misskey.noteVisibilities[number]); -let visibleUsers = $ref(props.initialVisibleUsers ?? []); +let visibleUsers = $ref([]); +if (props.initialVisibleUsers) { + props.initialVisibleUsers.forEach(pushVisibleUser); +} let autocomplete = $ref(null); let draghover = $ref(false); let quoteId = $ref(null); @@ -262,12 +265,12 @@ if (props.reply && ['home', 'followers', 'specified'].includes(props.reply.visib os.api('users/show', { userIds: props.reply.visibleUserIds.filter(uid => uid !== $i.id && uid !== props.reply.userId) }).then(users => { - visibleUsers.push(...users); + users.forEach(pushVisibleUser); }); if (props.reply.userId !== $i.id) { os.api('users/show', { userId: props.reply.userId }).then(user => { - visibleUsers.push(user); + pushVisibleUser(user); }); } } @@ -275,7 +278,7 @@ if (props.reply && ['home', 'followers', 'specified'].includes(props.reply.visib if (props.specified) { visibility = 'specified'; - visibleUsers.push(props.specified); + pushVisibleUser(props.specified); } // keep cw when reply @@ -397,9 +400,15 @@ function setVisibility() { }, 'closed'); } +function pushVisibleUser(user) { + if (!visibleUsers.some(u => u.username === user.username && u.host === user.host)) { + visibleUsers.push(user); + } +} + function addVisibleUser() { os.selectUser().then(user => { - visibleUsers.push(user); + pushVisibleUser(user); }); }