From b61afaab9e28c16d7007e1bf1212950144d8036e Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 12 Dec 2022 23:35:59 +0100 Subject: [PATCH] fix: preserve mentions when replying (#404) --- components/publish/PublishWidget.vue | 10 ++++++++-- composables/statusDrafts.ts | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) 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, + }) + }, } }