forked from Mirrors/elk
fix(drafts): remove and do not focus empty reply drafts (#850)
This commit is contained in:
parent
805f7731ad
commit
fcae855eea
1 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue