Files
David TaylorandGitHub 666b5dddde DEV: Move discourse-common/(utils|lib) to discourse/lib (#30733)
`discourse-common` was created in the past to share logic between the
'wizard' app and the main 'discourse' app. Since then, the wizard has
been consolidated into the main app, so the separation of
`discourse-common` is no longer useful.

This commit moves `discourse-common/(lib|utils)/*` into
`discourse/lib/*`, adds shims for the imports, and updates existing
uses in core.
2025-01-13 13:02:49 +00:00

36 lines
1.1 KiB
JavaScript

import { htmlSafe } from "@ember/template";
import getURL from "discourse/lib/get-url";
import User from "discourse/models/user";
import { i18n } from "discourse-i18n";
export default function formatChatDate(message, options = {}) {
const currentUser = User.current();
const tz = currentUser ? currentUser.user_option.timezone : moment.tz.guess();
const date = moment(new Date(message.createdAt), tz);
const title = date.format(i18n("dates.long_with_year"));
const display =
options.mode === "tiny"
? date.format(i18n("dates.time_short"))
: date.format(i18n("dates.time"));
if (message.staged) {
return htmlSafe(
`<span title='${title}' tabindex="-1" class='chat-time'>${display}</span>`
);
} else {
let url;
if (options.threadContext) {
url = getURL(
`/chat/c/-/${message.channel.id}/t/${message.thread.id}/${message.id}`
);
} else {
url = getURL(`/chat/c/-/${message.channel.id}/${message.id}`);
}
return htmlSafe(
`<a title='${title}' tabindex="-1" class='chat-time' href='${url}'>${display}</a>`
);
}
}