forked from Mirrors/elk
feat(editor): Respect default privacy setting of the account (2nd) (#1733)
Co-authored-by: patak <matias.capeletto@gmail.com>
This commit is contained in:
parent
23c1dfec10
commit
a0d036952d
3 changed files with 19 additions and 3 deletions
|
@ -153,6 +153,10 @@ defineExpose({
|
|||
editor.value?.commands?.focus?.()
|
||||
},
|
||||
})
|
||||
|
||||
onDeactivated(() => {
|
||||
clearEmptyDrafts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -17,7 +17,7 @@ watchEffect(() => {
|
|||
draftKey = route.query.draft?.toString() || 'home'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
onDeactivated(() => {
|
||||
clearEmptyDrafts()
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -13,6 +13,18 @@ export const builtinDraftKeys = [
|
|||
'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 {
|
||||
const {
|
||||
attachments = [],
|
||||
|
@ -32,7 +44,7 @@ export function getDefaultDraft(options: Partial<Mutable<mastodon.v1.CreateStatu
|
|||
params: {
|
||||
status: status || '',
|
||||
inReplyToId,
|
||||
visibility: visibility || 'public',
|
||||
visibility: getDefaultVisibility(visibility || 'public'),
|
||||
sensitive: sensitive ?? false,
|
||||
spoilerText: spoilerText || '',
|
||||
language: language || '', // auto inferred from current language on posting
|
||||
|
@ -145,7 +157,7 @@ export function directMessageUser(account: mastodon.v1.Account) {
|
|||
|
||||
export function clearEmptyDrafts() {
|
||||
for (const key in currentUserDrafts.value) {
|
||||
if (builtinDraftKeys.includes(key))
|
||||
if (builtinDraftKeys.includes(key) && !isEmptyDraft(currentUserDrafts.value[key]))
|
||||
continue
|
||||
if (!currentUserDrafts.value[key].params || isEmptyDraft(currentUserDrafts.value[key]))
|
||||
delete currentUserDrafts.value[key]
|
||||
|
|
Loading…
Reference in a new issue