Custom channel emoticons WIP (#130)
This commit is contained in:
@ -43,7 +43,8 @@ async function getConverseJSParams (
|
||||
'converse-theme',
|
||||
'federation-no-remote-chat',
|
||||
'prosody-room-allow-s2s',
|
||||
'chat-no-anonymous'
|
||||
'chat-no-anonymous',
|
||||
'disable-channel-configuration'
|
||||
])
|
||||
|
||||
if (settings['chat-no-anonymous'] && userIsConnected === false) {
|
||||
@ -133,7 +134,8 @@ async function getConverseJSParams (
|
||||
// forceDefaultHideMucParticipants is for testing purpose
|
||||
// (so we can stress test with the muc participant list hidden by default)
|
||||
forceDefaultHideMucParticipants: params.forceDefaultHideMucParticipants,
|
||||
externalAuthOIDC
|
||||
externalAuthOIDC,
|
||||
customEmojisUrl: connectionInfos.customEmojisUrl
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,6 +239,7 @@ async function _connectionInfos (
|
||||
localWsUri: string | null
|
||||
remoteConnectionInfos: WCRemoteConnectionInfos | undefined
|
||||
roomJID: string
|
||||
customEmojisUrl?: string
|
||||
} | InitConverseJSParamsError> {
|
||||
const { video, remoteChatInfos, channelId, roomKey } = roomInfos
|
||||
|
||||
@ -249,6 +252,7 @@ async function _connectionInfos (
|
||||
|
||||
let remoteConnectionInfos: WCRemoteConnectionInfos | undefined
|
||||
let roomJID: string
|
||||
let customEmojisUrl: string | undefined
|
||||
if (video?.remote) {
|
||||
const canWebsocketS2S = !settings['federation-no-remote-chat'] && !settings['disable-websocket']
|
||||
const canDirectS2S = !settings['federation-no-remote-chat'] && !!settings['prosody-room-allow-s2s']
|
||||
@ -266,6 +270,8 @@ async function _connectionInfos (
|
||||
}
|
||||
}
|
||||
roomJID = remoteConnectionInfos.roomJID
|
||||
|
||||
// TODO: fill customEmojisUrl (how to get the info? is the remote livechat compatible?)
|
||||
} else {
|
||||
try {
|
||||
roomJID = await _localRoomJID(
|
||||
@ -277,6 +283,12 @@ async function _connectionInfos (
|
||||
channelId,
|
||||
params.forcetype ?? false
|
||||
)
|
||||
|
||||
if (!settings['disable-channel-configuration'] && video?.channelId) {
|
||||
customEmojisUrl = getBaseRouterRoute(options) +
|
||||
'api/configuration/channel/emojis/' +
|
||||
encodeURIComponent(video.channelId)
|
||||
}
|
||||
} catch (err) {
|
||||
options.peertubeHelpers.logger.error(err)
|
||||
return {
|
||||
@ -293,7 +305,8 @@ async function _connectionInfos (
|
||||
localBoshUri,
|
||||
localWsUri,
|
||||
remoteConnectionInfos,
|
||||
roomJID
|
||||
roomJID,
|
||||
customEmojisUrl
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,13 @@ import { isUserAdminOrModerator } from '../../helpers'
|
||||
* Returns a middleware handler to get the channelInfos from the channel parameter.
|
||||
* This is used in api related to channel configuration options.
|
||||
* @param options Peertube server options
|
||||
* @param publicPage If true, the page is considered public, and we don't test user rights.
|
||||
* @returns middleware function
|
||||
*/
|
||||
function getCheckConfigurationChannelMiddleware (options: RegisterServerOptions): RequestPromiseHandler {
|
||||
function getCheckConfigurationChannelMiddleware (
|
||||
options: RegisterServerOptions,
|
||||
publicPage?: boolean
|
||||
): RequestPromiseHandler {
|
||||
return async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
const channelId = req.params.channelId
|
||||
@ -32,18 +36,20 @@ function getCheckConfigurationChannelMiddleware (options: RegisterServerOptions)
|
||||
return
|
||||
}
|
||||
|
||||
// To access this page, you must either be:
|
||||
// - the channel owner,
|
||||
// - an instance modo/admin
|
||||
// - TODO: a channel chat moderator, as defined in this page.
|
||||
if (channelInfos.ownerAccountId === currentUser.Account.id) {
|
||||
logger.debug('Current user is the channel owner')
|
||||
} else if (await isUserAdminOrModerator(options, res)) {
|
||||
logger.debug('Current user is an instance moderator or admin')
|
||||
} else {
|
||||
logger.warn('Current user tries to access a channel for which he has no right.')
|
||||
res.sendStatus(403)
|
||||
return
|
||||
if (!publicPage) {
|
||||
// To access this page, you must either be:
|
||||
// - the channel owner,
|
||||
// - an instance modo/admin
|
||||
// - TODO: a channel chat moderator, as defined in this page.
|
||||
if (channelInfos.ownerAccountId === currentUser.Account.id) {
|
||||
logger.debug('Current user is the channel owner')
|
||||
} else if (await isUserAdminOrModerator(options, res)) {
|
||||
logger.debug('Current user is an instance moderator or admin')
|
||||
} else {
|
||||
logger.warn('Current user tries to access a channel for which he has no right.')
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug('User can access the configuration channel api.')
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||
import type { Router, Request, Response, NextFunction } from 'express'
|
||||
import type { ChannelInfos } from '../../../../shared/lib/types'
|
||||
import type { ChannelInfos, ChannelEmojis } from '../../../../shared/lib/types'
|
||||
import { asyncMiddleware } from '../../middlewares/async'
|
||||
import { getCheckConfigurationChannelMiddleware } from '../../middlewares/configuration/channel'
|
||||
import { checkConfigurationEnabledMiddleware } from '../../middlewares/configuration/configuration'
|
||||
@ -110,6 +110,30 @@ async function initConfigurationApiRouter (options: RegisterServerOptions, route
|
||||
res.json(result)
|
||||
}
|
||||
]))
|
||||
|
||||
router.get('/configuration/channel/emojis/:channelId', asyncMiddleware([
|
||||
checkConfigurationEnabledMiddleware(options),
|
||||
getCheckConfigurationChannelMiddleware(options, true),
|
||||
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
||||
if (!res.locals.channelInfos) {
|
||||
logger.error('Missing channelInfos in res.locals, should not happen')
|
||||
res.sendStatus(500)
|
||||
return
|
||||
}
|
||||
// const channelInfos = res.locals.channelInfos as ChannelInfos
|
||||
|
||||
const channelEmojis: ChannelEmojis = {
|
||||
customEmojis: [{
|
||||
sn: ':test:',
|
||||
url: '/dist/images/custom_emojis/xmpp.png',
|
||||
isCategoryEmoji: true
|
||||
}]
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
res.json(channelEmojis)
|
||||
}
|
||||
]))
|
||||
}
|
||||
|
||||
export {
|
||||
|
Reference in New Issue
Block a user