Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions sql-scripts/02_defaults.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
'<p>Hello {display_name},</p><p><strong>{author}</strong> mentioned you on a task:</p><p style="font-size:16px;"><strong>#{task_id} - {title}</strong></p><p style="color:#5b6b7b;">Project: {project_name}</p><blockquote style="margin:12px 0;padding:8px 12px;border-left:3px solid #1cc7c9;color:#33455c;">{comment}</blockquote><p><a href="{url}" style="' + @btn + '">View task</a></p>',
@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,
Expand Down
3 changes: 3 additions & 0 deletions sql-scripts/03_locale.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
80 changes: 80 additions & 0 deletions src/Libraries/Taskist.Core/Common/MentionText.cs
Original file line number Diff line number Diff line change
@@ -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<int> ParseUserIds(string? text)
{
if (string.IsNullOrEmpty(text))
return [];

var ids = new List<int>();
foreach (Match match in TokenRegex().Matches(text))
{
if (int.TryParse(match.Groups[1].Value, out var id) && id > 0 && !ids.Contains(id))
ids.Add(id);
}

return ids;
}

public static string ToPlainText(string? text, IReadOnlyDictionary<int, string> names)
{
if (string.IsNullOrEmpty(text))
return string.Empty;

return TokenRegex().Replace(text, match => "@" + NameOf(match, names));
}

public static string ToHtml(string? text, IReadOnlyDictionary<int, string> names)
{
if (string.IsNullOrEmpty(text))
return string.Empty;

var html = new StringBuilder();
var position = 0;
foreach (Match match in TokenRegex().Matches(text))
{
html.Append(WebUtility.HtmlEncode(text[position..match.Index]));

var known = int.TryParse(match.Groups[1].Value, out var id) && names.ContainsKey(id);
html.Append(known
? $"<span class=\"mention\" data-user-id=\"{id}\">@{WebUtility.HtmlEncode(names[id])}</span>"
: $"<span class=\"mention mention--unknown\">@{UnknownName}</span>");

position = match.Index + match.Length;
}

html.Append(WebUtility.HtmlEncode(text[position..]));
return html.ToString();
}

#endregion

#region Utilities

private static string NameOf(Match match, IReadOnlyDictionary<int, string> names)
{
return int.TryParse(match.Groups[1].Value, out var id) && names.TryGetValue(id, out var name)
? name
: UnknownName;
}

[GeneratedRegex(@"@\[(\d{1,9})\]")]
private static partial Regex TokenRegex();

#endregion
}
3 changes: 2 additions & 1 deletion src/Libraries/Taskist.Core/Enums/ChatEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public enum ChatEvent
MergeRequestClosed = 64,
CodeReview = 128,
Conflict = 256,
All = TaskAssigned | StatusChanged | TaskUpdated | Commented | MergeRequestOpened | MergeRequestMerged | MergeRequestClosed | CodeReview | Conflict
Mentioned = 512,
All = TaskAssigned | StatusChanged | TaskUpdated | Commented | MergeRequestOpened | MergeRequestMerged | MergeRequestClosed | CodeReview | Conflict | Mentioned
}
3 changes: 2 additions & 1 deletion src/Libraries/Taskist.Core/Enums/EmailTemplateType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public enum EmailTemplateType
Notification,
Invite,
NewTaskNotification,
TaskNotification
TaskNotification,
Mentioned
}
3 changes: 2 additions & 1 deletion src/Libraries/Taskist.Core/Enums/NotificationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public enum NotificationType
MergeRequestClosed,
TaskStatusChanged,
TaskCommented,
TaskAssignmentChanged
TaskAssignmentChanged,
Mentioned
}
7 changes: 6 additions & 1 deletion src/Libraries/Taskist.Service/Git/Issues/IssueSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class IssueSyncService : IIssueSyncService
private readonly IClosingRequirementService _closingRequirementService;
private readonly ITaskCodeService _taskCodeService;
private readonly IBacklogWatcherService _backlogWatcherService;
private readonly IMentionService _mentionService;
private readonly ILogger<IssueSyncService> _logger;

