From 98cb14dd82f59e547cec3a15bfc0fdfa6807e24a Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 19 Oct 2023 15:51:38 +0100 Subject: [PATCH] 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. --- .../javascripts/discourse/helpers/format-chat-date.js | 5 ++--- .../javascripts/discourse/helpers/tonable-emoji-title.js | 6 ++---- .../javascripts/discourse/helpers/tonable-emoji-url.js | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/helpers/format-chat-date.js b/plugins/chat/assets/javascripts/discourse/helpers/format-chat-date.js index 37580a08552..fb504e08cc4 100644 --- a/plugins/chat/assets/javascripts/discourse/helpers/format-chat-date.js +++ b/plugins/chat/assets/javascripts/discourse/helpers/format-chat-date.js @@ -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) { `${display}` ); } -}); +} diff --git a/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-title.js b/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-title.js index f1fb7642d0a..6c4c625e15d 100644 --- a/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-title.js +++ b/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-title.js @@ -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}:`; -}); +} diff --git a/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-url.js b/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-url.js index 75e0bdc08d3..4d4aca6f301 100644 --- a/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-url.js +++ b/plugins/chat/assets/javascripts/discourse/helpers/tonable-emoji-url.js @@ -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`; -}); +}