diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index 3aa82d70..7d554fec 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -34,10 +34,16 @@ const { editor } = useTiptap({ get: () => draft.params.status, set: newVal => draft.params.status = newVal, }), - placeholder: computed(() => placeholder || draft.params.inReplyToId ? t('placeholder.replying') : t('placeholder.default_1')), + placeholder: computed(() => placeholder ?? draft.params.inReplyToId ? t('placeholder.replying') : t('placeholder.default_1')), autofocus: shouldExpanded, onSubmit: publish, - onFocus() { isExpanded = true }, + onFocus() { + if (!isExpanded && draft.initialText) { + editor.value?.chain().insertContent(`${draft.initialText} `).focus('end').run() + draft.initialText = '' + } + isExpanded = true + }, onPaste: handlePaste, }) diff --git a/composables/statusDrafts.ts b/composables/statusDrafts.ts index fa59e181..908fb463 100644 --- a/composables/statusDrafts.ts +++ b/composables/statusDrafts.ts @@ -4,6 +4,7 @@ import type { Mutable } from '~/types/utils' export interface Draft { editingStatus?: Status + initialText?: string params: Omit, 'status'> & { status?: Exclude } @@ -28,6 +29,7 @@ export function getDefaultDraft(options: Partial@${acct}` +} + export function getReplyDraft(status: Status) { + const acountsToMention: string[] = [] + const userId = currentUser.value?.account.id + if (status.account.id !== userId) + acountsToMention.push(status.account.acct) + acountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct))) return { key: `reply-${status.id}`, - draft: () => getDefaultDraft({ - inReplyToId: status!.id, - visibility: status.visibility, - }), + draft: () => { + return getDefaultDraft({ + initialText: acountsToMention.map(acct => mentionHTML(acct)).join(' '), + inReplyToId: status!.id, + visibility: status.visibility, + }) + }, } }