DEV: Modernize chat helper definitions (#24017)

These helpers are never used in raw-hbs. Exporting default functions is enough for them to be picked up by the ember resolver, and also makes it possible to use them in gjs files.
This commit is contained in:
David Taylor 2023-10-19 15:51:38 +01:00 committed by GitHub
parent b1c6e67e2c
commit 98cb14dd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 11 deletions

View File

@ -1,10 +1,9 @@
import { htmlSafe } from "@ember/template";
import User from "discourse/models/user";
import getURL from "discourse-common/lib/get-url";
import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "discourse-i18n";
registerUnbound("format-chat-date", function (message, mode) {
export default function formatChatDate(message, mode) {
const currentUser = User.current();
const tz = currentUser ? currentUser.user_option.timezone : moment.tz.guess();
const date = moment(new Date(message.createdAt), tz);
@ -25,4 +24,4 @@ registerUnbound("format-chat-date", function (message, mode) {
`<a title='${title}' tabindex="-1" class='chat-time' href='${url}'>${display}</a>`
);
}
});
}

View File

@ -1,9 +1,7 @@
import { registerUnbound } from "discourse-common/lib/helpers";
registerUnbound("tonable-emoji-title", function (emoji, diversity) {
export default function tonableEmojiTitle(emoji, diversity) {
if (!emoji.tonable || diversity === 1) {
return `:${emoji.name}:`;
}
return `:${emoji.name}:t${diversity}:`;
});
}

View File

@ -1,9 +1,7 @@
import { registerUnbound } from "discourse-common/lib/helpers";
registerUnbound("tonable-emoji-url", function (emoji, scale) {
export default function tonableEmojiUrl(emoji, scale) {
if (!emoji.tonable || scale === 1) {
return emoji.url;
}
return emoji.url.split(".png")[0] + `/${scale}.png`;
});
}