From fd62371fc4c8791fdb68794aad98a8716a9fce06 Mon Sep 17 00:00:00 2001 From: Somaraj <17797942+somaraj@users.noreply.github.com> Date: Wed, 2 Dec 2026 01:54:06 +0530 Subject: [PATCH] feat(backlog): @mentions in task comments Typing @ in the comment box suggests people who can see the task. Mentions are stored as user ids and shown as highlighted names. The mentioned user gets an in-app notification (one, even if also watching) and starts watching the task when watchers are on. Optional Mention chat event per project channel and an inactive Mentioned e-mail template. Mentioning yourself, a non-member or someone who can't see the task does nothing. Closes #14 --- CHANGELOG.md | 2 + sql-scripts/02_defaults.sql | 7 + sql-scripts/03_locale.sql | 3 + .../Taskist.Core/Common/MentionText.cs | 80 +++++++++ src/Libraries/Taskist.Core/Enums/ChatEvent.cs | 3 +- .../Taskist.Core/Enums/EmailTemplateType.cs | 3 +- .../Taskist.Core/Enums/NotificationType.cs | 3 +- .../Git/Issues/IssueSyncService.cs | 7 +- .../Messages/IMessageService.cs | 2 + .../Messages/MessageService.cs | 38 +++++ .../WorkItems/BacklogService.cs | 23 ++- .../WorkItems/BacklogWatcherService.cs | 38 +---- .../WorkItems/IMentionService.cs | 15 ++ .../WorkItems/ITaskViewerService.cs | 11 ++ .../WorkItems/MentionService.cs | 130 +++++++++++++++ .../WorkItems/TaskViewerService.cs | 71 ++++++++ .../Controllers/Masters/ProjectController.cs | 2 +- .../WorkItems/BacklogController.cs | 30 +++- .../WorkItems/BacklogCommentGridModel.cs | 2 + .../Models/WorkItems/BacklogCommentModel.cs | 2 + .../Taskist.Web/Views/Backlog/Comments.cshtml | 7 +- .../Taskist.Web/Views/Backlog/Edit.cshtml | 1 + .../Taskist.Web/Views/Backlog/Index.cshtml | 1 + .../Notification/_NotificationList.cshtml | 1 + .../wwwroot/css/pages/backlog-task.css | 66 ++++++++ .../wwwroot/css/theme-dark.generated.css | 7 + .../js/pages/backlog/backlog-comments.js | 6 +- .../js/pages/backlog/backlog-mentions.js | 157 ++++++++++++++++++ .../Taskist.Tests/Common/MentionTextTests.cs | 89 ++++++++++ 29 files changed, 758 insertions(+), 49 deletions(-) create mode 100644 src/Libraries/Taskist.Core/Common/MentionText.cs create mode 100644 src/Libraries/Taskist.Service/WorkItems/IMentionService.cs create mode 100644 src/Libraries/Taskist.Service/WorkItems/ITaskViewerService.cs create mode 100644 src/Libraries/Taskist.Service/WorkItems/MentionService.cs create mode 100644 src/Libraries/Taskist.Service/WorkItems/TaskViewerService.cs create mode 100644 src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-mentions.js create mode 100644 src/Tests/Taskist.Tests/Common/MentionTextTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 141d3be..c8f385b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Each release lists **Upgrade notes** when an install needs action beyond the ste ### Added - **Watch tasks** (Configuration → Work items → *Task watchers*, off by default): a Watch / Watching button with the watcher count and list in the task header, and a **Watching** filter (bell menu → *Tasks I'm watching*). The creator, developer and tester watch a task automatically, as does anyone who comments on it; anyone can unwatch, and that choice sticks. Watchers get an in-app notification when the status, developer/tester or comments change, including changes from Git merge requests, bulk updates and issue sync, but never for their own changes. Members who can no longer see the task stop receiving them. *E-mail watchers* also sends them by e-mail. ([#15](https://github.com/Taskist/taskist/issues/15)) +- **@mentions in comments.** Type `@` in a task's comment box to pick someone who can see the task. The mention is stored by user id and shown as a highlighted name, so it follows renames. The mentioned person gets an in-app notification; a person who is both mentioned and watching gets one notification, not two. Mentions also add the person as a watcher when task watchers are on. Mentioning yourself, a non-member, or a member who can't see the task does nothing. Optional extras, both off until enabled: a **Mention** chat event per project channel, and an e-mail using the new **Mentioned** e-mail template (seeded inactive; activate it under Integrations → Email Template). ([#14](https://github.com/Taskist/taskist/issues/14)) ### Security @@ -23,6 +24,7 @@ Each release lists **Upgrade notes** when an install needs action beyond the ste ### Upgrade notes - New additive migration `AddBacklogWatcher` (table `BacklogWatcher`), applied automatically by Docker; manual installs run `dotnet ef database update` or the regenerated `sql-scripts/01_schema.sql`. Re-run `sql-scripts/03_locale.sql` for the new labels. +- Re-run `sql-scripts/02_defaults.sql` to add the inactive **Mentioned** e-mail template (Docker does this automatically). Existing project chat channels don't receive the new **Mention** event until it is ticked on the project's Notifications tab. ## [1.1.0] - 2026-11-16 diff --git a/sql-scripts/02_defaults.sql b/sql-scripts/02_defaults.sql index 4c7d9a2..49292e9 100644 --- a/sql-scripts/02_defaults.sql +++ b/sql-scripts/02_defaults.sql @@ -311,6 +311,13 @@ SELECT t.[Name], t.[EmailSubject], t.[EmailBody], @emailAccountId, 1 FROM @emailTemplates AS t WHERE NOT EXISTS (SELECT 1 FROM [EmailTemplate] AS e WHERE e.[Name] = t.[Name]); +/* Mention e-mails are optional: the template is created inactive. Activate it under Integrations -> Email Template. */ +INSERT INTO [EmailTemplate] ([Name], [EmailSubject], [EmailBody], [EmailAccountId], [Active]) +SELECT 'Mentioned', '{author} mentioned you on #{task_id} {title}', + '
Hello {display_name},
{author} mentioned you on a task:
#{task_id} - {title}
Project: {project_name}
{comment}', + @emailAccountId, 0 +WHERE NOT EXISTS (SELECT 1 FROM [EmailTemplate] AS e WHERE e.[Name] = 'Mentioned'); + /* --------------------------------------------------------------------------------------------------------- Administrator account Created only while the [User] table is empty, so re-running never restores it after it was renamed, diff --git a/sql-scripts/03_locale.sql b/sql-scripts/03_locale.sql index d071850..aab26b7 100644 --- a/sql-scripts/03_locale.sql +++ b/sql-scripts/03_locale.sql @@ -158,6 +158,8 @@ FROM (VALUES (N'Backlog.Issue.SyncStopped', N'Sync stopped'), (N'Backlog.Issue.Title', N'Issue'), (N'Backlog.Issue.UnlinkConfirm', N'Stop syncing with this issue? The issue itself is not changed.'), + (N'Backlog.Mention.Hint', N'@ to mention someone'), + (N'Backlog.Mention.NoMatch', N'No matching people on this task'), (N'Backlog.Module', N'Module'), (N'Backlog.Mr.Create', N'Create merge request'), (N'Backlog.Mr.CreateButton', N'Create merge request'), @@ -326,6 +328,7 @@ FROM (VALUES (N'ChatEvent.CodeReview', N'Code review activity'), (N'ChatEvent.Commented', N'New comment'), (N'ChatEvent.Conflict', N'Merge conflicts'), + (N'ChatEvent.Mentioned', N'Mention'), (N'ChatEvent.MergeRequestClosed', N'Merge/pull request closed'), (N'ChatEvent.MergeRequestMerged', N'Merge/pull request merged'), (N'ChatEvent.MergeRequestOpened', N'Merge/pull request opened'), diff --git a/src/Libraries/Taskist.Core/Common/MentionText.cs b/src/Libraries/Taskist.Core/Common/MentionText.cs new file mode 100644 index 0000000..db06f57 --- /dev/null +++ b/src/Libraries/Taskist.Core/Common/MentionText.cs @@ -0,0 +1,80 @@ +using System.Net; +using System.Text; +using System.Text.RegularExpressions; + +namespace Taskist.Core.Common; + +public static partial class MentionText +{ + #region Fields + + public const string UnknownName = "unknown user"; + + #endregion + + #region Methods + + public static string Token(int userId) => $"@[{userId}]"; + + public static IReadOnlyList