Initialize prosody-list-rooms button.

This commit is contained in:
John Livingston
2021-06-12 01:16:57 +02:00
parent cc9cbf692a
commit 56e74e0877
6 changed files with 119 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import type { Router, Request, Response, NextFunction } from 'express'
import type { ChatType, ProsodyListRoomsResult } from '../../../shared/lib/types'
import { diag } from '../diagnostic'
import { getBaseStaticRoute, isUserAdmin } from '../helpers'
import { asyncMiddleware } from '../middlewares/async'
@ -39,6 +40,38 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise<Rout
}
))
router.get('/prosody-list-rooms', asyncMiddleware(
async (req: Request, res: Response, _next: NextFunction) => {
if (!res.locals.authenticated) {
res.sendStatus(403)
return
}
if (!await isUserAdmin(options, res)) {
res.sendStatus(403)
return
}
const chatType: ChatType = await options.settingsManager.getSetting('chat-type') as ChatType
if (chatType !== 'builtin-prosody') {
const message = 'Please save the settings first.' // TODO: translate?
res.status(200)
const r: ProsodyListRoomsResult = {
ok: false,
error: message
}
res.json(r)
return
}
res.status(200)
const r: ProsodyListRoomsResult = {
ok: true,
rooms: [] // TODO: get room list from Prosody
}
res.json(r)
}
))
return router
}

View File

@ -91,6 +91,13 @@ Please read the
private: true
})
registerSetting({
name: 'prosody-list-rooms',
label: 'List existing rooms',
type: 'html',
descriptionHTML: '<a class="peertube-plugin-livechat-prosody-list-rooms">List rooms</a>',
private: true
})
registerSetting({
name: 'prosody-port',
label: 'Prosody port',