feat(editor): Respect default privacy setting of the account (2nd) (#1733)

Co-authored-by: patak <matias.capeletto@gmail.com>
zio/stable
Peter Budai 2023-04-27 22:41:10 +02:00 committed by GitHub
parent 23c1dfec10
commit a0d036952d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -153,6 +153,10 @@ defineExpose({
editor.value?.commands?.focus?.() editor.value?.commands?.focus?.()
}, },
}) })
onDeactivated(() => {
clearEmptyDrafts()
})
</script> </script>
<template> <template>

View File

@ -17,7 +17,7 @@ watchEffect(() => {
draftKey = route.query.draft?.toString() || 'home' draftKey = route.query.draft?.toString() || 'home'
}) })
onMounted(() => { onDeactivated(() => {
clearEmptyDrafts() clearEmptyDrafts()
}) })
</script> </script>

View File

@ -13,6 +13,18 @@ export const builtinDraftKeys = [
'home', 'home',
] ]
const ALL_VISIBILITY = ['public', 'unlisted', 'private', 'direct'] as const
function getDefaultVisibility(currentVisibility: mastodon.v1.StatusVisibility) {
// The default privacy only should be taken into account if it makes
// the post more private than the replying to post
const preferredVisibility = currentUser.value?.account.source.privacy || 'public'
return ALL_VISIBILITY.indexOf(currentVisibility)
> ALL_VISIBILITY.indexOf(preferredVisibility)
? currentVisibility
: preferredVisibility
}
export function getDefaultDraft(options: Partial<Mutable<mastodon.v1.CreateStatusParams> & Omit<Draft, 'params'>> = {}): Draft { export function getDefaultDraft(options: Partial<Mutable<mastodon.v1.CreateStatusParams> & Omit<Draft, 'params'>> = {}): Draft {
const { const {
attachments = [], attachments = [],
@ -32,7 +44,7 @@ export function getDefaultDraft(options: Partial<Mutable<mastodon.v1.CreateStatu
params: { params: {
status: status || '', status: status || '',
inReplyToId, inReplyToId,
visibility: visibility || 'public', visibility: getDefaultVisibility(visibility || 'public'),
sensitive: sensitive ?? false, sensitive: sensitive ?? false,
spoilerText: spoilerText || '', spoilerText: spoilerText || '',
language: language || '', // auto inferred from current language on posting language: language || '', // auto inferred from current language on posting
@ -145,7 +157,7 @@ export function directMessageUser(account: mastodon.v1.Account) {
export function clearEmptyDrafts() { export function clearEmptyDrafts() {
for (const key in currentUserDrafts.value) { for (const key in currentUserDrafts.value) {
if (builtinDraftKeys.includes(key)) if (builtinDraftKeys.includes(key) && !isEmptyDraft(currentUserDrafts.value[key]))
continue continue
if (!currentUserDrafts.value[key].params || isEmptyDraft(currentUserDrafts.value[key])) if (!currentUserDrafts.value[key].params || isEmptyDraft(currentUserDrafts.value[key]))
delete currentUserDrafts.value[key] delete currentUserDrafts.value[key]