New features: announcements WIP (#518):

* handling message correction.
This commit is contained in:
John Livingston 2024-09-12 12:07:55 +02:00
parent f0088671ea
commit 4e436c00f0
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
2 changed files with 28 additions and 0 deletions

View File

@ -39,6 +39,11 @@ declare global {
sizzle: Function sizzle: Function
dayjs: Function dayjs: Function
__: Function __: Function
u: {
hasClass: Function
addClass: Function
removeClass: Function
}
} }
} }
initConversePlugins: typeof initConversePlugins initConversePlugins: typeof initConversePlugins

View File

@ -45,6 +45,8 @@ export const livechatAnnouncementsPlugin = {
/** /**
* Overloads the MUCMessageForm to handle the announcement type field (if present) when sending a message. * Overloads the MUCMessageForm to handle the announcement type field (if present) when sending a message.
*
* Also hides the announcement type field if we are correcting a previous message.
*/ */
function overrideMUCMessageForm (_converse: any, current: Current): void { function overrideMUCMessageForm (_converse: any, current: Current): void {
const MUCMessageForm = _converse.api.elements.registry['converse-muc-message-form'] const MUCMessageForm = _converse.api.elements.registry['converse-muc-message-form']
@ -61,6 +63,27 @@ function overrideMUCMessageForm (_converse: any, current: Current): void {
} }
current.announcementType = undefined current.announcementType = undefined
} }
insertIntoTextArea (...args: any[]): void {
super.insertIntoTextArea(...args)
try {
// FIXME: doing this here is not very clean.
// But that's how ConverseJS adds or removes the 'correction' class to the textarea.
const textarea = this.querySelector('.chat-textarea')
if (!textarea) { return }
const correcting = window.converse.env.u.hasClass('correcting', textarea)
const announcementForm = this.querySelector('.livechat-announcements-form')
const announcementSelect = this.querySelector('[name=livechat-announcements]')
if (correcting) {
if (announcementSelect) { announcementSelect.selectedIndex = 0 }
if (announcementForm) { announcementForm.style.display = 'none' }
} else {
if (announcementForm) { announcementForm.style.display = 'block' }
}
} catch (err) {
console.error(err)
}
}
} }
_converse.api.elements.define('converse-muc-message-form', MUCMessageFormloaded) _converse.api.elements.define('converse-muc-message-form', MUCMessageFormloaded)
} }