Custom channel emoticons WIP (#130)

This commit is contained in:
John Livingston
2024-06-06 15:03:12 +02:00
parent 893708d93a
commit a777c7ac8d
12 changed files with 56 additions and 17 deletions

View File

@ -285,11 +285,8 @@ async function _connectionInfos (
params.forcetype ?? false
)
if (video?.channelId && await Emojis.singletonSafe()?.channelHasCustomEmojis(video.channelId)) {
customEmojisUrl = getBaseRouterRoute(options) +
'emojis/channel/' +
encodeURIComponent(video.channelId) +
'/definition'
if (video?.channelId) {
customEmojisUrl = await Emojis.singletonSafe()?.channelCustomEmojisUrl(video.channelId)
}
} catch (err) {
options.peertubeHelpers.logger.error(err)

View File

@ -63,6 +63,26 @@ export class Emojis {
return fs.promises.access(filepath, fs.constants.F_OK).then(() => true, () => false)
}
/**
* Gets the public url for the channel emojis definition, if there are custom emojis.
* @param channelId channel Id
*/
public async channelCustomEmojisUrl (channelId: number): Promise<string | undefined> {
if (!await this.channelHasCustomEmojis(channelId)) {
return undefined
}
return canonicalizePluginUri(
this.options,
getBaseRouterRoute(this.options) +
'emojis/channel/' +
encodeURIComponent(channelId) +
'/definition',
{
removePluginVersion: true
}
)
}
/**
* Get the file path for the channel definition JSON file (does not test if the file exists).
* @param channelId channel Id
@ -286,6 +306,13 @@ export class Emojis {
customEmojis.push(sanitized)
}
// For now, the frontend does not implement isCategoryEmoji.
// if there is no isCategoryEmoji, we will take the first value.
// TODO: remove this when the frontend will be able to set this.
if (!categoryEmojiFound && customEmojis.length) {
customEmojis[0].isCategoryEmoji = true
}
const result: ChannelEmojis = {
customEmojis: customEmojis
}