Implements #146: copy message button for moderators

We overload the copy message method that comes with Converse 11, to add
the message metadata (nick and full date).
This commit is contained in:
John Livingston 2024-07-26 10:51:55 +02:00
parent dd4bca8c06
commit f88520d925
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
4 changed files with 36 additions and 1 deletions

View File

@ -167,7 +167,7 @@ async function displayConverseJS (
const converseJSParams: InitConverseJSParams = await (response).json()
if (!pollListenerInitiliazed) {
// First time we got here, initiliaze this event:
// First time we got here, initialize this event:
const i18nVoteOk = await clientOptions.peertubeHelpers.translate(LOC_POLL_VOTE_OK)
pollListenerInitiliazed = true
document.addEventListener('livechat-poll-vote', () => {

View File

@ -34,6 +34,7 @@ declare global {
env: {
html: Function
sizzle: Function
dayjs: Function
}
}
initConversePlugins: typeof initConversePlugins

View File

@ -7,6 +7,7 @@ import { customizeToolbar } from './livechat-specific/toolbar'
import { initReconnectionStuff } from './livechat-specific/reconnection'
import { chatRoomOverrides } from './livechat-specific/chatroom'
import { chatRoomMessageOverrides } from './livechat-specific/chatroom-message'
import { customizeMessageAction } from './livechat-specific/message-action'
export const livechatSpecificsPlugin = {
dependencies: ['converse-muc', 'converse-muc-views'],
@ -22,6 +23,7 @@ export const livechatSpecificsPlugin = {
customizeHeading(this)
customizeToolbar(this)
customizeMessageAction(this)
_converse.api.listen.on('chatRoomViewInitialized', function (this: any, _model: any): void {
// Remove the spinner if present...

View File

@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
//
// SPDX-License-Identifier: AGPL-3.0-only
/**
* Do some customization on Message actions custom elements:
* * override the copy text method to add meta data
*
* @param plugin The plugin object
*/
export function customizeMessageAction (plugin: any): void {
const _converse = plugin._converse
const MessageActions = _converse.api.elements.registry['converse-message-actions']
if (MessageActions) {
class MessageActionsOverloaded extends MessageActions {
async onMessageCopyButtonClicked (ev?: Event): Promise<void> {
ev?.preventDefault?.()
let txt = ''
try {
txt += this.model.getDisplayName() as string
txt += ' - '
const date = new Date(this.model.get('edited') || this.model.get('time'))
txt += date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
txt += '\n'
} catch {}
txt += this.model.getMessageText() as string
await navigator.clipboard.writeText(txt)
}
}
_converse.api.elements.define('converse-message-actions', MessageActionsOverloaded)
}
}