This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/helpers/format-chat-date.js
Roman Rizzi d07b472b79
DEV: /channel -> /c chat route rename (#19782)
* DEV: Rnemae channel path to just c

Also swap the channel id and channel slug params to be consistent with core.

* linting

* channel_path

* params in wrong order

* Drop slugify helper and channel route without slug

* Request slug and route models through the channel model if possible

* Add client side redirection for backwards-compatibility

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-01-27 09:58:12 -03:00

33 lines
898 B
JavaScript

import { registerUnbound } from "discourse-common/lib/helpers";
import { htmlSafe } from "@ember/template";
import getURL from "discourse-common/lib/get-url";
import I18n from "I18n";
import User from "discourse/models/user";
registerUnbound("format-chat-date", function (message, details, mode) {
let currentUser = User.current();
let tz = currentUser ? currentUser.user_option.timezone : moment.tz.guess();
let date = moment(new Date(message.created_at), tz);
let url = "";
if (details) {
url = getURL(
`/chat/c/-/${details.chat_channel_id}?messageId=${message.id}`
);
}
let title = date.format(I18n.t("dates.long_with_year"));
let display =
mode === "tiny"
? date.format(I18n.t("chat.dates.time_tiny"))
: date.format(I18n.t("dates.time"));
return htmlSafe(
`<a title='${title}' class='chat-time' href='${url}'>${display}</a>`
);
});