Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(editor): support mention user itself (#11133)

Flrande7e248a13796f
diff --git a/blocksuite/affine/inlines/mention/src/inline-spec.ts b/blocksuite/affine/inlines/mention/src/inline-spec.ts
index dd9eec5088..46094dd7fc 100644
--- a/blocksuite/affine/inlines/mention/src/inline-spec.ts
+++ b/blocksuite/affine/inlines/mention/src/inline-spec.ts
@@ -12,7 +12,7 @@ export const MentionInlineSpecExtension =
schema: z
.object({
member: z.string(),
- notification: z.string(),
+ notification: z.string().optional(),
})
.optional()
.nullable()
diff --git a/blocksuite/affine/shared/src/types/index.ts b/blocksuite/affine/shared/src/types/index.ts
index 3f4cf5191b..95d794dc10 100644
--- a/blocksuite/affine/shared/src/types/index.ts
+++ b/blocksuite/affine/shared/src/types/index.ts
@@ -75,7 +75,7 @@ export interface AffineTextAttributes {
footnote?: FootNote | null;
mention?: {
member: string;
- notification: string;
+ notification?: string;
} | null;
}
diff --git a/packages/frontend/core/src/modules/at-menu-config/services/index.ts b/packages/frontend/core/src/modules/at-menu-config/services/index.ts
index 50e48bf659..d32bd4969e 100644
--- a/packages/frontend/core/src/modules/at-menu-config/services/index.ts
+++ b/packages/frontend/core/src/modules/at-menu-config/services/index.ts
@@ -30,7 +30,7 @@ import { Service } from '@toeverything/infra';
import { cssVarV2 } from '@toeverything/theme/v2';
import { html } from 'lit';
-import type { WorkspaceServerService } from '../../cloud';
+import { AuthService, type WorkspaceServerService } from '../../cloud';
import type { WorkspaceDialogService } from '../../dialogs';
import type { DocsService } from '../../doc';
import type { DocDisplayMetaService } from '../../doc-display-meta';
@@ -352,8 +352,6 @@ export class AtMenuConfigService extends Service {
name: name ?? 'Unknown',
icon,
action: () => {
- close();
-
const root = inlineEditor.rootElement;
const block = root?.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
if (!block) return;
@@ -365,13 +363,36 @@ export class AtMenuConfigService extends Service {
const doc = block.doc;
const workspaceId = doc.workspace.id;
const docId = doc.id;
- const docTitle = doc.meta?.title ?? '';
const mode = block.std.get(DocModeProvider).getEditorMode() ?? 'page';
+ const currentUserId =
+ this.workspaceServerService.server?.scope.get(AuthService).session
+ .account$.value?.id;
+ if (!currentUserId) return;
+
+ close();
+
+ if (id === currentUserId) {
+ const inlineRange = inlineEditor.getInlineRange();
+ if (inlineRange && inlineRange.length === 0) {
+ inlineEditor.insertText(inlineRange, ' ', {
+ mention: {
+ member: id,
+ },
+ });
+ inlineEditor.setInlineRange({
+ index: inlineRange.index + 1,
+ length: 0,
+ });
+ }
+
+ return;
+ }
+
notificationService
.mentionUser(id, workspaceId, {
id: docId,
- title: docTitle,
+ title: this.docDisplayMetaService.title$(docId).value,
blockId: block.blockId,
mode: mode as GraphqlDocMode,
})