#endregion
Expand All @@ -76,8 +77,10 @@ public IssueSyncService(IRepository<ExternalIssueLink> linkRepository,
IClosingRequirementService closingRequirementService,
ITaskCodeService taskCodeService,
IBacklogWatcherService backlogWatcherService,
IMentionService mentionService,
ILogger<IssueSyncService> logger)
{
_mentionService = mentionService;
_backlogWatcherService = backlogWatcherService;
_linkRepository = linkRepository;
_commentLinkRepository = commentLinkRepository;
Expand Down Expand Up @@ -905,7 +908,9 @@ await _commentLinkRepository.InsertAsync(new ExternalCommentLink
private async Task<string> OutboundCommentBodyAsync(BacklogComment comment)
{
var author = comment.CreatedBy ?? await _userRepository.GetByIdAsync(comment.CreatedById);
return $"**{author?.Name ?? "A Taskist user"}** {OutboundMarker}\n\n{comment.Comment?.Trim()}";
var names = await _mentionService.GetNamesAsync([comment.Comment]);
var text = MentionText.ToPlainText(comment.Comment, names).Trim();
return $"**{author?.Name ?? "A Taskist user"}** {OutboundMarker}\n\n{text}";
}

private static string InboundCommentHtml(GitRepositoryContext repository, GitIssueCommentDto comment)
Expand Down
2 changes: 2 additions & 0 deletions src/Libraries/Taskist.Service/Messages/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ public interface IMessageService

Task<Task> EmailTaskNotificationAsync(Backlog backlog, User loggedUser, string status, bool tester);

Task EmailMentionAsync(Backlog backlog, User recipient, string authorName, string excerpt);

#endregion
}
38 changes: 38 additions & 0 deletions src/Libraries/Taskist.Service/Messages/MessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,44 @@ public async Task<Task> EmailTaskNotificationAsync(Backlog backlog, User loggedU
return Task.CompletedTask;
}

public async Task EmailMentionAsync(Backlog backlog, User recipient, string authorName, string excerpt)
{
if (backlog == null || recipient == null || string.IsNullOrWhiteSpace(recipient.Email))
return;

var emailTemplate = await _emailTemplateService.GetByNameAsync(EmailTemplateType.Mentioned.ToString());
if (emailTemplate == null || !emailTemplate.Active || string.IsNullOrEmpty(emailTemplate.EmailBody))
return;

var emailAccount = await _emailAccounteService.GetByIdAsync(emailTemplate.EmailAccountId);
if (emailAccount == null || !emailAccount.Active)
return;

var tokenValues = new Dictionary<string, string>
{
{ "url", WebUtility.HtmlEncode($"{_httpHelper.GetBaseURL()}/backlog/edit/{backlog.Id}") },
{ "task_id", backlog.Id.ToString() },
{ "display_name", WebUtility.HtmlEncode(recipient.Name) },
{ "author", WebUtility.HtmlEncode(authorName) },
{ "title", WebUtility.HtmlEncode(backlog.Title) },
{ "project_name", WebUtility.HtmlEncode(backlog.Project?.Name ?? string.Empty) },
{ "comment", WebUtility.HtmlEncode(excerpt).Replace("\n", "<br/>") }
};
var subjectValues = new Dictionary<string, string>
{
{ "task_id", backlog.Id.ToString() },
{ "author", authorName },
{ "title", backlog.Title }
};

var body = ReplaceTokensRegex(emailTemplate.EmailBody, tokenValues);
var subject = ReplaceTokensRegex(emailTemplate.EmailSubject ?? string.Empty, subjectValues);
var email = recipient.Email;
var name = recipient.Name;

_backgroundJobClient.Enqueue(() => _emailSenderService.SendEmailAsync(emailAccount, subject, body, email, name));
}

#endregion

#region Helpers
Expand Down
23 changes: 18 additions & 5 deletions src/Libraries/Taskist.Service/WorkItems/BacklogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class BacklogService : IBacklogService
protected readonly IntegrationSettings _integrationSettings;
protected readonly IRepository<BacklogWatcher> _backlogWatcherRepository;
protected readonly IBacklogWatcherService _backlogWatcherService;
protected readonly IMentionService _mentionService;

#endregion

Expand All @@ -76,8 +77,10 @@ public BacklogService(IRepository<Backlog> backlogRepository,
IClosingRequirementService closingRequirementService,
IntegrationSettings integrationSettings,
IRepository<BacklogWatcher> backlogWatcherRepository,
IBacklogWatcherService backlogWatcherService)
IBacklogWatcherService backlogWatcherService,
IMentionService mentionService)
{
_mentionService = mentionService;
_integrationSettings = integrationSettings;
_backlogWatcherRepository = backlogWatcherRepository;
_backlogWatcherService = backlogWatcherService;
Expand Down Expand Up @@ -1587,15 +1590,25 @@ await _backlogCommentRepository.InsertAsync(new BacklogComment
await AddToNotification(ChatEvent.Commented, backlog, notifications, $"A new comment was added by {loggedUserName}");
await _notificationChannelService.TaskUpdatesAsync(notifications);

var excerpt = HtmlText.ToPlainText(comment, 200);
await _backlogWatcherService.NotifyAsync(backlog, new TaskWatchNotice
var names = await _mentionService.GetNamesAsync([comment]);
var excerpt = HtmlText.ToPlainText(MentionText.ToPlainText(comment, names), 200);
if (string.IsNullOrWhiteSpace(excerpt))
excerpt = "New comment";

var mentioned = await _mentionService.ResolveAsync(backlog, comment, loggedUserId);

var watchNotice = new TaskWatchNotice
{
Type = NotificationType.TaskCommented,
Detail = string.IsNullOrWhiteSpace(excerpt) ? "New comment" : excerpt,
Detail = excerpt,
ActorId = loggedUserId,
ActorName = loggedUserName
});
};
watchNotice.Skip.AddRange(mentioned.Select(x => x.Id));
await _backlogWatcherService.NotifyAsync(backlog, watchNotice);
await _backlogWatcherService.AutoWatchAsync(backlogId, loggedUserId, WatchSource.Commented);

await _mentionService.NotifyAsync(backlog, mentioned, loggedUserId, loggedUserName, excerpt);
}
}

