diff --git a/src/Presentation/Taskist.Web/Views/Backlog/Edit.cshtml b/src/Presentation/Taskist.Web/Views/Backlog/Edit.cshtml
index 22c4407..8325ae1 100644
--- a/src/Presentation/Taskist.Web/Views/Backlog/Edit.cshtml
+++ b/src/Presentation/Taskist.Web/Views/Backlog/Edit.cshtml
@@ -17,6 +17,7 @@
+
diff --git a/src/Presentation/Taskist.Web/Views/Backlog/Index.cshtml b/src/Presentation/Taskist.Web/Views/Backlog/Index.cshtml
index 303c144..9777ad5 100644
--- a/src/Presentation/Taskist.Web/Views/Backlog/Index.cshtml
+++ b/src/Presentation/Taskist.Web/Views/Backlog/Index.cshtml
@@ -25,6 +25,7 @@
+
}
diff --git a/src/Presentation/Taskist.Web/Views/Notification/_NotificationList.cshtml b/src/Presentation/Taskist.Web/Views/Notification/_NotificationList.cshtml
index 94b72cc..9a90695 100644
--- a/src/Presentation/Taskist.Web/Views/Notification/_NotificationList.cshtml
+++ b/src/Presentation/Taskist.Web/Views/Notification/_NotificationList.cshtml
@@ -12,6 +12,7 @@
NotificationType.TaskStatusChanged => ("fa-arrow-right-arrow-left", "blue"),
NotificationType.TaskCommented => ("fa-comment-dots", "teal"),
NotificationType.TaskAssignmentChanged => ("fa-user-pen", "amber"),
+ NotificationType.Mentioned => ("fa-at", "blue"),
_ => ("fa-bell", "grey")
};
string Age(DateTime utc)
diff --git a/src/Presentation/Taskist.Web/wwwroot/css/pages/backlog-task.css b/src/Presentation/Taskist.Web/wwwroot/css/pages/backlog-task.css
index ab3312d..fe6a32b 100644
--- a/src/Presentation/Taskist.Web/wwwroot/css/pages/backlog-task.css
+++ b/src/Presentation/Taskist.Web/wwwroot/css/pages/backlog-task.css
@@ -299,6 +299,72 @@
display: flex;
gap: 8px;
align-items: flex-end;
+ position: relative;
+}
+
+.mention {
+ color: var(--cui-primary);
+ background: rgba(var(--cui-primary-rgb), 0.1);
+ border-radius: 4px;
+ padding: 0 3px;
+ font-weight: 600;
+ white-space: nowrap;
+}
+
+.mention--unknown {
+ color: #8a93a2;
+ background: transparent;
+ font-weight: 400;
+}
+
+.mention-menu {
+ position: absolute;
+ left: 0;
+ bottom: calc(100% + 4px);
+ z-index: 1060;
+ min-width: 220px;
+ max-width: 320px;
+ max-height: 240px;
+ overflow-y: auto;
+ margin: 0;
+ padding: 4px;
+ list-style: none;
+ background: #fff;
+ border: 1px solid #dde3ea;
+ border-radius: 8px;
+ box-shadow: 0 6px 18px rgba(16, 24, 40, 0.12);
+}
+
+.mention-menu__item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ padding: 6px 8px;
+ border: 0;
+ border-radius: 6px;
+ background: transparent;
+ color: #33455c;
+ font-size: 0.85rem;
+ text-align: left;
+}
+
+.mention-menu__item:hover,
+.mention-menu__item.is-active {
+ background: rgba(var(--cui-primary-rgb), 0.12);
+}
+
+.mention-menu__item img {
+ width: 22px;
+ height: 22px;
+ border-radius: 50%;
+ object-fit: cover;
+}
+
+.mention-menu__empty {
+ padding: 6px 8px;
+ font-size: 0.8rem;
+ color: #8a93a2;
}
.comment-input-wrap textarea {
diff --git a/src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css b/src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css
index 872f327..6e76e60 100644
--- a/src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css
+++ b/src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css
@@ -567,6 +567,13 @@
background: #212631;
border-top: 1px solid #4a566d;
}
+[data-coreui-theme=dark] .mention-menu {
+ background: #212631;
+ border: 1px solid #4c5560;
+}
+[data-coreui-theme=dark] .mention-menu__item {
+ color: #bcc5d2;
+}
[data-coreui-theme=dark] .history-item::before {
background: #303b46;
}
diff --git a/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-comments.js b/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-comments.js
index 2685d04..f4323c6 100644
--- a/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-comments.js
+++ b/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-comments.js
@@ -28,6 +28,8 @@ var BacklogComments = (function () {
var comment = $input.val().trim();
if (!comment) return;
+ if (window.BacklogMentions) comment = BacklogMentions.encode($root, comment);
+
var dto = { id: $root.data("task-id"), comment: comment, postToIssue: $root.find(".comment-post-to-issue").is(":checked") };
JSManager.ajaxPost($root.data("create-url"), dto, "comment-box", "Processing...", function (response) {
if (!response || response.success !== true) {
@@ -43,7 +45,9 @@ var BacklogComments = (function () {
$item.find(".comment-avatar").html($('
![]()
').attr("src", $root.data("photo-url") + "?userId=" + response.commentbyid));
$item.find(".comment-author").text(response.commentby);
$item.find(".comment-time").text("just now");
- $item.find(".comment-text").text(comment);
+ if (typeof response.html === "string") $item.find(".comment-text").html(response.html);
+ else $item.find(".comment-text").text(comment);
+ if (window.BacklogMentions) BacklogMentions.reset($root);
$list.append($item);
$root.find(".comments-empty").addClass("d-none");
$input.val("").trigger("input").focus();
diff --git a/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-mentions.js b/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-mentions.js
new file mode 100644
index 0000000..9fb1e15
--- /dev/null
+++ b/src/Presentation/Taskist.Web/wwwroot/js/pages/backlog/backlog-mentions.js
@@ -0,0 +1,157 @@
+var BacklogMentions = (function () {
+ "use strict";
+
+ var state = null;
+ var timer = null;
+ var requestNo = 0;
+
+ function picked($root) {
+ var list = $root.data("mentions");
+ if (!list) {
+ list = [];
+ $root.data("mentions", list);
+ }
+ return list;
+ }
+
+ function encode($root, text) {
+ var list = picked($root).slice().sort(function (a, b) { return b.name.length - a.name.length; });
+ list.forEach(function (m) {
+ text = text.split("@" + m.name).join(m.token);
+ });
+ return text;
+ }
+
+ function reset($root) {
+ $root.data("mentions", []);
+ close();
+ }
+
+ function queryAt(input) {
+ var caret = input.selectionStart;
+ if (caret !== input.selectionEnd) return null;
+ var match = /(^|\s)@([^\s@]{0,30})$/.exec(input.value.slice(0, caret));
+ if (!match) return null;
+ return { start: caret - match[2].length - 1, term: match[2] };
+ }
+
+ function close() {
+ if (state && state.$menu) state.$menu.remove();
+ state = null;
+ clearTimeout(timer);
+ }
+
+ function render() {
+ if (!state) return;
+ if (!state.$menu) {
+ state.$menu = $('');
+ state.$input.closest(".comment-input-wrap").append(state.$menu);
+ }
+
+ state.$menu.empty();
+ if (state.items.length === 0) {
+ state.$menu.append($('').text(state.$root.data("mention-empty") || ""));
+ return;
+ }
+
+ state.items.forEach(function (item, i) {
+ var $btn = $('')
+ .toggleClass("is-active", i === state.index)
+ .attr("aria-selected", i === state.index ? "true" : "false")
+ .attr("data-index", i)
+ .append($('
![]()
').attr("src", item.photo))
+ .append($("
").text(item.name));
+ state.$menu.append($("
").append($btn));
+ });
+ }
+
+ function search(term) {
+ var url = state && state.$root.data("mention-url");
+ if (!url) return;
+
+ clearTimeout(timer);
+ timer = setTimeout(function () {
+ var current = ++requestNo;
+ $.ajax({ url: url, data: { q: term }, dataType: "json" })
+ .done(function (items) {
+ if (!state || current !== requestNo) return;
+ state.items = items || [];
+ state.index = 0;
+ render();
+ })
+ .fail(close);
+ }, 150);
+ }
+
+ function choose(item) {
+ if (!state || !item) return;
+
+ var input = state.$input[0];
+ var caret = input.selectionStart;
+ var insert = "@" + item.name + " ";
+ input.value = input.value.slice(0, state.start) + insert + input.value.slice(caret);
+ var position = state.start + insert.length;
+ input.setSelectionRange(position, position);
+
+ var list = picked(state.$root);
+ if (!list.some(function (m) { return m.token === item.token; }))
+ list.push({ name: item.name, token: item.token });
+
+ var $input = state.$input;
+ close();
+ $input.trigger("input").trigger("focus");
+ }
+
+ $(document).on("input click", ".comments-root .comment-input", function () {
+ var $input = $(this);
+ var query = queryAt(this);
+ if (!query) {
+ close();
+ return;
+ }
+
+ if (!state || state.$input[0] !== this) {
+ close();
+ state = { $root: $input.closest(".comments-root"), $input: $input, $menu: null, items: [], index: 0 };
+ }
+
+ state.start = query.start;
+ search(query.term);
+ });
+
+ $(document).on("mousedown", ".mention-menu__item", function (e) {
+ e.preventDefault();
+ if (state) choose(state.items[Number.parseInt($(this).attr("data-index"), 10)]);
+ });
+
+ $(document).on("blur", ".comments-root .comment-input", function () {
+ setTimeout(function () {
+ if (state && document.activeElement !== state.$input[0]) close();
+ }, 150);
+ });
+
+ document.addEventListener("keydown", function (e) {
+ if (!state || !state.$menu || e.target !== state.$input[0]) return;
+
+ if (e.key === "Escape") {
+ close();
+ } else if (state.items.length === 0) {
+ return;
+ } else if (e.key === "ArrowDown") {
+ state.index = (state.index + 1) % state.items.length;
+ render();
+ } else if (e.key === "ArrowUp") {
+ state.index = (state.index - 1 + state.items.length) % state.items.length;
+ render();
+ } else if (e.key === "Enter" || e.key === "Tab") {
+ choose(state.items[state.index]);
+ } else {
+ return;
+ }
+
+ e.preventDefault();
+ e.stopPropagation();
+ }, true);
+
+ return { encode: encode, reset: reset };
+})();
diff --git a/src/Tests/Taskist.Tests/Common/MentionTextTests.cs b/src/Tests/Taskist.Tests/Common/MentionTextTests.cs
new file mode 100644
index 0000000..23c8dec
--- /dev/null
+++ b/src/Tests/Taskist.Tests/Common/MentionTextTests.cs
@@ -0,0 +1,89 @@
+using Taskist.Core.Common;
+
+namespace Taskist.Tests.Common;
+
+public class MentionTextTests
+{
+ #region Helpers
+
+ private static readonly Dictionary
Names = new() { [4] = "Bob Tester", [7] = "Cara " };
+
+ #endregion
+
+ #region ParseUserIds
+
+ [Fact]
+ public void ParseUserIds_ReturnsEachMentionOnce_InOrder()
+ {
+ Assert.Equal([7, 4], MentionText.ParseUserIds("@[7] please check, @[4] and @[7] again"));
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("no mentions here")]
+ [InlineData("email bob@[example] or @[] or @[abc] or @[0]")]
+ [InlineData("@ [4] and @[ 4]")]
+ public void ParseUserIds_IgnoresTextThatIsNotAToken(string? text)
+ {
+ Assert.Empty(MentionText.ParseUserIds(text));
+ }
+
+ [Fact]
+ public void ParseUserIds_IgnoresOverlongIds()
+ {
+ Assert.Empty(MentionText.ParseUserIds("@[12345678901]"));
+ }
+
+ [Fact]
+ public void Token_RoundTripsThroughTheParser()
+ {
+ Assert.Equal([42], MentionText.ParseUserIds("hi " + MentionText.Token(42)));
+ }
+
+ #endregion
+
+ #region ToPlainText
+
+ [Fact]
+ public void ToPlainText_ReplacesTokensWithNames()
+ {
+ Assert.Equal("@Bob Tester can you look?", MentionText.ToPlainText("@[4] can you look?", Names));
+ }
+
+ [Fact]
+ public void ToPlainText_UnknownUser_IsNamedGenerically()
+ {
+ Assert.Equal("ping @unknown user", MentionText.ToPlainText("ping @[99]", Names));
+ }
+
+ #endregion
+
+ #region ToHtml
+
+ [Fact]
+ public void ToHtml_EncodesTextAndHighlightsMentions()
+ {
+ var html = MentionText.ToHtml("hi @[4] & @[7]", Names);
+
+ Assert.Equal("<b>hi</b> @Bob Tester & "
+ + "@Cara <Ops>", html);
+ }
+
+ [Fact]
+ public void ToHtml_UnknownUser_IsMarked_WithoutLeakingTheId()
+ {
+ var html = MentionText.ToHtml("@[99]", Names);
+
+ Assert.Contains("mention--unknown", html);
+ Assert.DoesNotContain("99", html);
+ }
+
+ [Fact]
+ public void ToHtml_KeepsNewlines_ForPreWrapDisplay()
+ {
+ Assert.Equal("a\nb", MentionText.ToHtml("a\nb", Names));
+ }
+
+ #endregion
+}