From 934c07e34e4d2dab636f74aab7ce80c68d97bb51 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 25 Jun 2024 17:12:46 +0200 Subject: [PATCH] Fix #449: Remove the constraint for custom emojis shortnames to have ":" at the beginning and at the end. --- CHANGELOG.md | 4 ++++ client/common/configuration/elements/channel-emojis.ts | 4 +--- .../configuration/elements/templates/channel-emojis.ts | 6 ------ client/common/configuration/services/channel-details.ts | 2 +- languages/en.yml | 3 ++- server/lib/emojis/emojis.ts | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40b518ea..b6cdafa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ * #233: new option to [mute anonymous users](https://livingston.frama.io/peertube-plugin-livechat/documentation/user/streamers/moderation/). * #18: terms & conditions. You can configure terms&conditions on your instance that will be shown to each joining users. Streamers can also add [terms&conditions in their channels options](https://livingston.frama.io/peertube-plugin-livechat/documentation/user/streamers/terms/). +### Minor changes and fixes + +* Fix #449: Remove the constraint for custom emojis shortnames to have ":" at the beginning and at the end. + ## 10.1.2 * Fix: clicking on the import custom emojis button, without selected any file, was resulting in a state with all action button disabled. diff --git a/client/common/configuration/elements/channel-emojis.ts b/client/common/configuration/elements/channel-emojis.ts index 4475cc65..126e4c67 100644 --- a/client/common/configuration/elements/channel-emojis.ts +++ b/client/common/configuration/elements/channel-emojis.ts @@ -193,9 +193,7 @@ export class ChannelEmojisElement extends LivechatElement { } const url = await this._convertImageToDataUrl(entry.url) - let sn = entry.sn as string - if (!sn.startsWith(':')) { sn = ':' + sn } - if (!sn.endsWith(':')) { sn += ':' } + const sn = entry.sn as string const item: ChannelEmojisConfiguration['emojis']['customEmojis'][0] = { sn, diff --git a/client/common/configuration/elements/templates/channel-emojis.ts b/client/common/configuration/elements/templates/channel-emojis.ts index 0009ff06..12e1e293 100644 --- a/client/common/configuration/elements/templates/channel-emojis.ts +++ b/client/common/configuration/elements/templates/channel-emojis.ts @@ -91,12 +91,6 @@ export function tplChannelEmojis (el: ChannelEmojisElement): TemplateResult { el.resetValidation(e) if (el.channelEmojisConfiguration) { el.channelEmojisConfiguration.emojis.customEmojis = e.detail - // Fixing missing ':' for shortnames: - for (const desc of el.channelEmojisConfiguration.emojis.customEmojis) { - if (desc.sn === '') { continue } - if (!desc.sn.startsWith(':')) { desc.sn = ':' + desc.sn } - if (!desc.sn.endsWith(':')) { desc.sn += ':' } - } el.requestUpdate('channelEmojisConfiguration') } } diff --git a/client/common/configuration/services/channel-details.ts b/client/common/configuration/services/channel-details.ts index c54b95ec..43ec70b8 100644 --- a/client/common/configuration/services/channel-details.ts +++ b/client/common/configuration/services/channel-details.ts @@ -201,7 +201,7 @@ export class ChannelDetailsService { propertiesError[`emojis.${i}.sn`] = [] if (e.sn === '') { propertiesError[`emojis.${i}.sn`].push(ValidationErrorType.Missing) - } else if (!/^:[\w-]+:$/.test(e.sn)) { + } else if (!/^:?[\w-]+:?$/.test(e.sn)) { // optional ':' at the beggining and at the end propertiesError[`emojis.${i}.sn`].push(ValidationErrorType.WrongFormat) } else if (seen.has(e.sn)) { propertiesError[`emojis.${i}.sn`].push(ValidationErrorType.Duplicate) diff --git a/languages/en.yml b/languages/en.yml index b70ec513..17e3a701 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -512,7 +512,8 @@ livechat_configuration_channel_emojis_desc: | livechat_emojis_shortname: 'Short name' livechat_emojis_shortname_desc: | You can use emojis using ":shortname:". - The short name can only contain alphanumerical characters, underscores and hyphens. + The short name can start and/or end by a colon (:), and only contain alphanumerical characters, underscores and hyphens. + It is strongly recommended to start them by a colon, so that users can use autocompletion (by typing ":" then press TAB). livechat_emojis_file: 'File' livechat_emojis_file_desc: | The emoji file. diff --git a/server/lib/emojis/emojis.ts b/server/lib/emojis/emojis.ts index cfb1760b..ccd08f24 100644 --- a/server/lib/emojis/emojis.ts +++ b/server/lib/emojis/emojis.ts @@ -141,7 +141,7 @@ export class Emojis { * @param sn short name */ public validShortName (sn: any): boolean { - if ((typeof sn !== 'string') || !/^:[\w-]+:$/.test(sn)) { + if ((typeof sn !== 'string') || !/^:?[\w-]+:?$/.test(sn)) { this.logger.debug('Short name invalid: ' + (typeof sn === 'string' ? sn : '???')) return false }