Custom channel emoticons WIP (#130) + Fix cleanup on channel deletion.

This commit is contained in:
John Livingston
2024-06-06 14:55:40 +02:00
parent 92e9d6d1af
commit 893708d93a
3 changed files with 81 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import { fillVideoCustomFields } from '../../custom-fields'
import { videoHasWebchat } from '../../../../shared/lib/video'
import { updateProsodyRoom } from '../../prosody/api/manage-rooms'
import { getChannelInfosById } from '../../database/channel'
import { Emojis } from '../../emojis'
/**
* Register stuffs related to channel configuration
@ -40,11 +41,12 @@ async function initChannelConfiguration (options: RegisterServerOptions): Promis
registerHook({
target: 'action:api.video-channel.deleted',
handler: async (params: { channel: VideoChannel }) => {
handler: async (params: { videoChannel: VideoChannel }) => {
// When a video is deleted, we can delete the channel2room and room2channel files.
// Note: don't need to check if there is a chat for this video, just deleting existing files...
if (!params.channel.isLocal) { return }
const channelId = params.channel.id
// Note: this hook is only called for local channels.
const channelId = params.videoChannel.id
logger.info(`Channel ${channelId} deleted, removing 'channel configuration' related stuff.`)
// Here the associated channel can be either channel.X@mucdomain or video_uuid@mucdomain.
// In first case, nothing to do... in the second, we must delete.
@ -55,6 +57,13 @@ async function initChannelConfiguration (options: RegisterServerOptions): Promis
logger.error(err)
}
logger.info(`Channel ${channelId} deleted, removing 'custom emojis' related stuff.`)
try {
Emojis.singletonSafe()?.deleteChannelDefinition(channelId)
} catch (err) {
logger.error(err)
}
// Note: we don't delete the room. So that admins can check logs afterward, if any doubts.
}
})