Skip to content

A platform for community discussion. Free, open, simple.

UX: improve chat transcript styles in posts (#44437)

Kris0162b69cbec2
diff --git a/frontend/discourse/app/lib/click-track.js b/frontend/discourse/app/lib/click-track.js
index 2cd5ca11c6a..a3ec07c81b2 100644
--- a/frontend/discourse/app/lib/click-track.js
+++ b/frontend/discourse/app/lib/click-track.js
@@ -93,6 +93,7 @@ export default {
["mention", "mention-group"].some((name) =>
link.classList.contains(name)
) ||
+ link.matches("[data-user-card], [data-group-card]") ||
(link.matches('a.hashtag-cooked[data-type="category"][data-id]') &&
owner?.lookup("service:site-settings")?.enable_category_hashtag_cards)
) {
diff --git a/frontend/discourse/tests/unit/lib/click-track-test.js b/frontend/discourse/tests/unit/lib/click-track-test.js
index 13010f89c9e..8163c9d2379 100644
--- a/frontend/discourse/tests/unit/lib/click-track-test.js
+++ b/frontend/discourse/tests/unit/lib/click-track-test.js
@@ -63,6 +63,8 @@ module("Unit | Utility | click-track", function (hooks) {
<a class="mention" href="/u/joe">@joe</a>
<a class="hashtag-cooked" href="/c/staff/42" data-type="category" data-slug="staff"><svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg><span>staff</span></a>
<a class="mention-group" href="/g/support">@support</a>
+ <a class="user-card-link" href="/u/joe" data-user-card="joe">joe</a>
+ <a class="group-card-link" href="/g/support" data-group-card="support">support</a>
<a class="hashtag-cooked category-card-hashtag" href="/c/staff/42" data-type="category" data-id="42">staff</a>
<a class="mailto" href="mailto:[email protected]">email-me</a>
<a class="a-without-href">no href</a>
@@ -244,6 +246,11 @@ module("Unit | Utility | click-track", function (hooks) {
assert.true(track(generateClickEventOn(".mention-group")));
});
+ test("leaves user and group card links to the card listener", async function (assert) {
+ assert.true(track(generateClickEventOn(".user-card-link")));
+ assert.true(track(generateClickEventOn(".group-card-link")));
+ });
+
test("leaves category card hashtags to the card listener", async function (assert) {
this.owner.lookup("service:site-settings").enable_category_hashtag_cards =
true;
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
index cf7fb651222..e64ebf2aeb9 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
@@ -10,6 +10,7 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import { i18n } from "discourse-i18n";
import { clearChatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
import { buildGifPickHandler } from "discourse/plugins/chat/discourse/lib/gif-pick-handler";
+import groupChatTranscripts from "discourse/plugins/chat/discourse/lib/group-chat-transcripts";
import ChannelHashtagType from "discourse/plugins/chat/discourse/lib/hashtag-types/channel";
import richEditorExtension from "../../lib/rich-editor-extension";
import ChatHeaderIcon from "../components/chat/header/icon";
@@ -62,6 +63,39 @@ class ChatSetupInit {
}
});
+ // transcripts are post content, so they're decorated even for users who
+ // can't chat, anons included
+ api.decorateCookedElement((elem) => {
+ const currentUser = owner.lookup("service:current-user");
+ const currentUserTimezone = currentUser?.user_option?.timezone;
+ const chatTranscriptElements =
+ elem.querySelectorAll(".chat-transcript");
+
+ chatTranscriptElements.forEach((el) => {
+ const dateTimeRaw = el.dataset["datetime"];
+ const dateTimeEl = el.querySelector(
+ ".chat-transcript-datetime a, .chat-transcript-datetime span"
+ );
+
+ if (currentUserTimezone) {
+ dateTimeEl.innerText = moment
+ .tz(dateTimeRaw, currentUserTimezone)
+ .format(i18n("dates.long_no_year"));
+ } else {
+ dateTimeEl.innerText = moment(dateTimeRaw).format(
+ i18n("dates.long_no_year")
+ );
+ }
+
+ dateTimeEl.dataset.dateFormatted = true;
+ });
+
+ groupChatTranscripts(elem, {
+ site: owner.lookup("service:site"),
+ chatChannelsManager: owner.lookup("service:chat-channels-manager"),
+ });
+ });
+
if (!this.chatService.userCanChat) {
// include chat elements for anons (except header icon)
if (
@@ -165,34 +199,6 @@ class ChatSetupInit {
});
}
- // we want to decorate the chat quote dates regardless
- // of whether the current user has chat enabled
- api.decorateCookedElement((elem) => {
- const currentUser = owner.lookup("service:current-user");
- const currentUserTimezone = currentUser?.user_option?.timezone;
- const chatTranscriptElements =
- elem.querySelectorAll(".chat-transcript");
-
- chatTranscriptElements.forEach((el) => {
- const dateTimeRaw = el.dataset["datetime"];
- const dateTimeEl = el.querySelector(
- ".chat-transcript-datetime a, .chat-transcript-datetime span"
- );
-
- if (currentUserTimezone) {
- dateTimeEl.innerText = moment
- .tz(dateTimeRaw, currentUserTimezone)
- .format(i18n("dates.long_no_year"));
- } else {
- dateTimeEl.innerText = moment(dateTimeRaw).format(
- i18n("dates.long_no_year")
- );
- }
-
- dateTimeEl.dataset.dateFormatted = true;
- });
- });
-
if (!this.chatService.userCanChat || EmbedMode.enabled) {
return;
}
diff --git a/plugins/chat/assets/javascripts/discourse/lib/group-chat-transcripts.js b/plugins/chat/assets/javascripts/discourse/lib/group-chat-transcripts.js
new file mode 100644
index 00000000000..9ac07553048
--- /dev/null
+++ b/plugins/chat/assets/javascripts/discourse/lib/group-chat-transcripts.js
@@ -0,0 +1,316 @@
+import { ajax } from "discourse/lib/ajax";
+import domFromString from "discourse/lib/dom-from-string";
+import getURL from "discourse/lib/get-url";
+import { getHashtagTypeClasses } from "discourse/lib/hashtag-type-registry";
+import { iconHTML } from "discourse/lib/icon-library";
+import { emojiUnescape } from "discourse/lib/text";
+import { userPath } from "discourse/lib/url";
+import { escapeExpression } from "discourse/lib/utilities";
+import { i18n } from "discourse-i18n";
+import { transcriptSourcePresentation } from "discourse/plugins/chat/discourse/lib/transcript-source-types";
+
+export default function groupChatTranscripts(
+ element,
+ { site, chatChannelsManager }
+) {
+ const transcripts = [...element.querySelectorAll(".chat-transcript")].filter(
+ (transcript) =>
+ !transcript.parentElement.closest(
+ ".chat-transcript, .chat-transcript-group"
+ )
+ );
+
+ const groups = [];
+ let group;
+ transcripts.forEach((transcript) => {
+ if (
+ !group ||
+ transcript.previousElementSibling !== group ||
+ !isContinuation(transcript)
+ ) {
+ group = buildGroup(transcript, { site, chatChannelsManager });
+ groups.push(group);
+ transcript.before(group);
+ }
+
+ group.querySelector(".chat-transcript-group__body").append(transcript);
+ expandThread(transcript);
+ });
+
+ groups.forEach((transcriptGroup) => {
+ const channelUrl = linkableChannelUrl(transcriptGroup);
+ if (channelUrl) {
+ linkTimestamps(transcriptGroup, channelUrl);
+ linkThreadTitles(transcriptGroup, channelUrl);
+ }
+ linkAuthors(transcriptGroup);
+ promoteSoleThread(transcriptGroup);
+ });
+}
+
+// ids come from cooked attributes a post author can write, so they're encoded to
+// keep each one a single path segment
+function channelPath(channelId) {
+ return getURL(`/chat/c/-/${encodeURIComponent(channelId)}`);
+}
+
+function linkableChannelUrl(group) {
+ const first = group.querySelector(".chat-transcript");
+ const { channelId } = first.dataset;
+
+ // an unlinked first timestamp means links were left out on purpose (archives)
+ if (!channelId || !ownTimestamp(first)?.querySelector(":scope > a")) {
+ return;
+ }
+
+ return channelPath(channelId);
+}
+
+function linkTimestamps(group, channelUrl) {
+ group.querySelectorAll(".chat-transcript").forEach((transcript) => {
+ const unlinked = ownTimestamp(transcript)?.querySelector(
+ ":scope > span[title]"
+ );
+ if (!unlinked) {
+ return;
+ }
+
+ const { messageId } = transcript.dataset;
+ const threadId = transcript.parentElement.closest(
+ ".chat-transcript[data-thread-id]"
+ )?.dataset.threadId;
+
+ const link = document.createElement("a");
+ link.href = threadId
+ ? `${channelUrl}/t/${encodeURIComponent(threadId)}/${encodeURIComponent(messageId)}`
+ : `${channelUrl}/${encodeURIComponent(messageId)}`;
+ link.title = unlinked.title;
+ link.append(...unlinked.childNodes);
+ unlinked.replaceWith(link);
+ });
+}
+
+function linkThreadTitles(group, channelUrl) {
+ group
+ .querySelectorAll(".chat-transcript[data-thread-id]")
+ .forEach((transcript) => {
+ const title = transcript.querySelector(
+ ".chat-transcript-thread-header__title"
+ );
+ if (!title || title.querySelector(":scope > a")) {
+ return;
+ }
+
+ const link = document.createElement("a");
+ link.href = `${channelUrl}/t/${encodeURIComponent(transcript.dataset.threadId)}`;
+ link.append(...title.childNodes);
+ title.append(link);
+ });
+}
+
+function promoteSoleThread(group) {
+ const header = group.querySelector(".chat-transcript-group__header");
+ const body = group.querySelector(".chat-transcript-group__body");
+ const threadHeader = body.querySelector(".chat-transcript-thread-header");
+
+ if (!header || !threadHeader || body.children.length !== 1) {
+ return;
+ }
+
+ const thread = document.createElement("span");
+ thread.classList.add("chat-transcript-group__thread");
+ thread.append(...threadHeader.childNodes);
+ threadHeader.remove();
+
+ header.querySelector(".chat-transcript-group__channel").after(thread);
+}
+
+function linkAuthors(group) {
+ group.querySelectorAll(".chat-transcript").forEach((transcript) => {
+ const { username } = transcript.dataset;
+ if (!username) {
+ return;
+ }
+
+ const avatarLink = wrapInUserLink(
+ transcript.querySelector(".chat-transcript-user-avatar"),
+ username
+ );
+ // the username link carries the accessible name; this is a duplicate target
+ avatarLink?.setAttribute("tabindex", "-1");
+ avatarLink?.setAttribute("aria-hidden", "true");
+
+ wrapInUserLink(
+ transcript.querySelector(".chat-transcript-username"),
+ username
+ );
+ });
+}
+
+function wrapInUserLink(element, username) {
+ // composer previews cook without avatars, leaving the slot empty
+ if (!element?.textContent.trim() && !element?.querySelector("img")) {
+ return;
+ }
+
+ if (element.querySelector(":scope > a")) {
+ return;
+ }
+
+ const link = document.createElement("a");
+ link.href = userPath(encodeURIComponent(username.toLowerCase()));
+ link.dataset.userCard = username;
+ link.append(...element.childNodes);
+ element.append(link);
+ return link;
+}
+
+// a thread's replies are nested inside it, after its own timestamp
+function ownTimestamp(transcript) {
+ return transcript.querySelector(".chat-transcript-datetime");
+}
+
+// Only a transcript's first block names the channel or source. Later blocks aren't
+// always marked chained, e.g. one author's messages are split where a thread starts.
+function isContinuation(transcript) {
+ const { channelName, source } = transcript.dataset;
+ return !channelName && !source;
+}
+
+function expandThread(transcript) {
+ const details = transcript.querySelector(":scope > details");
+ if (!details) {
+ return;
+ }
+
+ const summary = details.querySelector(":scope > summary");
+ summary?.replaceWith(...summary.childNodes);
+ details.replaceWith(...details.childNodes);
+}
+
+function buildGroup(transcript, services) {
+ const group = document.createElement("div");
+ group.classList.add("chat-transcript-group");
+
+ const { channelName, channelId, source, sourceType } = transcript.dataset;
+ const name = channelName || source;
+ if (name) {
+ group.append(
+ buildTranscriptHeader(
+ { channelName, channelId, source, sourceType },
+ services
+ )
+ );
+
+ transcript.querySelector(":scope > .chat-transcript-meta")?.remove();
+ transcript
+ .querySelectorAll(".chat-transcript-channel")
+ .forEach((link) => link.remove());
+ }
+
+ // the body scrolls when long, so it must be reachable by keyboard
+ const body = document.createElement("div");
+ body.classList.add("chat-transcript-group__body");
+ body.tabIndex = 0;
+ body.setAttribute("role", "region");
+ body.setAttribute(
+ "aria-label",
+ name
+ ? i18n("chat.quote.transcript_region", { channel: name })
+ : i18n("chat.quote.transcript_label")
+ );
+ group.append(body);
+
+ return group;
+}
+
+/**
+ * Heads a transcript with the chat channel it was quoted from, or with an
+ * unlinked source presented by its registered source type.
+ */
+export function buildTranscriptHeader(
+ { channelName, channelId, source, sourceType },
+ services
+) {
+ const header = document.createElement("div");
+ header.classList.add("chat-transcript-group__header");
+
+ const fromChannel = !!channelName;
+ const linked = fromChannel && channelId;
+
+ const channel = document.createElement(linked ? "a" : "span");
+ channel.classList.add("hashtag-cooked", "chat-transcript-group__channel");
+ if (linked) {
+ channel.href = channelPath(channelId);
+ }
+
+ let iconMarkup, labelText;
+ if (fromChannel) {
+ iconMarkup = channelIconHTML(channelId, services);
+ labelText = i18n("chat.quote.transcript_label");
+ } else {
+ const presentation = transcriptSourcePresentation(sourceType);
+ iconMarkup = iconHTML(presentation.icon);
+ labelText = presentation.label;
+ }
+
+ channel.innerHTML = `${iconMarkup}<span>${emojiUnescape(
+ escapeExpression(fromChannel ? channelName : source)
+ )}</span>`;
+
+ // channels the user hasn't joined (or that haven't loaded yet) need a lookup
+ if (
+ linked &&
+ getHashtagTypeClasses().channel &&
+ !findChannel(channelId, services)
+ ) {
+ fetchChannelEmoji(channelId).then((emoji) => {
+ if (emoji) {
+ channel.firstElementChild.replaceWith(
+ domFromString(channelIconHTML(channelId, services, emoji))[0]
+ );
+ }
+ });
+ }
+
+ const label = document.createElement("span");
+ label.classList.add("chat-transcript-group__label");
+ label.textContent = labelText;
+
+ header.append(channel, label);
+ return header;
+}
+
+function channelIconHTML(channelId, services, emoji) {
+ const icon = services.site.hashtag_icons?.channel ?? "comment";
+ const channelType = getHashtagTypeClasses().channel;
+
+ if (channelType && channelId) {
+ return channelType.generateIconHTML({
+ id: parseInt(channelId, 10),
+ icon,
+ emoji: emoji ?? findChannel(channelId, services)?.emoji,
+ });
+ }
+
+ return iconHTML(icon);
+}
+
+const channelEmojiRequests = new Map();
+
+function fetchChannelEmoji(channelId) {
+ if (!channelEmojiRequests.has(channelId)) {
+ channelEmojiRequests.set(
+ channelId,
+ ajax("/hashtags/by-ids", { data: { channel: [channelId] } })
+ .then((result) => result.channel?.[0]?.emoji)
+ .catch(() => null)
+ );
+ }
+ return channelEmojiRequests.get(channelId);
+}
+
+function findChannel(channelId, { chatChannelsManager }) {
+ const id = parseInt(channelId, 10);
+ return chatChannelsManager?.channels.find((channel) => channel.id === id);
+}
diff --git a/plugins/chat/assets/javascripts/discourse/lib/transcript-source-types.js b/plugins/chat/assets/javascripts/discourse/lib/transcript-source-types.js
new file mode 100644
index 00000000000..8a0537cfc2f
--- /dev/null
+++ b/plugins/chat/assets/javascripts/discourse/lib/transcript-source-types.js
@@ -0,0 +1,23 @@
+import { i18n } from "discourse-i18n";
+
+const DEFAULT_ICON = "comment";
+
+const sourceTypes = new Map();
+
+export function registerTranscriptSourceType(type, { icon, label }) {
+ sourceTypes.set(type, { icon, label });
+}
+
+// sourceType comes from post markup, so unknown values fall back to the defaults
+export function transcriptSourcePresentation(type) {
+ const registered = sourceTypes.get(type);
+
+ return {
+ icon: registered?.icon ?? DEFAULT_ICON,
+ label: i18n(registered?.label ?? "chat.quote.transcript_label"),
+ };
+}
+
+export function resetTranscriptSourceTypes() {
+ sourceTypes.clear();
+}
diff --git a/plugins/chat/assets/javascripts/discourse/pre-initializers/chat-plugin-api.js b/plugins/chat/assets/javascripts/discourse/pre-initializers/chat-plugin-api.js
index e8c426e60cf..b9ed9d56c15 100644
--- a/plugins/chat/assets/javascripts/discourse/pre-initializers/chat-plugin-api.js
+++ b/plugins/chat/assets/javascripts/discourse/pre-initializers/chat-plugin-api.js
@@ -5,6 +5,10 @@ import {
} from "discourse/plugins/chat/discourse/components/chat-message";
import { registerChatComposerButton } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
import { removeChatComposerSecondaryActions } from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
+import {
+ registerTranscriptSourceType,
+ resetTranscriptSourceTypes,
+} from "discourse/plugins/chat/discourse/lib/transcript-source-types";
import { addChatDrawerStateCallback } from "discourse/plugins/chat/discourse/services/chat-state-manager";
/**
@@ -125,6 +129,25 @@ import { addChatDrawerStateCallback } from "discourse/plugins/chat/discourse/ser
* api.removeChatComposerSecondaryActions("copyLink", "select");
*/
+/**
+ * Registers how chat transcripts quoted in posts present a non-channel source,
+ * named by the transcript's `sourceType` attribute
+ *
+ * @memberof PluginApi
+ * @instance
+ * @function registerChatTranscriptSourceType
+ * @param {string} type - value of the `sourceType` attribute
+ * @param {Object} options
+ * @param {string} options.icon - icon shown before the source name
+ * @param {string} [options.label] - translation key for the header label
+ * @example
+ *
+ * api.registerChatTranscriptSourceType("meeting", {
+ * icon: "users",
+ * label: "my_plugin.meeting_transcript",
+ * });
+ */
+
export default {
name: "chat-plugin-api",
after: "inject-discourse-objects",
@@ -174,6 +197,18 @@ export default {
});
}
+ if (!apiPrototype.hasOwnProperty("registerChatTranscriptSourceType")) {
+ Object.defineProperty(
+ apiPrototype,
+ "registerChatTranscriptSourceType",
+ {
+ value(type, options) {
+ registerTranscriptSourceType(type, options);
+ },
+ }
+ );
+ }
+
if (!apiPrototype.hasOwnProperty("removeChatComposerSecondaryActions")) {
Object.defineProperty(
apiPrototype,
@@ -190,5 +225,6 @@ export default {
teardown() {
resetChatMessageDecorators();
+ resetTranscriptSourceTypes();
},
};
diff --git a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js
index 382dfcfe69f..5c63ff996ab 100644
--- a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js
+++ b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js
@@ -28,6 +28,9 @@ const chatTranscriptRule = {
const channelId = tagInfo.attrs.channelId;
const threadId = tagInfo.attrs.threadId;
const threadTitle = tagInfo.attrs.threadTitle;
+ // names a transcript that didn't come from a chat channel; never linked
+ const source = tagInfo.attrs.source;
+ const sourceType = tagInfo.attrs.sourceType;
const channelLink = channelId
? options.getURL(`/chat/c/-/${channelId}`)
: null;
@@ -148,6 +151,14 @@ const chatTranscriptRule = {
wrapperDivToken.attrs.push(["data-channel-id", channelId]);
}
+ if (source) {
+ wrapperDivToken.attrs.push(["data-source", source]);
+ }
+
+ if (sourceType) {
+ wrapperDivToken.attrs.push(["data-source-type", sourceType]);
+ }
+
if (multiQuote) {
wrapperDivToken.attrs.push(["data-multiquote", "true"]);
}
@@ -361,6 +372,8 @@ export function setup(helper) {
"div[data-message-id]",
"div[data-channel-name]",
"div[data-channel-id]",
+ "div[data-source]",
+ "div[data-source-type]",
"div[data-username]",
"div[data-datetime]",
"a.chat-transcript-channel",
diff --git a/plugins/chat/assets/javascripts/lib/rich-editor-extension.js b/plugins/chat/assets/javascripts/lib/rich-editor-extension.js
index 8e218171315..e7ad0804c44 100644
--- a/plugins/chat/assets/javascripts/lib/rich-editor-extension.js
+++ b/plugins/chat/assets/javascripts/lib/rich-editor-extension.js
@@ -1,6 +1,7 @@
-import getURL from "discourse/lib/get-url";
+import { getOwnerWithFallback } from "discourse/lib/get-owner";
import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";
import { i18n } from "discourse-i18n";
+import { buildTranscriptHeader } from "discourse/plugins/chat/discourse/lib/group-chat-transcripts";
/** @type {RichEditorExtension} */
const extension = {
@@ -12,6 +13,8 @@ const extension = {
datetime: {},
channel: {},
channelId: {},
+ source: { default: null },
+ sourceType: { default: null },
html: {},
rawContent: {},
multiQuote: {},
@@ -37,41 +40,41 @@ const extension = {
wrapperElement.classList.add("chat-transcript-chained");
}
- let metaElement;
- let channelLinkElement;
+ // only a transcript's first block names the channel or source; later
+ // blocks join its box, which the stylesheet finds through these attributes
if (node.attrs.channel) {
- if (node.attrs.multiQuote) {
- metaElement = document.createElement("div");
- metaElement.classList.add("chat-transcript-meta");
-
- const channelLink = node.attrs.channelId
- ? getURL(`/chat/c/-/${node.attrs.channelId}`)
- : null;
-
- metaElement.innerHTML = i18n("chat.quote.original_channel", {
- channel: dReplaceEmoji(node.attrs.channel),
- channelLink: "",
- });
-
- const metaLinkElement = metaElement.querySelector("a");
- if (metaLinkElement && channelLink) {
- metaLinkElement.href = channelLink;
+ wrapperElement.dataset.channelName = node.attrs.channel;
+ } else if (node.attrs.source) {
+ wrapperElement.dataset.source = node.attrs.source;
+ }
+
+ let headerElement;
+ if (node.attrs.channel || node.attrs.source) {
+ const owner = getOwnerWithFallback();
+ headerElement = buildTranscriptHeader(
+ {
+ channelName: node.attrs.channel,
+ channelId: node.attrs.channelId,
+ source: node.attrs.source,
+ sourceType: node.attrs.sourceType,
+ },
+ {
+ site: owner.lookup("service:site"),
+ chatChannelsManager: owner.lookup(
+ "service:chat-channels-manager"
+ ),
}
- } else {
- channelLinkElement = document.createElement("a");
- channelLinkElement.classList.add("chat-transcript-channel");
- channelLinkElement.href = getURL(
- `/chat/c/-/${node.attrs.channelId}`
- );
- channelLinkElement.innerHTML = `#${dReplaceEmoji(
- node.attrs.channel
- )}`;
- }
+ );
}
const userElement = document.createElement("div");
userElement.classList.add("chat-transcript-user");
+ // avatars can't be looked up here, so this stays an empty placeholder
+ const avatarElement = document.createElement("div");
+ avatarElement.classList.add("chat-transcript-user-avatar");
+ userElement.appendChild(avatarElement);
+
// TODO (martin) Need to use current user's timezone here when we have
// that available.
const formattedDateTime = moment(node.attrs.datetime).format(
@@ -91,14 +94,11 @@ const extension = {
messagesElement.classList.add("chat-transcript-messages");
messagesElement.innerHTML = node.attrs.html;
- if (metaElement) {
- wrapperElement.appendChild(metaElement);
+ if (headerElement) {
+ wrapperElement.appendChild(headerElement);
}
if (node.attrs.threadId) {
- const threadDetailsElement = document.createElement("details");
- const threadSummaryElement = document.createElement("summary");
-
const threadElement = document.createElement("div");
threadElement.classList.add("chat-transcript-thread");
@@ -120,27 +120,17 @@ const extension = {
threadHeaderElement.appendChild(threadTitleElement);
threadElement.appendChild(threadHeaderElement);
threadElement.appendChild(userElement);
-
- if (channelLinkElement) {
- userElement.appendChild(channelLinkElement);
- }
-
threadElement.appendChild(messagesElement);
- threadSummaryElement.appendChild(threadElement);
- threadDetailsElement.appendChild(threadSummaryElement);
+ wrapperElement.appendChild(threadElement);
if (node.attrs.threadHtml) {
- threadDetailsElement.innerHTML += node.attrs.threadHtml;
+ wrapperElement.insertAdjacentHTML(
+ "beforeend",
+ node.attrs.threadHtml
+ );
}
-
- wrapperElement.appendChild(threadDetailsElement);
} else {
wrapperElement.appendChild(userElement);
-
- if (channelLinkElement) {
- userElement.appendChild(channelLinkElement);
- }
-
wrapperElement.appendChild(messagesElement);
}
@@ -201,6 +191,8 @@ const extension = {
datetime: token.attrGet("data-datetime"),
channel: token.attrGet("data-channel-name"),
channelId: token.attrGet("data-channel-id"),
+ source: token.attrGet("data-source"),
+ sourceType: token.attrGet("data-source-type"),
chained: token.attrGet("data-chained"),
multiQuote: token.attrGet("data-multiquote"),
threadId: token.attrGet("data-thread-id"),
diff --git a/plugins/chat/assets/stylesheets/common/chat-transcript.scss b/plugins/chat/assets/stylesheets/common/chat-transcript.scss
index 50ac87b11ae..25a70ea04cc 100644
--- a/plugins/chat/assets/stylesheets/common/chat-transcript.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-transcript.scss
@@ -41,17 +41,28 @@
}
.chat-transcript-username {
- color: var(--primary-high-or-secondary-low);
+ color: var(--secondary-low);
font-weight: bold;
}
.chat-transcript-datetime {
color: var(--primary-high);
- font-size: var(--font-down-2-rem);
+ font-size: var(--font-down-1);
padding: 0 0.5rem;
+ // mirrors the nested date + time sizing in chat
+ > a,
+ > span {
+ font-size: var(--font-down-2);
+ }
+
a {
color: var(--primary-high);
+
+ &:hover,
+ &:focus {
+ color: var(--primary);
+ }
}
}
@@ -72,28 +83,6 @@
}
}
- .topic-body .cooked & {
- > details {
- padding: 0.5rem;
-
- > summary {
- display: flex;
-
- &::before {
- line-height: 1;
- }
-
- .chat-transcript-thread {
- min-width: 0;
-
- &-header {
- margin-bottom: 0.5rem;
- }
- }
- }
- }
- }
-
.chat-transcript-user-avatar .avatar {
aspect-ratio: 20 / 20;
}
@@ -135,8 +124,223 @@
}
}
+.chat-transcript-group {
+ margin: 1rem 0;
+ border: 1px solid var(--content-border-color);
+ border-radius: var(--d-border-radius-large);
+ overflow: hidden;
+
+ &__header {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.5rem 0.75rem;
+ border-bottom: 1px solid var(--content-border-color);
+ }
+
+ &__channel {
+ min-width: 0;
+ padding: 0;
+ background: none;
+ border-radius: 0;
+ font-weight: bold;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ &__thread {
+ display: flex;
+ align-items: center;
+ gap: 0.35rem;
+ min-width: 0;
+
+ // gives way before the channel name does
+ flex: 0 100 auto;
+ color: var(--primary-high);
+
+ &::before {
+ content: "›" / "";
+ color: var(--primary-medium);
+ }
+
+ // the glyph fills more of its box than the channel icon, so it runs smaller
+ .d-icon {
+ flex-shrink: 0;
+ width: 0.75em;
+ height: 0.75em;
+ color: var(--primary-medium);
+ }
+
+ .chat-transcript-thread-header__title {
+ @include ellipsis;
+ }
+
+ a {
+ color: inherit;
+ }
+ }
+
+ &__label {
+ flex-shrink: 0;
+ margin-left: auto;
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
+ &__body {
+ max-height: 30rem;
+ overflow-y: auto;
+
+ // inset, as the group clips anything outside it
+ &:focus-visible {
+ outline: 2px solid var(--tertiary);
+ outline-offset: -2px;
+ }
+ }
+
+ .chat-transcript {
+ margin: 0;
+ padding: 0.5rem 0.75rem;
+ min-height: 0;
+ background: none;
+ border: none;
+ }
+
+ .chat-transcript-user-avatar a {
+ display: block;
+ }
+
+ .chat-transcript-username a {
+ color: inherit;
+ }
+
+ .chat-transcript .chat-transcript {
+ width: auto;
+ margin: 0 0.75rem 0
+ calc(0.75rem + var(--chat-transcript-avatar-size) / 2 - 1px);
+ padding: 0.375rem 0.5rem 0.375rem
+ calc(var(--chat-transcript-avatar-size) / 2 + 0.75rem - 1px);
+ border-left: 2px solid var(--content-border-color);
+ }
+
+ // a thread's replies are nested in it, so its hover moves to its own message
+ // to keep each message highlighting on its own
+ .chat-transcript:has(> .chat-transcript-thread) {
+ padding: 0 0 0.5rem;
+ }
+
+ .chat-transcript-thread {
+ padding: 0.5rem 0.75rem;
+ }
+
+ .no-touch & .chat-transcript:has(> .chat-transcript-thread):hover {
+ background: none;
+ }
+
+ .no-touch & .chat-transcript-thread:hover {
+ background: var(--d-hover);
+ }
+}
+
+.chat-transcript-group,
+.ProseMirror {
+ --chat-transcript-avatar-size: 24px;
+
+ .chat-transcript-user,
+ .chat-transcript-messages {
+ padding-left: calc(var(--chat-transcript-avatar-size) + 0.75rem);
+ }
+
+ .chat-transcript-user {
+ position: relative;
+ }
+
+ .chat-transcript-messages p:first-of-type {
+ margin-top: 0.1em;
+ }
+
+ .chat-transcript-user-avatar {
+ position: absolute;
+ top: 0;
+ left: 0;
+ padding-right: 0;
+ }
+
+ .chat-transcript-user-avatar .avatar,
+ .chat-transcript-user .chat-transcript-user-avatar:not(:has(img)) {
+ width: var(--chat-transcript-avatar-size);
+ height: var(--chat-transcript-avatar-size);
+ }
+
+ .chat-transcript-user .chat-transcript-user-avatar:not(:has(img)) {
+ padding: 0;
+ border-radius: 50%;
+ background: var(--primary-low);
+ }
+
+ .chat-transcript-thread-header {
+ display: flex;
+ align-items: center;
+ gap: 0.35rem;
+ margin-bottom: 0.5rem;
+ color: var(--primary-high);
+ font-size: var(--font-down-1);
+
+ .d-icon {
+ color: var(--primary-medium);
+ }
+
+ a {
+ color: inherit;
+ }
+ }
+}
+
.ProseMirror {
.chat-transcript {
white-space: normal;
}
+
+ > .chat-transcript {
+ margin: 1rem 0;
+ padding: 0.5rem 0.75rem;
+ min-height: 0;
+ background: none;
+ border: 1px solid var(--content-border-color);
+ border-radius: var(--d-border-radius-large);
+
+ > .chat-transcript-group__header {
+ margin: -0.5rem -0.75rem 0.5rem;
+ }
+ }
+
+ > .chat-transcript
+ + .chat-transcript:not([data-channel-name], [data-source]) {
+ margin-top: 0;
+ border-top: none;
+ border-top-left-radius: 0;
+ border-top-right-radius: 0;
+ }
+
+ > .chat-transcript:has(
+ + .chat-transcript:not([data-channel-name], [data-source])
+ ) {
+ margin-bottom: 0;
+ border-bottom: none;
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+ }
+
+ .chat-transcript .chat-transcript {
+ margin: 0 0 0 calc(var(--chat-transcript-avatar-size) / 2 - 1px);
+ padding: 0.375rem 0 0.375rem
+ calc(var(--chat-transcript-avatar-size) / 2 + 0.75rem - 1px);
+ min-height: 0;
+ background: none;
+ border-left: 2px solid var(--content-border-color);
+ }
+
+ .no-touch & .chat-transcript:hover {
+ background: none;
+ }
}
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index 01c0e4bfa50..28718c6811c 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -578,6 +578,8 @@ en:
original_channel: 'Originally sent in <a href="%{channelLink}">%{channel}</a>'
copy_success: "Chat quote copied to clipboard"
default_thread_title: "Thread"
+ transcript_label: "Transcript"
+ transcript_region: "Transcript from %{channel}"
notification_levels:
never: "Never"
diff --git a/plugins/chat/lib/chat/transcript_service.rb b/plugins/chat/lib/chat/transcript_service.rb
index be08f6dd8bf..0edf7c00714 100644
--- a/plugins/chat/lib/chat/transcript_service.rb
+++ b/plugins/chat/lib/chat/transcript_service.rb
@@ -25,6 +25,7 @@ module Chat
class TranscriptBBCode
attr_reader :channel,
+ :channel_id,
:multiquote,
:chained,
:no_link,
@@ -34,6 +35,7 @@ module Chat
def initialize(
channel: nil,
+ channel_id: nil,
acting_user: nil,
multiquote: false,
chained: false,
@@ -43,6 +45,7 @@ module Chat
thread_ranges: {}
)
@channel = channel
+ @channel_id = channel&.id || channel_id
@acting_user = acting_user
@multiquote = multiquote
@chained = chained
@@ -65,10 +68,8 @@ module Chat
def render
attrs = [quote_attr(@message_data.first[:message])]
- if channel
- attrs << channel_attr
- attrs << channel_id_attr
- end
+ attrs << channel_attr if channel
+ attrs << channel_id_attr if channel_id
attrs << MULTIQUOTE_ATTR if multiquote
attrs << CHAINED_ATTR if chained
@@ -135,7 +136,7 @@ module Chat
end
def channel_id_attr
- "channelId=\"#{channel.id}\""
+ "channelId=\"#{channel_id}\""
end
def thread_id_attr
@@ -212,8 +213,11 @@ module Chat
rendered_markdown << open_bbcode_tag.render
thread_id = threading_enabled ? message.thread_id : nil
+ # carries the channel id but not the name, so it renders as a
+ # continuation of the transcript with a linked timestamp
open_bbcode_tag =
TranscriptBBCode.new(
+ channel_id: @channel.id,
acting_user: @acting_user,
chained: !all_messages_same_user,
no_link: @opts[:no_link],
diff --git a/plugins/chat/spec/lib/chat/transcript_service_spec.rb b/plugins/chat/spec/lib/chat/transcript_service_spec.rb
index 1eed028c686..c34f31ee519 100644
--- a/plugins/chat/spec/lib/chat/transcript_service_spec.rb
+++ b/plugins/chat/spec/lib/chat/transcript_service_spec.rb
@@ -106,11 +106,11 @@ describe Chat::TranscriptService do
an extremely insightful response :)
[/chat]
- [chat quote="brucechat;#{message2.id};#{message2.created_at.iso8601}" chained="true"]
+ [chat quote="brucechat;#{message2.id};#{message2.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
says you!
[/chat]
- [chat quote="martinchat;#{message3.id};#{message3.created_at.iso8601}" chained="true"]
+ [chat quote="martinchat;#{message3.id};#{message3.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
aw :(
[/chat]
MARKDOWN
@@ -173,11 +173,11 @@ describe Chat::TranscriptService do
an extremely insightful response :)
[/chat]
- [chat quote="brucechat;#{message2.id};#{message2.created_at.iso8601}" chained="true"]
+ [chat quote="brucechat;#{message2.id};#{message2.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
says you!
[/chat]
- [chat quote="martinchat;#{message3.id};#{message3.created_at.iso8601}" chained="true"]
+ [chat quote="martinchat;#{message3.id};#{message3.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
aw :(
[/chat]
MARKDOWN
@@ -280,7 +280,7 @@ describe Chat::TranscriptService do
wow so tru
[/chat]
- [chat quote="brucechat;#{message3.id};#{message3.created_at.iso8601}" chained="true" reactions="sob:ivar"]
+ [chat quote="brucechat;#{message3.id};#{message3.created_at.iso8601}" channelId="#{channel.id}" chained="true" reactions="sob:ivar"]
a new perspective
[/chat]
MARKDOWN
@@ -486,7 +486,7 @@ describe Chat::TranscriptService do
#{regular_message.message}
[/chat]
- [chat quote="martinchat;#{thread.original_message.id};#{thread.original_message.created_at.iso8601}" threadId="#{thread.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]
+ [chat quote="martinchat;#{thread.original_message.id};#{thread.original_message.created_at.iso8601}" channelId="#{channel.id}" threadId="#{thread.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]
#{thread.original_message.message}
[chat quote="martinchat;#{reply.id};#{reply.created_at.iso8601}"]
@@ -542,7 +542,7 @@ describe Chat::TranscriptService do
[/chat]
- [chat quote="martinchat;#{empty_thread.original_message.id};#{empty_thread.original_message.created_at.iso8601}" chained="true"]
+ [chat quote="martinchat;#{empty_thread.original_message.id};#{empty_thread.original_message.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
no replies
[/chat]
MARKDOWN
@@ -610,7 +610,7 @@ describe Chat::TranscriptService do
I need ideas
[/chat]
- [chat quote="brucechat;#{thread_1_om.id};#{thread_1_om.created_at.iso8601}" chained="true" threadId="#{thread_1.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]
+ [chat quote="brucechat;#{thread_1_om.id};#{thread_1_om.created_at.iso8601}" channelId="#{channel.id}" chained="true" threadId="#{thread_1.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]
this is my idea
[chat quote="martinchat;#{thread_1_message.id};#{thread_1_message.created_at.iso8601}" chained="true"]
@@ -619,11 +619,11 @@ describe Chat::TranscriptService do
[/chat]
- [chat quote="brucechat;#{channel_message_2.id};#{channel_message_2.created_at.iso8601}" chained="true"]
+ [chat quote="brucechat;#{channel_message_2.id};#{channel_message_2.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
more?
[/chat]
- [chat quote="brucechat;#{thread_2_om.id};#{thread_2_om.created_at.iso8601}" chained="true" threadId="#{thread_2.id}" threadTitle="the second idea"]
+ [chat quote="brucechat;#{thread_2_om.id};#{thread_2_om.created_at.iso8601}" channelId="#{channel.id}" chained="true" threadId="#{thread_2.id}" threadTitle="the second idea"]
another one
[chat quote="martinchat;#{thread_2_message_1.id};#{thread_2_message_1.created_at.iso8601}" chained="true"]
diff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rb
index 4cd063cb409..52743af8e07 100644
--- a/plugins/chat/spec/models/chat/message_spec.rb
+++ b/plugins/chat/spec/models/chat/message_spec.rb
@@ -541,14 +541,14 @@ describe Chat::Message do
<div class="chat-transcript-messages">
<p>this is the first message</p></div>
</div>
- <div class="chat-transcript chat-transcript-chained" data-message-id="#{msg2.id}" data-username="otherbbcodeuser" data-datetime="#{msg2.created_at.iso8601}" data-chained="true">
+ <div class="chat-transcript chat-transcript-chained" data-message-id="#{msg2.id}" data-username="otherbbcodeuser" data-datetime="#{msg2.created_at.iso8601}" data-chained="true" data-channel-id="#{chat_channel.id}">
<div class="chat-transcript-user">
<div class="chat-transcript-user-avatar">
<img alt="" width="24" height="24" src="#{avatar_src2}" class="avatar"></div>
<div class="chat-transcript-username">
otherbbcodeuser</div>
<div class="chat-transcript-datetime">
- <span title="#{msg2.created_at.iso8601}"></span></div>
+ <a href="/chat/c/-/#{chat_channel.id}/#{msg2.id}" title="#{msg2.created_at.iso8601}"></a></div>
</div>
<div class="chat-transcript-messages">
<p>and another cool one</p></div>
diff --git a/plugins/chat/spec/requests/chat_controller_spec.rb b/plugins/chat/spec/requests/chat_controller_spec.rb
index b15ce824460..12c35bf1add 100644
--- a/plugins/chat/spec/requests/chat_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat_controller_spec.rb
@@ -479,11 +479,11 @@ RSpec.describe Chat::ChatController do
an extremely insightful response :)
[/chat]
- [chat quote="#{user2.username};#{message2.id};#{message2.created_at.iso8601}" chained="true"]
+ [chat quote="#{user2.username};#{message2.id};#{message2.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
says you!
[/chat]
- [chat quote="#{user.username};#{message3.id};#{message3.created_at.iso8601}" chained="true"]
+ [chat quote="#{user.username};#{message3.id};#{message3.created_at.iso8601}" channelId="#{channel.id}" chained="true"]
aw :(
[/chat]
EXPECTED
diff --git a/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb b/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb
index 0db69c74471..f3abdc5f0ae 100644
--- a/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb
+++ b/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb
@@ -103,10 +103,7 @@ describe "chat transcripts in rich editor" do
)
expect(rich).to have_css(".chat-transcript.chat-transcript-chained", count: 2)
- expect(rich).to have_css(
- ".chat-transcript .chat-transcript-meta",
- text: "Originally sent in #{channel.name}",
- )
+ expect(rich).to have_css(".chat-transcript .chat-transcript-group__channel", text: channel.name)
expect(rich).to have_css(
".chat-transcript:nth-of-type(1) .chat-transcript-user .chat-transcript-username",
text: message_1.user.username,
@@ -200,17 +197,20 @@ describe "chat transcripts in rich editor" do
cdp.copy_paste(markdown, css_selector: composer.composer_input_selector)
- expect(rich).to have_css(".chat-transcript-meta a")
+ expect(rich).to have_css(".chat-transcript-group__channel")
attributes = page.evaluate_script(<<~JS)
Object.fromEntries(
Array.from(
- document.querySelector(".d-editor-input.ProseMirror .chat-transcript-meta a").attributes
+ document.querySelector(".d-editor-input.ProseMirror .chat-transcript-group__channel").attributes
).map((attribute) => [attribute.name, attribute.value])
)
JS
- expect(attributes).to eq({ "href" => "/chat/c/-/#{channel_id}" })
+ expect(attributes).to eq(
+ "class" => "hashtag-cooked chat-transcript-group__channel",
+ "href" => "/chat/c/-/%22%20onmouseover%3D%22alert(1)%22%20x%3D%22",
+ )
end
end
end
diff --git a/plugins/chat/spec/system/transcript_spec.rb b/plugins/chat/spec/system/transcript_spec.rb
index 92de99017cc..8014876fe60 100644
--- a/plugins/chat/spec/system/transcript_spec.rb
+++ b/plugins/chat/spec/system/transcript_spec.rb
@@ -73,7 +73,10 @@ RSpec.describe "Quoting chat message transcripts" do
topic_page.fill_in_composer("This is a new post!\n\n" + clip_text)
expect(page).to have_css(".d-editor-preview .chat-transcript", count: 2)
- expect(page).to have_content("Originally sent in #{chat_channel_1.name}")
+ expect(page).to have_css(
+ ".d-editor-preview .chat-transcript-group__channel",
+ text: chat_channel_1.name,
+ )
topic_page.send_reply
@@ -123,6 +126,79 @@ RSpec.describe "Quoting chat message transcripts" do
end
end
+ context "when viewing a transcript from several users in a post" do
+ fab!(:other_user, :user)
+ fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1, user: current_user) }
+ fab!(:message_2) { Fabricate(:chat_message, chat_channel: chat_channel_1, user: other_user) }
+
+ let(:user_card) { PageObjects::Components::UserCard.new }
+ let!(:post_1) do
+ Fabricate(:post, raw: generate_transcript([message_1, message_2], current_user))
+ end
+
+ it "groups the messages in one box under the channel" do
+ topic_page.visit_topic(post_1.topic)
+
+ within(topic_page.post_by_number_selector(1)) do
+ expect(page).to have_css(".chat-transcript-group", count: 1)
+ expect(page).to have_css(".chat-transcript-group__channel", text: chat_channel_1.name)
+ expect(page).to have_css(".chat-transcript-group__body .chat-transcript", count: 2)
+ end
+ end
+
+ it "links each timestamp to its message" do
+ topic_page.visit_topic(post_1.topic)
+
+ within(topic_page.post_by_number_selector(1)) do
+ [message_1, message_2].each do |message|
+ expect(page).to have_css(
+ ".chat-transcript-datetime a[href$='/chat/c/-/#{chat_channel_1.id}/#{message.id}']",
+ )
+ end
+ end
+ end
+
+ it "opens the user card from the username" do
+ topic_page.visit_topic(post_1.topic)
+
+ find(".chat-transcript[data-message-id='#{message_2.id}'] .chat-transcript-username a").click
+
+ expect(user_card).to be_showing_user(other_user.username)
+ expect(page).to have_current_path(%r{/t/[^/]+/#{post_1.topic.id}})
+ end
+ end
+
+ context "when viewing a transcript of a thread in a post" do
+ fab!(:thread) do
+ Fabricate(:chat_thread, channel: chat_channel_1, title: "Ideas", with_replies: 2)
+ end
+
+ before { chat_channel_1.update!(threading_enabled: true) }
+
+ let!(:post_1) do
+ Fabricate(:post, raw: generate_transcript(thread.original_message, current_user))
+ end
+
+ it "shows the thread expanded, titled in the header" do
+ topic_page.visit_topic(post_1.topic)
+
+ within(topic_page.post_by_number_selector(1)) do
+ expect(page).to have_no_css(".chat-transcript details")
+ expect(page).to have_css(
+ ".chat-transcript-group__thread a[href$='/chat/c/-/#{chat_channel_1.id}/t/#{thread.id}']",
+ text: "Ideas",
+ )
+ expect(page).to have_no_css(".chat-transcript-group__body .chat-transcript-thread-header")
+
+ thread.replies.each do |reply|
+ expect(page).to have_css(
+ ".chat-transcript-datetime a[href$='/chat/c/-/#{chat_channel_1.id}/t/#{thread.id}/#{reply.id}']",
+ )
+ end
+ end
+ end
+ end
+
context "when quoting into a topic directly" do
fab!(:message_1) { Fabricate(:chat_message, chat_channel: chat_channel_1) }
let(:topic_title) { "Some topic title for testing" }
diff --git a/plugins/chat/test/javascripts/components/rich-editor-extension-test.gjs b/plugins/chat/test/javascripts/components/rich-editor-extension-test.gjs
index 9f841d3e31a..4c5c47c9965 100644
--- a/plugins/chat/test/javascripts/components/rich-editor-extension-test.gjs
+++ b/plugins/chat/test/javascripts/components/rich-editor-extension-test.gjs
@@ -54,12 +54,10 @@ haha **ok** _cool_
.dom(".chat-transcript-user .chat-transcript-datetime", rootElement)
.exists();
assert
- .dom(".chat-transcript-channel", rootElement)
- .hasText("#design gems");
- assert
- .dom(".chat-transcript-channel", rootElement)
+ .dom(".chat-transcript-group__channel", rootElement)
+ .hasText("design gems")
.hasAttribute("href", "/chat/c/-/95");
- assert.dom(".chat-transcript-channel img[title='tada']").exists();
+ assert.dom(".chat-transcript-group__channel img[title='tada']").exists();
assert.strictEqual(value, singleMessageSingleUserMarkdown);
});
@@ -101,10 +99,11 @@ haha **ok** _cool_
assert
.dom(".chat-transcript:nth-of-type(1)")
.hasClass("chat-transcript-chained");
+ assert.dom(".chat-transcript-group__header").exists({ count: 1 });
assert
- .dom(".chat-transcript-meta")
- .hasText("Originally sent in design gems");
- assert.dom(".chat-transcript-meta img[title='tada']").exists();
+ .dom(".chat-transcript:nth-of-type(1) .chat-transcript-group__channel")
+ .hasText("design gems");
+ assert.dom(".chat-transcript-group__channel img[title='tada']").exists();
let rootElement = document.querySelector(
".ProseMirror .chat-transcript:nth-of-type(1)"
@@ -129,6 +128,23 @@ haha **ok** _cool_
assert.strictEqual(value, multiMessagesMultiUserMarkdown);
});
+ test("transcript named by an unlinked source", async function (assert) {
+ const sourceMarkdown = `[chat quote="martin;1;2025-03-20T07:12:55Z" source="Weekly sync" sourceType=meeting chained=true]
+test
+[/chat]
+[chat quote="hunter;2;2025-03-20T07:13:04Z" chained=true]
+haha
+[/chat]
+`;
+ const [{ value }] = await setupRichEditor(assert, sourceMarkdown);
+
+ assert.dom(".chat-transcript-group__header").exists({ count: 1 });
+ assert.dom("span.chat-transcript-group__channel").hasText("Weekly sync");
+ assert.dom(".chat-transcript-group__label").hasText("Transcript");
+
+ assert.strictEqual(value, sourceMarkdown);
+ });
+
test("messages in a thread", async function (assert) {
const threadMessagesMarkdown = `[chat quote="martin;29854;2025-03-20T07:12:57Z" channel="design gems :tada:" channelId=95 multiQuote=true threadId=124 threadTitle="Some cool thread title"]
thread op message
@@ -140,16 +156,14 @@ thread other message
[/chat]
`;
const [{ value }] = await setupRichEditor(assert, threadMessagesMarkdown);
+ assert.dom(".chat-transcript-group__channel").hasText("design gems");
+ assert.dom(".chat-transcript-group__channel img[title='tada']").exists();
assert
- .dom(".chat-transcript-meta")
- .hasText("Originally sent in design gems");
- assert.dom(".chat-transcript-meta img[title='tada']").exists();
- assert
- .dom(".chat-transcript details summary .chat-transcript-thread")
- .exists();
+ .dom(".chat-transcript details")
+ .doesNotExist("the thread is shown expanded");
let rootElement = document.querySelector(
- ".ProseMirror .chat-transcript details summary .chat-transcript-thread"
+ ".ProseMirror .chat-transcript > .chat-transcript-thread"
);
assert
.dom(
@@ -168,20 +182,20 @@ thread other message
.dom(".chat-transcript-messages", rootElement)
.hasHtml(
"<p>thread op message</p>",
- "the thread op message is inside the summary element"
+ "the thread op message is inside the thread element"
);
assert
.dom(".chat-transcript-user .chat-transcript-username", rootElement)
.hasText("martin");
rootElement = document.querySelector(
- ".ProseMirror .chat-transcript details .chat-transcript"
+ ".ProseMirror .chat-transcript > .chat-transcript"
);
assert
.dom(".chat-transcript-messages", rootElement)
.hasHtml(
"<p>thread other message</p>",
- "the other thread messages are inside the details element"
+ "the other thread messages are nested in the thread's transcript"
);
assert
.dom(".chat-transcript-user .chat-transcript-username", rootElement)
diff --git a/plugins/chat/test/javascripts/unit/lib/group-chat-transcripts-test.js b/plugins/chat/test/javascripts/unit/lib/group-chat-transcripts-test.js
new file mode 100644
index 00000000000..7740c5abc8e
--- /dev/null
+++ b/plugins/chat/test/javascripts/unit/lib/group-chat-transcripts-test.js
@@ -0,0 +1,312 @@
+import { settled } from "@ember/test-helpers";
+import { setupTest } from "ember-qunit";
+import { module, test } from "qunit";
+import { registerHashtagType } from "discourse/lib/hashtag-type-registry";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
+import groupChatTranscripts from "discourse/plugins/chat/discourse/lib/group-chat-transcripts";
+import ChannelHashtagType from "discourse/plugins/chat/discourse/lib/hashtag-types/channel";
+import {
+ registerTranscriptSourceType,
+ resetTranscriptSourceTypes,
+} from "discourse/plugins/chat/discourse/lib/transcript-source-types";
+
+const site = { hashtag_icons: { channel: "comment" } };
+
+function render(html) {
+ const element = document.createElement("div");
+ element.innerHTML = html;
+ groupChatTranscripts(element, { site });
+ return element;
+}
+
+module("Unit | lib | group-chat-transcripts", function (hooks) {
+ setupTest(hooks);
+
+ hooks.afterEach(function () {
+ resetTranscriptSourceTypes();
+ });
+
+ test("groups a multi-author transcript under one channel header", function (assert) {
+ const element = render(`
+ <div class="chat-transcript chat-transcript-chained" data-channel-name="general" data-channel-id="7" data-multiquote="true">
+ <div class="chat-transcript-meta">Originally sent in <a href="/chat/c/-/7">general</a></div>
+ </div>
+ <div class="chat-transcript chat-transcript-chained"></div>
+ <div class="chat-transcript chat-transcript-chained"></div>
+ `);
+
+ const groups = element.querySelectorAll(".chat-transcript-group");
+ assert.strictEqual(groups.length, 1);
+ assert
+ .dom(".chat-transcript-group__body > .chat-transcript", groups[0])
+ .exists({ count: 3 });
+ assert
+ .dom(".chat-transcript-group__channel", groups[0])
+ .hasText("general")
+ .hasAttribute("href", "/chat/c/-/7");
+ assert.dom(".chat-transcript-meta", groups[0]).doesNotExist();
+ assert
+ .dom(".chat-transcript-group__body", groups[0])
+ .hasAttribute("role", "region")
+ .hasAttribute("tabindex", "0")
+ .hasAria("label", "Transcript from general");
+ });
+
+ test("moves a single quote's channel link into the header", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7">
+ <div class="chat-transcript-user"><a class="chat-transcript-channel" href="/chat/c/-/7">#general</a></div>
+ </div>
+ `);
+
+ assert.dom(".chat-transcript-group__channel", element).hasText("general");
+ assert.dom(".chat-transcript-channel", element).doesNotExist();
+ });
+
+ test("groups a single author's messages split around a thread", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7" data-multiquote="true" data-thread-id="3"></div>
+ <div class="chat-transcript" data-channel-id="7"></div>
+ `);
+
+ assert.dom(".chat-transcript-group", element).exists({ count: 1 });
+ assert
+ .dom(".chat-transcript-group__body > .chat-transcript", element)
+ .exists({ count: 2 });
+ });
+
+ test("moves a sole thread's title into the header", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7" data-thread-id="3">
+ <details>
+ <summary>
+ <div class="chat-transcript-thread">
+ <div class="chat-transcript-thread-header"><span class="chat-transcript-thread-header__title">Ideas</span></div>
+ </div>
+ </summary>
+ <div class="chat-transcript chat-transcript-chained"></div>
+ </details>
+ </div>
+ `);
+
+ assert
+ .dom(
+ ".chat-transcript-group__channel + .chat-transcript-group__thread",
+ element
+ )
+ .hasText("Ideas");
+ assert.dom(".chat-transcript-thread-header", element).doesNotExist();
+ });
+
+ test("links thread titles to the thread", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7" data-thread-id="3">
+ <details>
+ <summary>
+ <div class="chat-transcript-thread">
+ <div class="chat-transcript-thread-header"><span class="chat-transcript-thread-header__title">Ideas</span></div>
+ <div class="chat-transcript-datetime"><a href="/chat/c/-/7/1" title="t1">first</a></div>
+ </div>
+ </summary>
+ </details>
+ </div>
+ `);
+
+ assert
+ .dom(".chat-transcript-thread-header__title > a", element)
+ .hasText("Ideas")
+ .hasAttribute("href", "/chat/c/-/7/t/3");
+ });
+
+ test("keeps a thread's title inline when the transcript has more", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7" data-thread-id="3">
+ <details>
+ <summary>
+ <div class="chat-transcript-thread">
+ <div class="chat-transcript-thread-header"><span class="chat-transcript-thread-header__title">Ideas</span></div>
+ </div>
+ </summary>
+ </details>
+ </div>
+ <div class="chat-transcript" data-channel-id="7"></div>
+ `);
+
+ assert.dom(".chat-transcript-group__thread", element).doesNotExist();
+ assert.dom(".chat-transcript-thread-header", element).hasText("Ideas");
+ });
+
+ test("heads a transcript with an unlinked source", function (assert) {
+ registerTranscriptSourceType("meeting", {
+ icon: "users",
+ label: "chat.quote.default_thread_title",
+ });
+
+ const element = render(`
+ <div class="chat-transcript chat-transcript-chained" data-message-id="1" data-source="Weekly sync" data-source-type="meeting">
+ <div class="chat-transcript-datetime"><span title="t1">first</span></div>
+ </div>
+ <div class="chat-transcript chat-transcript-chained" data-message-id="2"></div>
+ `);
+
+ assert.dom(".chat-transcript-group", element).exists({ count: 1 });
+ assert
+ .dom(".chat-transcript-group__body > .chat-transcript", element)
+ .exists({ count: 2 });
+ assert
+ .dom("span.chat-transcript-group__channel", element)
+ .hasText("Weekly sync");
+ assert
+ .dom(".chat-transcript-group__channel .d-icon-users", element)
+ .exists();
+ assert.dom(".chat-transcript-group__label", element).hasText("Thread");
+ assert.dom(".chat-transcript-datetime a", element).doesNotExist();
+ assert
+ .dom(".chat-transcript-group__body", element)
+ .hasAria("label", "Transcript from Weekly sync");
+ });
+
+ test("presents an unregistered source type generically", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-source="Weekly sync" data-source-type="nope"></div>
+ `);
+
+ assert
+ .dom(".chat-transcript-group__channel .d-icon-comment", element)
+ .exists();
+ assert.dom(".chat-transcript-group__label", element).hasText("Transcript");
+ });
+
+ test("starts a new group at a block naming a source", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7"></div>
+ <div class="chat-transcript" data-source="Weekly sync"></div>
+ `);
+
+ assert.dom(".chat-transcript-group", element).exists({ count: 2 });
+ });
+
+ test("keeps adjacent separate quotes in separate groups", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7"></div>
+ <div class="chat-transcript" data-channel-name="random" data-channel-id="8"></div>
+ `);
+
+ assert.dom(".chat-transcript-group", element).exists({ count: 2 });
+ });
+
+ test("expands threads, keeping replies inside their transcript", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7" data-thread-id="1">
+ <details>
+ <summary><div class="chat-transcript-thread"></div></summary>
+ <div class="chat-transcript chat-transcript-chained"></div>
+ </details>
+ </div>
+ `);
+
+ assert
+ .dom(".chat-transcript-group__body > .chat-transcript", element)
+ .exists({ count: 1 });
+ assert.dom("details, summary", element).doesNotExist();
+ assert
+ .dom(
+ "[data-thread-id] > .chat-transcript-thread + .chat-transcript",
+ element
+ )
+ .exists();
+ });
+
+ test("links every timestamp in the transcript to its message", function (assert) {
+ const element = render(`
+ <div class="chat-transcript chat-transcript-chained" data-message-id="1" data-channel-name="general" data-channel-id="7" data-thread-id="9">
+ <details>
+ <summary>
+ <div class="chat-transcript-datetime"><a href="/chat/c/-/7/1" title="t1">first</a></div>
+ </summary>
+ <div class="chat-transcript chat-transcript-chained" data-message-id="2">
+ <div class="chat-transcript-datetime"><span title="t2">reply</span></div>
+ </div>
+ </details>
+ </div>
+ <div class="chat-transcript chat-transcript-chained" data-message-id="3">
+ <div class="chat-transcript-datetime"><span title="t3">third</span></div>
+ </div>
+ `);
+
+ assert
+ .dom("[data-message-id='1'] .chat-transcript-datetime > a", element)
+ .hasAttribute("href", "/chat/c/-/7/1");
+ assert
+ .dom("[data-message-id='2'] .chat-transcript-datetime > a", element)
+ .hasAttribute("href", "/chat/c/-/7/t/9/2")
+ .hasAttribute("title", "t2")
+ .hasText("reply");
+ assert
+ .dom("[data-message-id='3'] .chat-transcript-datetime > a", element)
+ .hasAttribute("href", "/chat/c/-/7/3");
+ });
+
+ test("leaves archive timestamps unlinked", function (assert) {
+ const element = render(`
+ <div class="chat-transcript chat-transcript-chained" data-message-id="1" data-channel-name="general" data-channel-id="7">
+ <div class="chat-transcript-datetime"><span title="t1">first</span></div>
+ </div>
+ <div class="chat-transcript chat-transcript-chained" data-message-id="2">
+ <div class="chat-transcript-datetime"><span title="t2">second</span></div>
+ </div>
+ `);
+
+ assert.dom(".chat-transcript-datetime a", element).doesNotExist();
+ });
+
+ test("links the avatar and username to the user card", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-username="Bruce" data-channel-name="general" data-channel-id="7">
+ <div class="chat-transcript-user">
+ <div class="chat-transcript-user-avatar"><img class="avatar"></div>
+ <div class="chat-transcript-username">Bruce</div>
+ </div>
+ </div>
+ `);
+
+ assert
+ .dom(".chat-transcript-username > a", element)
+ .hasText("Bruce")
+ .hasAttribute("href", "/u/bruce")
+ .hasAttribute("data-user-card", "Bruce");
+ assert
+ .dom(".chat-transcript-user-avatar > a", element)
+ .hasAttribute("data-user-card", "Bruce")
+ .hasAttribute("tabindex", "-1");
+ assert.dom(".chat-transcript-user-avatar > a > img", element).exists();
+ });
+
+ test("shows the emoji of a channel the user hasn't loaded", async function (assert) {
+ const channelType = new ChannelHashtagType(this.owner);
+ // skips the color lookup, which this test doesn't cover
+ channelType.loadedIds.add(42);
+ registerHashtagType("channel", channelType);
+ pretender.get("/hashtags/by-ids", () =>
+ response({ channel: [{ id: 42, emoji: "tada" }] })
+ );
+
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="42"></div>
+ `);
+ await settled();
+
+ assert
+ .dom(".chat-transcript-group__channel > img.emoji", element)
+ .hasAttribute("title", "tada");
+ });
+
+ test("is idempotent", function (assert) {
+ const element = render(`
+ <div class="chat-transcript" data-channel-name="general" data-channel-id="7"></div>
+ `);
+ groupChatTranscripts(element, { site });
+
+ assert.dom(".chat-transcript-group", element).exists({ count: 1 });
+ });
+});
diff --git a/plugins/voice/assets/javascripts/discourse/initializers/voice-transcript-source.js b/plugins/voice/assets/javascripts/discourse/initializers/voice-transcript-source.js
new file mode 100644
index 00000000000..4ddc483a195
--- /dev/null
+++ b/plugins/voice/assets/javascripts/discourse/initializers/voice-transcript-source.js
@@ -0,0 +1,16 @@
+import { withPluginApi } from "discourse/lib/plugin-api";
+import { TRANSCRIPT_SOURCE_TYPE } from "../lib/voice/transcript-markdown";
+
+export default {
+ name: "voice-transcript-source",
+
+ initialize() {
+ withPluginApi((api) => {
+ // absent when the chat plugin isn't installed
+ api.registerChatTranscriptSourceType?.(TRANSCRIPT_SOURCE_TYPE, {
+ icon: "microphone-lines",
+ label: "voice.transcript.source_label",
+ });
+ });
+ },
+};
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/transcript-markdown.js b/plugins/voice/assets/javascripts/discourse/lib/voice/transcript-markdown.js
index f585dae3e47..d292f644359 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/transcript-markdown.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/transcript-markdown.js
@@ -1,19 +1,31 @@
+import { serializeBBCodeAttr } from "discourse/lib/text";
import { i18n } from "discourse-i18n";
+// chat presents this type as registered by the voice-transcript-source initializer
+export const TRANSCRIPT_SOURCE_TYPE = "voice";
+
// Renders a recorded transcript as post markdown. When chat is enabled the
// entries reuse chat's transcript markup — one chained [chat] block per
// utterance, which cooks into the familiar quoted-conversation look — with
// the utterance id standing in for the message id and no channel attributes,
-// so nothing links anywhere. Without chat the markup wouldn't cook, so plain
-// bbcode quotes are used instead.
-export function transcriptToMarkdown(entries, { chatMarkup = true } = {}) {
+// so nothing links anywhere. The first entry names the room as the
+// transcript's source, which heads it in place of a channel. Without chat the
+// markup wouldn't cook, so plain bbcode quotes are used instead.
+export function transcriptToMarkdown(
+ entries,
+ { chatMarkup = true, roomName } = {}
+) {
return entries
- .map((entry) => {
+ .map((entry, index) => {
const username =
entry.username || i18n("voice.transcript.unknown_speaker");
if (chatMarkup) {
const timestamp = new Date(entry.startedAt).toISOString();
- return `[chat quote="${username};${entry.utteranceId};${timestamp}" chained="true"]\n${entry.text}\n[/chat]`;
+ const source =
+ index === 0 && roomName
+ ? `${serializeBBCodeAttr(roomName, "source")}${serializeBBCodeAttr(TRANSCRIPT_SOURCE_TYPE, "sourceType")}`
+ : "";
+ return `[chat quote="${username};${entry.utteranceId};${timestamp}"${source} chained="true"]\n${entry.text}\n[/chat]`;
}
return `[quote="${username}"]\n${entry.text}\n[/quote]`;
})
diff --git a/plugins/voice/assets/javascripts/discourse/lib/voice/transcription-coordinator.js b/plugins/voice/assets/javascripts/discourse/lib/voice/transcription-coordinator.js
index d97cac9e152..7e10712dee3 100644
--- a/plugins/voice/assets/javascripts/discourse/lib/voice/transcription-coordinator.js
+++ b/plugins/voice/assets/javascripts/discourse/lib/voice/transcription-coordinator.js
@@ -351,6 +351,7 @@ export default class TranscriptionCoordinator {
return {
reply: transcriptToMarkdown(entries, {
chatMarkup: !!this.#siteSettings.chat_enabled,
+ roomName: room?.name,
}),
title: i18n("voice.transcript.draft_title", {
room: room?.name ?? "",
diff --git a/plugins/voice/config/locales/client.en.yml b/plugins/voice/config/locales/client.en.yml
index c901afd6b18..86262038c5b 100644
--- a/plugins/voice/config/locales/client.en.yml
+++ b/plugins/voice/config/locales/client.en.yml
@@ -198,6 +198,7 @@ en:
draft_topic: "Open transcript draft"
stop_and_open: "Stop recording and open draft"
draft_title: "Call transcript: %{room}"
+ source_label: "Call transcript"
unknown_speaker: "unknown speaker"
stage:
promoted_to_speaker: "You've been made a speaker."
diff --git a/plugins/voice/test/javascripts/unit/lib/transcript-markdown-test.js b/plugins/voice/test/javascripts/unit/lib/transcript-markdown-test.js
index 5a251cd43f5..5b9b3bc5814 100644
--- a/plugins/voice/test/javascripts/unit/lib/transcript-markdown-test.js
+++ b/plugins/voice/test/javascripts/unit/lib/transcript-markdown-test.js
@@ -34,6 +34,26 @@ module("Voice | Unit | Lib | transcript-markdown", function (hooks) {
);
});
+ test("names the room as the source on the first entry only", function (assert) {
+ const markdown = transcriptToMarkdown(entries, { roomName: "Weekly sync" });
+
+ assert.strictEqual(
+ markdown,
+ [
+ '[chat quote="alice;7;2026-08-20T16:38:24.000Z" source="Weekly sync" sourceType=voice chained="true"]\nhello world\n[/chat]',
+ '[chat quote="bob;8;2026-08-20T16:38:46.000Z" chained="true"]\nhi there\n[/chat]',
+ ].join("\n\n")
+ );
+ });
+
+ test("keeps a room name with quotes in one attribute", function (assert) {
+ const markdown = transcriptToMarkdown(entries, {
+ roomName: 'The "big" room',
+ });
+
+ assert.true(markdown.includes(` source='The "big" room' `));
+ });
+
test("falls back to plain quotes without chat markup", function (assert) {
const markdown = transcriptToMarkdown(entries, { chatMarkup: false });