fix(drafts): remove and do not focus empty reply drafts (#850)

zio/stable
Piotrek Tomczewski 2023-01-08 14:54:12 +01:00 committed by GitHub
parent 805f7731ad
commit fcae855eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -54,12 +54,17 @@ function mentionHTML(acct: string) {
return `<span data-type="mention" data-id="${acct}" contenteditable="false">@${acct}</span>`
}
export function getReplyDraft(status: mastodon.v1.Status) {
const accountsToMention: string[] = []
function getAccountsToMention(status: mastodon.v1.Status) {
const userId = currentUser.value?.account.id
const accountsToMention: string[] = []
if (status.account.id !== userId)
accountsToMention.push(status.account.acct)
accountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct)))
return accountsToMention
}
export function getReplyDraft(status: mastodon.v1.Status) {
const accountsToMention = getAccountsToMention(status)
return {
key: `reply-${status.id}`,
draft: () => {
@ -77,7 +82,9 @@ export const isEmptyDraft = (draft: Draft | null | undefined) => {
return true
const { params, attachments } = draft
const status = params.status || ''
return (status.length === 0 || status === '<p></p>')
const text = htmlToText(status).trim().replace(/^(@\S+\s?)+/, '').trim()
return (text.length === 0)
&& attachments.length === 0
&& (params.spoilerText || '').length === 0
}