Emoji only mode WIP:
* Button to enable it on all rooms.
This commit is contained in:
parent
08017ac2bb
commit
91cddfa8d8
6
client/@types/global.d.ts
vendored
6
client/@types/global.d.ts
vendored
@ -144,3 +144,9 @@ declare const LOC_PROSODY_FIREWALL_FILE_ENABLED: string
|
||||
declare const LOC_PROSODY_FIREWALL_NAME: string
|
||||
declare const LOC_PROSODY_FIREWALL_NAME_DESC: string
|
||||
declare const LOC_PROSODY_FIREWALL_CONTENT: string
|
||||
|
||||
declare const LOC_EMOJI_ONLY_MODE_TITLE: string
|
||||
declare const LOC_EMOJI_ONLY_MODE_DESC_1: string
|
||||
declare const LOC_EMOJI_ONLY_MODE_DESC_2: string
|
||||
declare const LOC_EMOJI_ONLY_MODE_DESC_3: string
|
||||
declare const LOC_EMOJI_ONLY_ENABLE_ALL_ROOMS: string
|
||||
|
@ -256,6 +256,21 @@ export class ChannelEmojisElement extends LivechatElement {
|
||||
}
|
||||
}
|
||||
|
||||
public async enableEmojisOnlyModeOnAllRooms (ev: Event): Promise<void> {
|
||||
ev.preventDefault()
|
||||
if (!this._channelDetailsService || !this.channelId) {
|
||||
this.ptNotifier.error(await this.ptTranslate(LOC_ERROR))
|
||||
return
|
||||
}
|
||||
try {
|
||||
await this._channelDetailsService.enableEmojisOnlyModeOnAllRooms(this.channelId)
|
||||
this.ptNotifier.info(await this.ptTranslate(LOC_SUCCESSFULLY_SAVED))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
this.ptNotifier.error(await this.ptTranslate(LOC_ERROR))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an url (or dataUrl), download the image, and converts to dataUrl.
|
||||
* @param url the url
|
||||
|
@ -45,13 +45,14 @@ export function tplChannelEmojis (el: ChannelEmojisElement): TemplateResult {
|
||||
|
||||
<livechat-channel-tabs .active=${'emojis'} .channelId=${el.channelId}></livechat-channel-tabs>
|
||||
|
||||
<h2>${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_EMOJIS_TITLE)}</h2>
|
||||
|
||||
<p>
|
||||
${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_EMOJIS_DESC)}
|
||||
<livechat-help-button .page=${'documentation/user/streamers/emojis'}>
|
||||
</livechat-help-button>
|
||||
</p>
|
||||
|
||||
|
||||
<form role="form" @submit=${el.saveEmojis} @change=${el.resetValidation}>
|
||||
<div class="peertube-plugin-livechat-configuration-actions">
|
||||
${
|
||||
@ -106,5 +107,23 @@ export function tplChannelEmojis (el: ChannelEmojisElement): TemplateResult {
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2>${ptTr(LOC_EMOJI_ONLY_MODE_TITLE)}</h2>
|
||||
|
||||
<p>
|
||||
${ptTr(LOC_EMOJI_ONLY_MODE_DESC_1, true)}
|
||||
</p>
|
||||
<p>
|
||||
${ptTr(LOC_EMOJI_ONLY_MODE_DESC_2, true)}
|
||||
</p>
|
||||
<p>
|
||||
${ptTr(LOC_EMOJI_ONLY_MODE_DESC_3, true)}
|
||||
</p>
|
||||
|
||||
<div class="peertube-plugin-livechat-configuration-actions">
|
||||
<button type="button" @click=${el.enableEmojisOnlyModeOnAllRooms}>
|
||||
${ptTr(LOC_EMOJI_ONLY_ENABLE_ALL_ROOMS)}
|
||||
</button>
|
||||
</div>
|
||||
</div>`
|
||||
}
|
||||
|
@ -312,4 +312,23 @@ export class ChannelDetailsService {
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
public async enableEmojisOnlyModeOnAllRooms (channelId: number): Promise<void> {
|
||||
const response = await fetch(
|
||||
getBaseRoute(this._registerClientOptions) +
|
||||
'/api/configuration/channel/emojis/' +
|
||||
encodeURIComponent(channelId) +
|
||||
'/enable_emoji_only',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: this._headers
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Can\'t enable Emojis Only Mode on all rooms.')
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
}
|
||||
|
@ -638,3 +638,18 @@ prosody_firewall_name_desc: |
|
||||
prosody_firewall_content: File content
|
||||
|
||||
emoji_only_info: Emoji only mode is enabled, you can only use emoji in your messages.
|
||||
emoji_only_mode_title: Emojis only mode
|
||||
emoji_only_mode_desc_1: |
|
||||
You can enable an "Emojy only mode" in your chatrooms.
|
||||
When this mode is enabled, participants can only send emojis (standard, or channel custom emojis).
|
||||
Moderators are not affected by this limitation.
|
||||
emoji_only_mode_desc_2: |
|
||||
This mode can be usefull for Example:
|
||||
<ul>
|
||||
<li>To avoid spam or offensive message when you are not here to moderate.</li>
|
||||
<li>When there are too many speaking participants, and you can't no more moderate correctly.</li>
|
||||
</ul>
|
||||
emoji_only_mode_desc_3: |
|
||||
To enable or disable this mode, you can use the room configuration form.
|
||||
If you want to enable it for all your rooms at once, you can use the button bellow.
|
||||
emoji_only_enable_all_rooms: Enable the emoji only mode on all channel's chatrooms
|
||||
|
@ -107,7 +107,9 @@ local function update_room(event)
|
||||
end
|
||||
if type(config.livechat_emoji_only) == "boolean" then
|
||||
if set_peertubelivechat_emoji_only_mode then
|
||||
set_peertubelivechat_emoji_only_mode(room, config.livechat_emoji_only)
|
||||
if set_peertubelivechat_emoji_only_mode(room, config.livechat_emoji_only) then
|
||||
must104 = true;
|
||||
end
|
||||
end
|
||||
end
|
||||
if type(config.livechat_custom_emoji_regexp) == "string" then
|
||||
|
@ -200,6 +200,44 @@ async function initConfigurationApiRouter (options: RegisterServerOptions, route
|
||||
}
|
||||
}
|
||||
]))
|
||||
|
||||
router.post('/configuration/channel/emojis/:channelId/enable_emoji_only', asyncMiddleware([
|
||||
checkConfigurationEnabledMiddleware(options),
|
||||
getCheckConfigurationChannelMiddleware(options),
|
||||
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
if (!res.locals.channelInfos) {
|
||||
throw new Error('Missing channelInfos in res.locals, should not happen')
|
||||
}
|
||||
|
||||
const emojis = Emojis.singleton()
|
||||
const channelInfos = res.locals.channelInfos as ChannelInfos
|
||||
|
||||
logger.info(`Enabling emoji only mode on each channel ${channelInfos.id} rooms ...`)
|
||||
|
||||
// We can also update the EmojisRegexp, just in case.
|
||||
const customEmojisRegexp = await emojis.getChannelCustomEmojisRegexp(channelInfos.id)
|
||||
const roomJIDs = RoomChannel.singleton().getChannelRoomJIDs(channelInfos.id)
|
||||
for (const roomJID of roomJIDs) {
|
||||
// No need to await here
|
||||
logger.info(`Enabling emoji only mode on room ${roomJID} ...`)
|
||||
updateProsodyRoom(options, roomJID, {
|
||||
livechat_emoji_only: true,
|
||||
livechat_custom_emoji_regexp: customEmojisRegexp
|
||||
}).then(
|
||||
() => {},
|
||||
(err) => logger.error(err)
|
||||
)
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
res.json({ ok: true })
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
res.sendStatus(500)
|
||||
}
|
||||
}
|
||||
]))
|
||||
}
|
||||
|
||||
export {
|
||||
|
Loading…
x
Reference in New Issue
Block a user