Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(comments): @mention workspace members in task comments (#1353)

Andrej98184d2611a2
diff --git a/apps/api/src/activity/controllers/create-comment.ts b/apps/api/src/activity/controllers/create-comment.ts
index 045411ac6..1e5f85c35 100644
--- a/apps/api/src/activity/controllers/create-comment.ts
+++ b/apps/api/src/activity/controllers/create-comment.ts
@@ -3,6 +3,8 @@ import { HTTPException } from "hono/http-exception";
import db from "../../database";
import { activityTable, taskTable, userTable } from "../../database/schema";
import { publishEvent } from "../../events";
+import createNotification from "../../notification/controllers/create-notification";
+import { parseMentionIds } from "../../utils/parse-mentions";
async function createComment(taskId: string, userId: string, content: string) {
const [activity] = await db
@@ -27,7 +29,7 @@ async function createComment(taskId: string, userId: string, content: string) {
.where(eq(userTable.id, userId));
const [task] = await db
- .select({ projectId: taskTable.projectId })
+ .select({ projectId: taskTable.projectId, title: taskTable.title })
.from(taskTable)
.where(eq(taskTable.id, taskId));
@@ -39,6 +41,21 @@ async function createComment(taskId: string, userId: string, content: string) {
});
}
+ // Notify any workspace members @mentioned in the comment (not the author).
+ const mentionedIds = parseMentionIds(content).filter((id) => id !== userId);
+ for (const mentionedId of mentionedIds) {
+ await createNotification({
+ userId: mentionedId,
+ type: "task_mention",
+ eventData: {
+ taskTitle: task?.title ?? null,
+ mentionerName: user?.name ?? null,
+ },
+ resourceId: taskId,
+ resourceType: "task",
+ });
+ }
+
return activity;
}
diff --git a/apps/api/src/utils/parse-mentions.ts b/apps/api/src/utils/parse-mentions.ts
new file mode 100644
index 000000000..7d7b5b707
--- /dev/null
+++ b/apps/api/src/utils/parse-mentions.ts
@@ -0,0 +1,11 @@
+// Extract unique mentioned user ids from a comment/description body. Matches the
+// `<kaneo-mention id="...">` tag the editor serializes @mentions to.
+export function parseMentionIds(content: string | null | undefined): string[] {
+ if (!content) return [];
+ const ids = new Set<string>();
+ const re = /<kaneo-mention[^>]*\bid="([^"]+)"/gi;
+ for (let m = re.exec(content); m !== null; m = re.exec(content)) {
+ if (m[1]) ids.add(m[1]);
+ }
+ return [...ids];
+}
diff --git a/apps/web/package.json b/apps/web/package.json
index 96f68ad97..552cf366e 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -61,6 +61,7 @@
"@tiptap/pm": "^3.22.5",
"@tiptap/react": "^3.22.5",
"@tiptap/starter-kit": "^3.22.5",
+ "@tiptap/suggestion": "^3.27.1",
"@types/file-saver": "^2.0.7",
"@vitejs/plugin-react": "^5.1.4",
"babel-plugin-react-compiler": "^19.0.0-beta-714736e-20250131",
diff --git a/apps/web/src/components/activity/comment-editor.tsx b/apps/web/src/components/activity/comment-editor.tsx
index 3ee5c14de..d4d22b316 100644
--- a/apps/web/src/components/activity/comment-editor.tsx
+++ b/apps/web/src/components/activity/comment-editor.tsx
@@ -40,6 +40,9 @@ import { bundledLanguages, type Highlighter } from "shiki";
import { AttachmentCard } from "@/components/task/extensions/attachment-card";
import { EmbedBlock } from "@/components/task/extensions/embed-block";
import { KaneoIssueLink } from "@/components/task/extensions/kaneo-issue-link";
+import { KaneoMention } from "@/components/task/extensions/kaneo-mention";
+import type { MentionMember } from "@/components/task/extensions/mention-list";
+import { MentionSuggestion } from "@/components/task/extensions/mention-suggestion";
import {
SHIKI_CODEBLOCK_REFRESH_META,
ShikiCodeBlock,
@@ -56,6 +59,8 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/menu";
+import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";
+import { useGetActiveWorkspaceUsers } from "@/hooks/queries/workspace-users/use-get-active-workspace-users";
import { cn } from "@/lib/cn";
import { parseTaskListMarkdownToNodes } from "@/lib/editor-task-list-paste";
import {
@@ -184,6 +189,20 @@ export default function CommentEditor({
const { t } = useTranslation();
const resolvedPlaceholder =
placeholder ?? t("activity:comment.leavePlaceholder");
+ const { data: activeWorkspace } = useActiveWorkspace();
+ const { data: workspaceUsers } = useGetActiveWorkspaceUsers(
+ activeWorkspace?.id ?? "",
+ );
+ const mentionMembersRef = useRef<MentionMember[]>([]);
+ mentionMembersRef.current = useMemo(
+ () =>
+ (workspaceUsers?.members ?? []).map((member) => ({
+ id: member.userId,
+ label: member.user?.name ?? member.user?.email ?? "",
+ image: member.user?.image ?? null,
+ })),
+ [workspaceUsers],
+ );
const editorShellRef = useRef<HTMLDivElement | null>(null);
const imageInputRef = useRef<HTMLInputElement | null>(null);
const dragDepthRef = useRef(0);
@@ -605,6 +624,10 @@ export default function CommentEditor({
EmbedBlock,
AttachmentCard,
KaneoIssueLink,
+ KaneoMention,
+ MentionSuggestion.configure({
+ getMembers: () => mentionMembersRef.current,
+ }),
TaskList,
Image.configure({
HTMLAttributes: {
diff --git a/apps/web/src/components/task/extensions/kaneo-mention.tsx b/apps/web/src/components/task/extensions/kaneo-mention.tsx
new file mode 100644
index 000000000..31a93fc04
--- /dev/null
+++ b/apps/web/src/components/task/extensions/kaneo-mention.tsx
@@ -0,0 +1,59 @@
+import { mergeAttributes, Node } from "@tiptap/core";
+
+// Inline atom node for an @mention of a workspace member. Stores the member id
+// (used by the backend to fire a notification) and a display label, and
+// round-trips through Markdown as `<kaneo-mention id label></kaneo-mention>`,
+// mirroring the KaneoIssueLink extension.
+export const KaneoMention = Node.create({
+ name: "kaneoMention",
+ group: "inline",
+ inline: true,
+ atom: true,
+ selectable: true,
+
+ addAttributes() {
+ return {
+ id: {
+ default: "",
+ parseHTML: (el) =>
+ el.getAttribute("id") || el.getAttribute("data-id") || "",
+ renderHTML: (attrs) => ({ "data-id": attrs.id }),
+ },
+ label: {
+ default: "",
+ parseHTML: (el) =>
+ el.getAttribute("label") || el.getAttribute("data-label") || "",
+ renderHTML: (attrs) => ({ "data-label": attrs.label }),
+ },
+ };
+ },
+
+ parseHTML() {
+ return [
+ { tag: "kaneo-mention[id]" },
+ { tag: "span[data-type='kaneo-mention']" },
+ ];
+ },
+
+ renderHTML({ node, HTMLAttributes }) {
+ return [
+ "span",
+ mergeAttributes(HTMLAttributes, {
+ "data-type": "kaneo-mention",
+ class: "kaneo-mention",
+ }),
+ `@${node.attrs.label || ""}`,
+ ];
+ },
+
+ renderText({ node }) {
+ return `@${node.attrs.label || ""}`;
+ },
+
+ renderMarkdown(node: { attrs?: { id?: string; label?: string } }) {
+ const id = String(node.attrs?.id || "");
+ const label = String(node.attrs?.label || "");
+ if (!id) return `@${label}`;
+ return `<kaneo-mention id="${id}" label="${label}"></kaneo-mention>`;
+ },
+});
diff --git a/apps/web/src/components/task/extensions/mention-list.tsx b/apps/web/src/components/task/extensions/mention-list.tsx
new file mode 100644
index 000000000..eb30178c6
--- /dev/null
+++ b/apps/web/src/components/task/extensions/mention-list.tsx
@@ -0,0 +1,78 @@
+import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
+
+export type MentionMember = {
+ id: string;
+ label: string;
+ image?: string | null;
+};
+
+export type MentionListRef = {
+ onKeyDown: (props: { event: KeyboardEvent }) => boolean;
+};
+
+type MentionListProps = {
+ items: MentionMember[];
+ command: (item: MentionMember) => void;
+};
+
+const MentionList = forwardRef<MentionListRef, MentionListProps>(
+ ({ items, command }, ref) => {
+ const [selected, setSelected] = useState(0);
+
+ // biome-ignore lint/correctness/useExhaustiveDependencies: reset on items change
+ useEffect(() => setSelected(0), [items]);
+
+ const select = (index: number) => {
+ const item = items[index];
+ if (item) command(item);
+ };
+
+ useImperativeHandle(ref, () => ({
+ onKeyDown: ({ event }) => {
+ if (items.length === 0) return false;
+ if (event.key === "ArrowUp") {
+ setSelected((s) => (s + items.length - 1) % items.length);
+ return true;
+ }
+ if (event.key === "ArrowDown") {
+ setSelected((s) => (s + 1) % items.length);
+ return true;
+ }
+ if (event.key === "Enter") {
+ select(selected);
+ return true;
+ }
+ return false;
+ },
+ }));
+
+ if (items.length === 0) return null;
+
+ return (
+ <div className="kaneo-mention-list">
+ {items.map((item, index) => (
+ <button
+ type="button"
+ key={item.id}
+ className={`kaneo-mention-item${index === selected ? " is-active" : ""}`}
+ onClick={() => select(index)}
+ onMouseEnter={() => setSelected(index)}
+ >
+ <Avatar className="h-5 w-5">
+ <AvatarImage src={item.image ?? ""} alt={item.label} />
+ <AvatarFallback className="text-[9px] font-medium">
+ {item.label.charAt(0).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ <span className="truncate">{item.label}</span>
+ </button>
+ ))}
+ </div>
+ );
+ },
+);
+
+MentionList.displayName = "MentionList";
+
+export default MentionList;
diff --git a/apps/web/src/components/task/extensions/mention-suggestion.tsx b/apps/web/src/components/task/extensions/mention-suggestion.tsx
new file mode 100644
index 000000000..7f92c6937
--- /dev/null
+++ b/apps/web/src/components/task/extensions/mention-suggestion.tsx
@@ -0,0 +1,96 @@
+import { Extension } from "@tiptap/core";
+import { PluginKey } from "@tiptap/pm/state";
+import { ReactRenderer } from "@tiptap/react";
+import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";
+import MentionList, {
+ type MentionListRef,
+ type MentionMember,
+} from "./mention-list";
+
+type MentionSuggestionOptions = {
+ getMembers: () => MentionMember[];
+};
+
+// Adds an @-triggered autocomplete of workspace members to an editor. On select
+// it inserts a `kaneoMention` node (which round-trips through Markdown). Built on
+// @tiptap/suggestion so it stays self-contained and does not touch the editor's
+// own keyboard/menu handling.
+export const MentionSuggestion = Extension.create<MentionSuggestionOptions>({
+ name: "kaneoMentionSuggestion",
+
+ addOptions() {
+ return { getMembers: () => [] };
+ },
+
+ addProseMirrorPlugins() {
+ const getMembers = this.options.getMembers;
+
+ const suggestion: Omit<SuggestionOptions, "editor"> = {
+ char: "@",
+ pluginKey: new PluginKey("kaneoMentionSuggestion"),
+ allowSpaces: false,
+ items: ({ query }) => {
+ const q = query.toLowerCase();
+ return getMembers()
+ .filter((m) => m.label?.toLowerCase().includes(q))
+ .slice(0, 8);
+ },
+ command: ({ editor, range, props }) => {
+ const member = props as unknown as MentionMember;
+ editor
+ .chain()
+ .focus()
+ .insertContentAt(range, [
+ {
+ type: "kaneoMention",
+ attrs: { id: member.id, label: member.label },
+ },
+ { type: "text", text: " " },
+ ])
+ .run();
+ },
+ render: () => {
+ let component: ReactRenderer<MentionListRef> | null = null;
+ let popup: HTMLDivElement | null = null;
+
+ const place = (clientRect?: (() => DOMRect | null) | null) => {
+ if (!popup || !clientRect) return;
+ const rect = clientRect();
+ if (!rect) return;
+ popup.style.top = `${rect.bottom + window.scrollY + 4}px`;
+ popup.style.left = `${rect.left + window.scrollX}px`;
+ };
+
+ return {
+ onStart: (props) => {
+ component = new ReactRenderer(MentionList, {
+ props,
+ editor: props.editor,
+ });
+ popup = document.createElement("div");
+ popup.className = "kaneo-mention-popup";
+ popup.appendChild(component.element);
+ document.body.appendChild(popup);
+ place(props.clientRect);
+ },
+ onUpdate: (props) => {
+ component?.updateProps(props);
+ place(props.clientRect);
+ },
+ onKeyDown: (props) => {
+ if (props.event.key === "Escape") return false;
+ return component?.ref?.onKeyDown(props) ?? false;
+ },
+ onExit: () => {
+ popup?.remove();
+ popup = null;
+ component?.destroy();
+ component = null;
+ },
+ };
+ },
+ };
+
+ return [Suggestion({ editor: this.editor, ...suggestion })];
+ },
+});
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index 351dbee16..979166550 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -435,6 +435,56 @@ input:-webkit-autofill:active {
color: var(--accent-foreground);
}
+ .kaneo-mention {
+ display: inline-flex;
+ align-items: baseline;
+ border-radius: 0.3rem;
+ padding: 0 0.2rem;
+ font-weight: 500;
+ color: var(--primary);
+ background: color-mix(in srgb, var(--primary) 12%, transparent);
+ white-space: nowrap;
+ }
+
+ .kaneo-mention-popup {
+ position: absolute;
+ z-index: 50;
+ }
+
+ .kaneo-mention-list {
+ display: flex;
+ flex-direction: column;
+ gap: 0.1rem;
+ min-width: 12rem;
+ max-height: 16rem;
+ overflow-y: auto;
+ border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
+ border-radius: 0.5rem;
+ background: var(--popover);
+ padding: 0.32rem;
+ box-shadow:
+ 0 10px 28px --alpha(var(--color-black) / 18%),
+ 0 1px 2px --alpha(var(--color-black) / 10%);
+ }
+
+ .kaneo-mention-item {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ width: 100%;
+ border-radius: 0.35rem;
+ padding: 0.32rem 0.42rem;
+ text-align: left;
+ font-size: 0.79rem;
+ color: color-mix(in srgb, var(--foreground) 88%, transparent);
+ }
+
+ .kaneo-mention-item:hover,
+ .kaneo-mention-item.is-active {
+ background: var(--accent);
+ color: var(--accent-foreground);
+ }
+
.kaneo-tiptap-slash-empty {
padding: 0.4rem 0.55rem;
font-size: 0.76rem;
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 67336d33e..d0be0785e 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -1158,6 +1158,10 @@
"title": "Task assigned to you",
"content": "You have been assigned to task: {{taskTitle}}"
},
+ "task_mention": {
+ "title": "{{mentionerName}} mentioned you",
+ "content": "{{mentionerName}} mentioned you in: {{taskTitle}}"
+ },
"time_entry_created": {
"title": "Time tracking started",
"contentWithTask": "Time tracking started on task: {{taskTitle}}",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fac84da8a..e88257c64 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -80,10 +80,10 @@ importers:
version: 3.1041.0
'@better-auth/api-key':
specifier: ^1.6.11
- version: 1.6.11(f891274a36efae612e07dac933cf26e3)
+ version: 1.6.11(d02ea3d87361f8f9da2198a563634fb6)
'@better-auth/drizzle-adapter':
specifier: ^1.6.11
'@hono/node-server':
specifier: '>=1.19.13'
version: 2.0.4([email protected])
@@ -198,7 +198,7 @@ importers:
version: 0.563.0([email protected])
next:
specifier: '>=15.5.18 <16.0.0 || >=16.2.6'
radix-ui:
specifier: ^1.4.3
@@ -250,7 +250,7 @@ importers:
'@better-auth/api-key':
specifier: ^1.6.9
- version: 1.6.9(4c8bc36a69653fae3aeeac59b56808dd)
+ version: 1.6.9(c5cb1a52354bab75b245f65b78667356)
'@dnd-kit/core':
specifier: ^6.3.1
@@ -389,6 +389,9 @@ importers:
'@tiptap/starter-kit':
specifier: ^3.22.5
version: 3.22.5
+ '@tiptap/suggestion':
+ specifier: ^3.27.1
+ version: 3.27.1(@floating-ui/[email protected])(@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected])
'@types/file-saver':
specifier: ^2.0.7
version: 2.0.7
@@ -4441,6 +4444,13 @@ packages:
'@tiptap/[email protected]':
resolution: {integrity: sha512-LZ/LYbwH6rnDi5DnRyagkuNsYAVyhM+yJvvz+ZuYA0JkPiTXJV86J5PWSKew8M0gVfMHcNVtKjfQCvViFCeIgw==}
+ '@tiptap/[email protected]':
+ resolution: {integrity: sha512-GNBPRav+lAfXzqmmUAS6ylRAn3G8JfsP6XosjoORxJIQJLx1ktDqwp6tm1Vgz9aGIM2TrBxLS1uBbI1Gb2/1VA==}
+ peerDependencies:
+ '@floating-ui/dom': ^1.0.0
+ '@tiptap/core': 3.27.1
+ '@tiptap/pm': 3.27.1
+
'@ts-morph/[email protected]':
resolution: {integrity: sha512-Wf29UqxWDpc+i61k3oIOzcUfQt79PIT9y/MWfAGlrkjg6lBC1hwDECLXPVJAhWjiGbfBCxZd65F/LIZF3+jeJQ==}
@@ -9290,16 +9300,16 @@ snapshots:
'@bcoe/[email protected]': {}
- '@better-auth/[email protected](f891274a36efae612e07dac933cf26e3)':
+ '@better-auth/[email protected](d02ea3d87361f8f9da2198a563634fb6)':
dependencies:
'@better-auth/utils': 0.4.0
zod: 4.3.6
- '@better-auth/[email protected](4c8bc36a69653fae3aeeac59b56808dd)':
+ '@better-auth/[email protected](c5cb1a52354bab75b245f65b78667356)':
dependencies:
'@better-auth/utils': 0.4.0
zod: 4.3.6
@@ -9360,9 +9370,9 @@ snapshots:
optionalDependencies:
dependencies:
'@better-auth/utils': 0.4.0
optionalDependencies:
@@ -13412,6 +13422,12 @@ snapshots:
'@tiptap/extensions': 3.22.5(@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected])
'@tiptap/pm': 3.22.5
+ dependencies:
+ '@floating-ui/dom': 1.7.4
+ '@tiptap/core': 3.22.5(@tiptap/[email protected])
+ '@tiptap/pm': 3.22.5
+
'@ts-morph/[email protected]':
dependencies:
fast-glob: 3.3.3
@@ -13599,7 +13615,7 @@ snapshots:
obug: 2.1.1
std-env: 4.0.0
tinyrainbow: 3.1.0
'@vitest/[email protected]':
dependencies:
@@ -15897,15 +15913,15 @@ snapshots:
dependencies:
'@next/env': 15.5.18
'@swc/helpers': 0.5.15
caniuse-lite: 1.0.30001792
postcss: 8.5.11
- react: 19.1.0
- react-dom: 19.1.0([email protected])
- styled-jsx: 5.1.6(@babel/[email protected])([email protected])
+ react: 19.2.4
+ react-dom: 19.2.4([email protected])
+ styled-jsx: 5.1.6(@babel/[email protected])([email protected])
optionalDependencies:
'@next/swc-darwin-arm64': 15.5.18
'@next/swc-darwin-x64': 15.5.18
@@ -15916,20 +15932,22 @@ snapshots:
'@next/swc-win32-arm64-msvc': 15.5.18
'@next/swc-win32-x64-msvc': 15.5.18
'@opentelemetry/api': 1.9.0
+ babel-plugin-react-compiler: 19.0.0-beta-ebf51a3-20250411
sharp: 0.34.5
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
+ optional: true
dependencies:
'@next/env': 15.5.18
'@swc/helpers': 0.5.15
caniuse-lite: 1.0.30001792
postcss: 8.5.11
- react: 19.2.4
- react-dom: 19.2.4([email protected])
- styled-jsx: 5.1.6(@babel/[email protected])([email protected])
+ react: 19.1.0
+ react-dom: 19.1.0([email protected])
+ styled-jsx: 5.1.6(@babel/[email protected])([email protected])
optionalDependencies:
'@next/swc-darwin-arm64': 15.5.18
'@next/swc-darwin-x64': 15.5.18
@@ -15940,12 +15958,10 @@ snapshots:
'@next/swc-win32-arm64-msvc': 15.5.18
'@next/swc-win32-x64-msvc': 15.5.18
'@opentelemetry/api': 1.9.0
- babel-plugin-react-compiler: 19.0.0-beta-ebf51a3-20250411
sharp: 0.34.5
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
- optional: true
dependencies:
@@ -17193,12 +17209,12 @@ snapshots:
dependencies:
inline-style-parser: 0.2.7
dependencies:
client-only: 0.0.1
react: 19.1.0
optionalDependencies:
- '@babel/core': 7.29.7
+ '@babel/core': 8.0.1
dependencies: