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:
parent
dd4bca8c06
commit
f88520d925
@ -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', () => {
|
||||
|
@ -34,6 +34,7 @@ declare global {
|
||||
env: {
|
||||
html: Function
|
||||
sizzle: Function
|
||||
dayjs: Function
|
||||
}
|
||||
}
|
||||
initConversePlugins: typeof initConversePlugins
|
||||
|
@ -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...
|
||||
|
32
conversejs/lib/plugins/livechat-specific/message-action.ts
Normal file
32
conversejs/lib/plugins/livechat-specific/message-action.ts
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user