Expand Down
38 changes: 5 additions & 33 deletions src/Libraries/Taskist.Service/WorkItems/BacklogWatcherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
using Microsoft.Extensions.Logging;
using Taskist.Core.Common;
using Taskist.Core.Domain.Settings;
using Taskist.Core.Domain.Users;
using Taskist.Core.Domain.WorkItems;
using Taskist.Core.Dtos.Notification;
using Taskist.Core.Dtos.WorkItems;
using Taskist.Core.Enums;
using Taskist.Data.Repository;
using Taskist.Service.Messages;
using Taskist.Service.Users;

namespace Taskist.Service.WorkItems;

Expand All @@ -18,8 +16,7 @@ public class BacklogWatcherService : IBacklogWatcherService
#region Fields

protected readonly IRepository<BacklogWatcher> _watcherRepository;
protected readonly IRepository<User> _userRepository;
protected readonly IUserService _userService;
protected readonly ITaskViewerService _taskViewerService;
protected readonly IUserNotificationService _userNotificationService;
protected readonly WorkItemSettings _workItemSettings;
protected readonly ILogger<BacklogWatcherService> _logger;
Expand All @@ -29,15 +26,13 @@ public class BacklogWatcherService : IBacklogWatcherService
#region Ctor

public BacklogWatcherService(IRepository<BacklogWatcher> watcherRepository,
IRepository<User> userRepository,
IUserService userService,
ITaskViewerService taskViewerService,
IUserNotificationService userNotificationService,
WorkItemSettings workItemSettings,
ILogger<BacklogWatcherService> logger)
{
_watcherRepository = watcherRepository;
_userRepository = userRepository;
_userService = userService;
_taskViewerService = taskViewerService;
_userNotificationService = userNotificationService;
_workItemSettings = workItemSettings;
_logger = logger;
Expand All @@ -60,7 +55,7 @@ public async Task<TaskWatchState> GetStateAsync(Backlog backlog, int userId)

state.Watching = WatcherRecipients.IsWatching(userId, implicitWatchers, rows);

var users = await AllowedUsersAsync(backlog, WatcherRecipients.Watchers(implicitWatchers, rows));
var users = await _taskViewerService.FilterViewersAsync(backlog, WatcherRecipients.Watchers(implicitWatchers, rows));
state.Watchers = users
.Select(x => x.Name)
.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)
Expand Down Expand Up @@ -107,7 +102,7 @@ public async Task NotifyAsync(Backlog backlog, TaskWatchNotice notice)
if (ids.Count == 0)
return;

var users = await AllowedUsersAsync(backlog, ids);
var users = await _taskViewerService.FilterViewersAsync(backlog, ids);
if (users.Count == 0)
return;

Expand Down Expand Up @@ -166,28 +161,5 @@ await _watcherRepository.InsertAsync(new BacklogWatcher
await _watcherRepository.UpdateAsync(row);
}

private async Task<List<User>> AllowedUsersAsync(Backlog backlog, IReadOnlyList<int> ids)
{
if (ids.Count == 0)
return [];

var users = await _userRepository.Table
.Where(x => ids.Contains(x.Id) && !x.Deleted && !x.Locked)
.ToListAsync();

var allowed = new List<User>();
foreach (var user in users)
{
var mapping = await _userService.GetProjectMapping(user.Id, backlog.ProjectId);
if (mapping == null)
continue;

if (mapping.CanViewOthersTask || backlog.AssigneeId == user.Id || backlog.TesterId == user.Id)
allowed.Add(user);
}

return allowed;
}

#endregion
}
15 changes: 15 additions & 0 deletions src/Libraries/Taskist.Service/WorkItems/IMentionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Taskist.Core.Domain.Users;
using Taskist.Core.Domain.WorkItems;

namespace Taskist.Service.WorkItems;

public interface IMentionService
{
Task<IList<User>> GetCandidatesAsync(Backlog backlog, int currentUserId, string? term, int take = 8);

Task<IList<User>> ResolveAsync(Backlog backlog, string? comment, int authorId);

Task<IReadOnlyDictionary<int, string>> GetNamesAsync(IEnumerable<string?> texts);

Task NotifyAsync(Backlog backlog, IList<User> mentioned, int authorId, string authorName, string excerpt);
}
Loading
Loading