Feature Specification: Mentions in Thread Comments
Overview
Enable users to mention other team members in thread comments using the @ trigger character. Mentioned users will receive real-time notifications via WebSocket and see unread mentions in the "Shared with me" folder.
User Stories
US-1: Mention User in Comment
As a team member working on a thread I want to mention another team member using @usernameSo that they receive a notification and can quickly respond to my query
Acceptance Criteria:
- Type
@in thread comment editor to trigger mention autocomplete - Show 5 user suggestions immediately upon
@trigger - Filter suggestions as user continues typing after
@ - Only show users who have access to the thread (shared inbox members)
- Internal users only (no external email addresses)
- Mention appears with highlighted background in comment
- Mention is stored as part of the comment content (synced via Yjs)
US-2: Receive Mention Notification
As a team member I want to receive real-time notifications when someone mentions me So that I can respond promptly to requests for my attention
Acceptance Criteria:
- Receive WebSocket notification when mentioned in a comment
- Thread appears in "Shared with me" folder as unread mention
- Only show unread mentions in "Shared with me"
- Only show active threads (not archived)
- Notification includes thread details and who mentioned me
US-3: View Unread Mentions
As a team member I want to see all threads where I have unread mentions So that I can prioritize my attention on conversations that need my input
Acceptance Criteria:
- "Shared with me" folder shows threads with unread mentions
- Threads are sorted by most recent mention first
- Archive filter applies: archived threads only shown when archive mode is ON
- Thread list items show visual badge (@ symbol) for threads with unread mentions
- When opening thread, auto-scroll to first unread mention comment
- Unread mention comments are highlighted until viewed
US-4: Mark Mention as Read
As a team member I want to mark mentions as read when I interact with the thread So that I can track which mentions I've already seen
Acceptance Criteria:
- Any interaction with thread marks all unread mentions as read (changing assignee, adding comment, changing status, updating tags)
- Navigating away from "Shared with me" folder marks all viewed mentions as read
- Thread is removed from "Shared with me" folder when all mentions are read
- Read status persists across sessions
- Visual badge (@ symbol) on threads with unread mentions in "Shared with me"
Technical Architecture
Database Schema
New Table: mentions
CREATE TABLE mentions (
id SERIAL PRIMARY KEY,
thread_id TEXT NOT NULL REFERENCES threads(id) ON DELETE CASCADE,
message_id TEXT NOT NULL, -- Yjs document message identifier (UUID)
mentioned_user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
mentioned_by_user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
read_at TIMESTAMP WITH TIME ZONE -- NULL = unread, timestamp = when marked read
);
CREATE INDEX idx_mentions_user_read ON mentions(mentioned_user_id, read_at, created_at DESC);
CREATE INDEX idx_mentions_thread ON mentions(thread_id);
CREATE INDEX idx_mentions_message ON mentions(message_id);Design Rationale:
mentioned_user_idandmentioned_by_user_idare INTEGER (not JSONB) - simple user IDs- Composite index
(mentioned_user_id, read_at, created_at)optimizes "Shared with me" queries (WHERE read_at IS NULL) thread_idforeign key with CASCADE delete ensures cleanup when threads are deletedmessage_idindex for efficient lookups by message (UUID format)read_atis nullable: NULL = unread, timestamp = when marked read (no separate boolean needed)- Foreign key cascades handle cleanup when threads or users are deleted
Retention Policy:
- Database stores all mentions for historical search capability
- Future feature: Search mentions across all threads
- No automatic deletion implemented (YAGNI - will revisit when storage becomes concern)
Frontend Integration
TipTap Mention Extension
Use TipTap's built-in @tiptap/extension-mention:
import Mention from '@tiptap/extension-mention'
// In thread-comment-input.vue extensions array:
Mention.configure({
HTMLAttributes: {
class: 'mention' // Styled with highlighted background
},
suggestion: {
items: async ({ query }) => {
// Fetch users from usersStore who have access to current thread
const sharedInboxUsers = getSharedInboxUsers(currentThreadInbox)
return sharedInboxUsers
.filter(user => !user.external) // Internal users only
.filter(user => user.displayName.toLowerCase().includes(query.toLowerCase()))
.slice(0, 5) // Limit to 5 suggestions
},
render: () => {
// Use Reka UI Popover for suggestion dropdown (shadow-dom compatible)
// Matches existing UI patterns
}
}
})Integration Points:
- Modify
ui/teams/components/thread-comment-input.vueto add Mention extension - Extract mentioned user IDs from editor content before sending comment
- Use existing
usersStorefor user list and access control - Leverage Yjs for collaborative editing of mentions (mentions sync automatically)
"Shared with me" Folder
Modify ui/teams/stores/folders.js:
personalInboxes.value = [
{ id: 'me', name: gt('Assigned to me'), icon: 'bi:person' },
{ id: 'shared', name: gt('Shared with me'), icon: 'bi:people' }, // Already exists
// ... tour folder
]Implementation:
- Folder already exists in UI (currently unused)
- Fetch threads with unread mentions for current user
- Respect archive filter: only show archived threads when archive mode is ON
- Sort by most recent mention first
- Display @ badge on threads with unread mentions
- Mark mentions as read when navigating away from folder
- Auto-scroll to first unread mention when opening thread
- Highlight unread mention comments until they enter viewport
Backend API
POST /api/threads/:threadId/mentions
Create mention records when comment is posted:
Request:
{
"messageId": "uuid-v4-message-id",
"mentionedUserIds": [123, 789]
}Response:
{
"success": true,
"mentions": [
{
"id": 1,
"threadId": "thread-123",
"messageId": "uuid-v4-message-id",
"mentionedUserId": 123,
"mentionedByUserId": 999,
"createdAt": "2025-10-23T12:00:00Z",
"readAt": null
}
]
}Logic:
- Validate user has access to thread (same check as assignees)
- Validate mentioned users have access to thread
- Create mention records in database
- Trigger WebSocket notifications to mentioned users
- Return created mention records
GET /api/mentions/unread
Fetch unread mentions for current user:
Query Parameters:
status=active(filter by thread status, default: active)
Response:
{
"mentions": [
{
"id": 1,
"threadId": "thread-123",
"messageId": "uuid-v4-message-id",
"mentionedByUserId": 999,
"mentionedByUser": {
"id": 999,
"displayName": "John Doe",
"email": "john@example.com"
},
"thread": {
"id": "thread-123",
"subject": "Support Request #123",
"inbox": {"email": "support@example.com", "displayName": "Support"},
"status": "active"
},
"createdAt": "2025-10-23T12:00:00Z",
"readAt": null
}
]
}Logic:
- Query mentions table for current user where
read_at IS NULL - Join with threads table to get thread details
- Filter by thread status (active only by default)
- Order by
created_at DESC - Return thread details for "Shared with me" folder display
PUT /api/mentions/mark-read
Mark specific mentions as read for current user:
Request:
{
"messageIds": ["uuid-v4-message-id-1", "uuid-v4-message-id-2"]
}Response:
{
"success": true,
"markedCount": 2
}Logic:
- Update
read_at = NOW()for mentions in provided message IDs for current user whereread_at IS NULL - Return count of marked mentions
- Called when viewing mentions (legacy approach, kept for compatibility)
PUT /api/folders/shared/mark-read
Mark all mentions as read when navigating away from "Shared with me" folder:
Response:
{
"success": true,
"markedCount": 5
}Logic:
- Update
read_at = NOW()for all unread mentions for current user - Called when user navigates away from "Shared with me" folder
- Return count of marked mentions
WebSocket Notifications
Notification Message Format
Extend existing WebSocket notification pattern:
{
"type": "mention",
"data": {
"mentionId": 1,
"threadId": "thread-123",
"messageId": "uuid-v4-message-id",
"mentionedByUserId": 999,
"mentionedByUser": {
"id": 999,
"displayName": "John Doe",
"email": "john@example.com"
},
"thread": {
"subject": "Support Request #123",
"inbox": {"email": "support@example.com", "displayName": "Support"}
},
"createdAt": "2025-10-23T12:00:00Z"
}
}Notification Pattern: See Technical Patterns - Thread Events for real-time notification architecture.
Implementation:
- WebSocket message type:
"mention" - Targets specific user by user ID
- Frontend updates "Shared with me" folder badge in real-time
Yjs Collaboration Integration
Mentions use Yjs CRDT for collaborative editing. See Technical Patterns - Yjs/CRDT.
Mention Flow:
- User types
@usernamein comment editor (TipTap + Yjs) - Mention node syncs to all collaborators via Yjs
- On comment submission, frontend extracts mention user IDs
- Backend creates mention records and sends WebSocket notifications
Visual Design
Mention Styling
.mention {
background-color: var(--highlight-background);
color: var(--highlight-text);
padding: 0.125rem 0.25rem;
border-radius: 0.25rem;
font-weight: 500;
}
.mention-comment--unread {
background-color: var(--mention-unread-background);
border-left: 3px solid var(--mention-unread-border);
padding-left: 0.5rem;
}Behavior:
- Highlighted background distinguishes mentions from regular text
- NOT clickable in initial implementation (future: integrate with Core UI API)
- Consistent with existing Teams UI design tokens
- Unread mention comments highlighted until they enter viewport
- Auto-scroll to first unread mention when opening thread from "Shared with me"
Thread List Badge
Threads with unread mentions in "Shared with me" folder show @ symbol badge:
<span class="mention-badge">@</span>Styling:
- Small badge positioned near thread subject
- Consistent with existing badge patterns in thread list
- Only visible in "Shared with me" folder
Suggestion Dropdown
Use Reka UI Popover component (matches existing patterns and shadow-dom compatible):
- Show user avatar/initials
- Display name and email
- Limit to 5 suggestions
- Keyboard navigation (arrow keys, Enter to select)
- Mouse hover and click support
- Shadow-dom compatibility ensures proper rendering in microfrontend environment
Permission Model
Mention Permission Rule:
If you have access to the thread (shared inbox member), you can mention any other shared inbox member.
Implementation:
- Use existing
accountstable join to check thread access - Same logic as assignee selection (see
src/routes/api/threads/[threadId]/assignee.js) - No additional permission checks needed
UX Improvements
Read Status Management
Interaction-Based Read Tracking:
- Any interaction with thread marks all unread mentions in that thread as read
- Interactions include: changing assignee, adding comment, changing status, updating tags
- Provides better UX - once user engages with thread, mentions are considered acknowledged
- Implemented by calling
markThreadMentionsAsRead()helper in all thread mutation endpoints
Navigation-Based Read Tracking:
- When navigating away from "Shared with me" folder, mark all viewed mentions as read
- Ensures threads don't remain in folder after user has seen them
- Called via
onBeforeRouteLeavenavigation guard
Archive Filter Integration:
- "Shared with me" folder respects existing archive filter toggle
- Archive mode ON: Show both active and archived threads with unread mentions
- Archive mode OFF: Only show active threads (default behavior)
- Consistent with existing folder filtering logic
Visual Feedback
Thread List Badge:
- @ symbol badge on thread list items with unread mentions
- Only visible in "Shared with me" folder
- Provides quick visual scan of which threads need attention
Comment Highlighting:
- Unread mention comments highlighted with left border + background tint
- Highlight removed when comment enters viewport
- Only highlights unread mentions (not all mentions in thread)
Auto-Scroll Behavior:
- When opening thread from "Shared with me", auto-scroll to first unread mention
- Smooth scroll animation for better UX
- Ensures user sees why thread appeared in their mentions
Testing Strategy
Unit Tests
Backend Tests (Vitest):
spec/routes/api/threads/mentions.test.js- POST /api/threads/:threadId/mentions - create mentions
- GET /api/mentions/unread - fetch unread mentions
- PUT /api/mentions/mark-read - mark specific mentions as read
- PUT /api/folders/shared/mark-read - mark all mentions as read
- Permission validation (user must have thread access)
- Multiple mentions in single comment
- Invalid user ID handling
- Archive filter integration (only active threads by default)
Frontend Tests (Vitest):
spec/ui/stores/mentions.test.js(if separate store created)- Fetch unread mentions
- Mark mentions as read
- Real-time notification handling
spec/ui/components/thread-comment-input.test.js- TipTap Mention extension integration
- Mention suggestion rendering
- User filtering logic
E2E Tests (Playwright)
Test Plan: docs/development/testing/specs/mentions.md
Scenarios:
Mention User in Comment
- Open thread
- Type
@in comment editor - Verify suggestion dropdown appears
- Select user from suggestions
- Verify mention appears with highlight
- Submit comment
- Verify mention stored in database
Receive Mention Notification
- User A mentions User B in comment
- Verify User B receives WebSocket notification
- Verify thread appears in User B's "Shared with me" folder
- Verify @ badge appears on thread in list
Auto-Scroll to Mention
- User B opens thread from "Shared with me" folder
- Verify auto-scroll to first unread mention comment
- Verify unread mention comment is highlighted
Viewport-Based Read Tracking
- User B scrolls to mention comment
- Verify mention comment enters viewport
- Verify highlight removed from comment
- Verify mention marked as read in database
Navigation-Based Read Tracking
- User B views thread with mentions in "Shared with me"
- User B navigates to different folder (e.g., "Assigned to me")
- Verify all viewed mentions marked as read
- Verify thread removed from "Shared with me" (if no unread mentions remain)
Archive Filter Integration
- User A mentions User B in archived thread
- User B opens "Shared with me" with archive mode OFF
- Verify archived thread NOT shown
- User B toggles archive mode ON
- Verify archived thread with mention now visible
Collaborative Editing
- User A types mention in comment (doesn't send)
- User B simultaneously types in same comment
- Verify both edits merge correctly (Yjs CRDT)
- User A sends comment
- Verify mention notification only sent on submission
Permission Validation
- User A attempts to mention User C (not in shared inbox)
- Verify User C not shown in suggestions
- Verify backend rejects mention if manually crafted
Multiple Unread Mentions
- User A mentions User B in comments 1, 3, and 5
- User B opens thread from "Shared with me"
- Verify auto-scroll to comment 1 (first unread mention)
- Verify only unread mentions (1, 3, 5) are highlighted
- Verify read mentions (if any) are NOT highlighted
Implementation Phases
Phase 1: Database & Backend API (COMPLETED)
- Create
mentionstable migration - Implement POST /api/threads/:threadId/mentions endpoint
- Implement GET /api/mentions/unread endpoint
- Add WebSocket notification broadcasting
Phase 2: Frontend - TipTap Integration (COMPLETED)
- Add TipTap Mention extension to thread-comment-input.vue
- Implement suggestion dropdown with user filtering
- Extract mention user IDs on comment submission
- Send mentions to backend API
Phase 3: Frontend - "Shared with me" Folder (COMPLETED)
- Implement unread mentions fetching
- Update folder UI to show mention threads
- Implement real-time WebSocket notification listener
Phase 4: UX Improvements (COMPLETED)
- Add @ badge to thread list items with unread mentions
- Implement interaction-based read tracking (mark on any thread interaction)
- Implement navigation-based read tracking (mark on folder navigation)
- Add auto-scroll to first unread mention when opening thread
- Add highlight styling to unread mention comments
- Integrate archive filter with "Shared with me" folder
- Update backend API: PUT /api/mentions/mark-read (by message IDs)
- Update backend API: PUT /api/folders/shared/mark-read (mark all)
- Update all thread mutation endpoints to mark mentions as read
Phase 5: Testing & Polish
- Update unit tests for new read tracking behavior
- Update E2E test scenarios for UX improvements
- Add mention styling polish
- Performance testing with multiple mentions
Future Enhancements (Out of Scope)
- Clickable Mentions: Integrate with Core UI API to show user profile on click
- Mention Search: Search mentions across all threads by user or date range
- Email Notifications: Optional email digest for mentions when user offline
- Mention Deletion Handling: Track when comments with mentions are edited/deleted
- Mention Analytics: Dashboard showing mention patterns and response times
- @team Mentions: Mention all members of shared inbox with special syntax
- Mention Preview: Hover over mention to show user details
- Unread Count Badge: Show count of unread mentions on "Shared with me" folder
References
- ADR-0007: Introduce Yjs for real-time state sharing
- ADR-0008: Use custom WebSocket implementation for Yjs
- TipTap Mention Extension: https://tiptap.dev/api/extensions/mention
- Yjs Documentation: https://docs.yjs.dev/
- Existing Patterns:
ui/teams/components/thread-comment-input.vue- TipTap editorui/teams/stores/users.js- User managementui/teams/stores/folders.js- Folder structuresrc/routes/ws/ws.js- WebSocket implementationsrc/routes/api/threads/[threadId]/assignee.js- Permission pattern

