From a46425d51fdaf40f3700d77d751c84ebf4db9529 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 31 Jul 2024 15:53:19 +0200 Subject: [PATCH] Moderator notes WIP (#144) --- conversejs/build-conversejs.sh | 4 +- conversejs/custom/plugins/notes/api.js | 31 ++++++++++ .../plugins/notes/components/muc-note-view.js | 3 +- .../notes/components/muc-notes-view.js | 15 ++++- conversejs/custom/plugins/notes/index.js | 5 ++ .../notes/styles/muc-note-occupant.scss | 2 + .../custom/plugins/notes/styles/muc-note.scss | 5 +- .../plugins/notes/styles/muc-notes.scss | 17 ++++++ .../notes/templates/muc-note-occupant.js | 2 +- .../plugins/notes/templates/muc-note.js | 29 +++++++-- .../plugins/notes/templates/muc-notes.js | 61 ++++++++++++++++++- conversejs/custom/plugins/notes/utils.js | 27 ++++---- .../custom/shared/components/font-awesome.js | 5 ++ conversejs/loc.keys.js | 4 +- languages/en.yml | 4 +- 15 files changed, 183 insertions(+), 31 deletions(-) create mode 100644 conversejs/custom/plugins/notes/api.js diff --git a/conversejs/build-conversejs.sh b/conversejs/build-conversejs.sh index 72c79da0..9ebdedbf 100644 --- a/conversejs/build-conversejs.sh +++ b/conversejs/build-conversejs.sh @@ -18,8 +18,8 @@ set -x CONVERSE_VERSION="v11.0.0" CONVERSE_REPO="https://github.com/conversejs/converse.js.git" # You can eventually set CONVERSE_COMMIT to a specific commit ID, if you want to apply some patches. -# 2024-07-30: using Converse upstream (v11 WIP). -CONVERSE_COMMIT="9ddf6e7b7a83fdc04c8b55f0f470e59c09283a39" +# 2024-07-31: using Converse upstream (v11 WIP). +CONVERSE_COMMIT="2f8cfc02d04bb6191b3b9facb706e475836279f5" # # 2024-07-31: testing the jcbrand/bootstrap5 branch # CONVERSE_COMMIT="e5edeec997d53a8720470a49685be123e8688e1c" diff --git a/conversejs/custom/plugins/notes/api.js b/conversejs/custom/plugins/notes/api.js new file mode 100644 index 00000000..9836a64d --- /dev/null +++ b/conversejs/custom/plugins/notes/api.js @@ -0,0 +1,31 @@ +async function openNotes () { + const appElement = document.querySelector('livechat-converse-muc-note-app') + if (!appElement) { + throw new Error('Cant find Note App Element') + } + await appElement.showApp() + await appElement.updateComplete // waiting for the app to be open + + const notesElement = appElement.querySelector('livechat-converse-muc-notes') + if (!notesElement) { + throw new Error('Cant find Notes Element') + } + await notesElement.updateComplete + return notesElement +} + +async function openCreateNoteForm (occupant) { + const notesElement = await openNotes() + await notesElement.openCreateNoteForm(undefined, occupant) +} + +async function searchNotesAbout (occupant) { + const notesElement = await openNotes() + await notesElement.filterNotes({ occupant }) +} + +export default { + openNotes, + openCreateNoteForm, + searchNotesAbout +} diff --git a/conversejs/custom/plugins/notes/components/muc-note-view.js b/conversejs/custom/plugins/notes/components/muc-note-view.js index cdcb4e15..260b31e3 100644 --- a/conversejs/custom/plugins/notes/components/muc-note-view.js +++ b/conversejs/custom/plugins/notes/components/muc-note-view.js @@ -13,7 +13,8 @@ export default class MUCNoteView extends CustomElement { static get properties () { return { model: { type: Object, attribute: true }, - edit: { type: Boolean, attribute: false } + edit: { type: Boolean, attribute: false }, + is_ocupant_filter: { type: Boolean, attribute: true } } } diff --git a/conversejs/custom/plugins/notes/components/muc-notes-view.js b/conversejs/custom/plugins/notes/components/muc-notes-view.js index cedd26dc..c393f1bc 100644 --- a/conversejs/custom/plugins/notes/components/muc-notes-view.js +++ b/conversejs/custom/plugins/notes/components/muc-notes-view.js @@ -15,7 +15,8 @@ export default class MUCNotesView extends DraggablesCustomElement { model: { type: Object, attribute: true }, create_note_error_message: { type: String, attribute: false }, create_note_opened: { type: Boolean, attribute: false }, - create_note_for_occupant: { type: Object, attribute: false } + create_note_about_occupant: { type: Object, attribute: false }, + occupant_filter: { type: Object, attribute: false } } } @@ -45,7 +46,11 @@ export default class MUCNotesView extends DraggablesCustomElement { async openCreateNoteForm (ev, occupant) { ev?.preventDefault?.() this.create_note_opened = true - this.create_note_for_occupant = occupant ?? undefined + this.create_note_about_occupant = occupant ?? undefined + if (this.create_note_about_occupant === undefined && this.occupant_filter) { + // if we have a current filter, we can use it for the new note. + this.create_note_about_occupant = this.occupant_filter + } await this.updateComplete const textarea = this.querySelector('.notes-create-note textarea[name="description"]') if (textarea) { @@ -56,7 +61,11 @@ export default class MUCNotesView extends DraggablesCustomElement { closeCreateNoteForm (ev) { ev?.preventDefault?.() this.create_note_opened = false - this.create_note_for_occupant = undefined + this.create_note_about_occupant = undefined + } + + filterNotes (filters) { + this.occupant_filter = filters?.occupant || undefined } async submitCreateNote (ev) { diff --git a/conversejs/custom/plugins/notes/index.js b/conversejs/custom/plugins/notes/index.js index 860ec9eb..ad93c941 100644 --- a/conversejs/custom/plugins/notes/index.js +++ b/conversejs/custom/plugins/notes/index.js @@ -7,6 +7,7 @@ import { XMLNS_NOTE } from './constants.js' import { ChatRoomNote } from './note.js' import { ChatRoomNotes } from './notes.js' import { initOrDestroyChatRoomNotes, getHeadingButtons, getMessageActionButtons } from './utils.js' +import notesApi from './api.js' import './components/muc-note-app-view.js' import './components/muc-notes-view.js' @@ -30,6 +31,10 @@ converse.plugins.add('livechat-converse-notes', { livechat_note_app_restore: false // should we open the app by default if it was previously oppened? }) + Object.assign(_converse.api, { + livechat_notes: notesApi + }) + _converse.api.listen.on('chatRoomInitialized', muc => { muc.session.on('change:connection_status', _session => { // When joining a room, initializing the Notes object (if user has access), diff --git a/conversejs/custom/plugins/notes/styles/muc-note-occupant.scss b/conversejs/custom/plugins/notes/styles/muc-note-occupant.scss index 18f3819a..185caa3d 100644 --- a/conversejs/custom/plugins/notes/styles/muc-note-occupant.scss +++ b/conversejs/custom/plugins/notes/styles/muc-note-occupant.scss @@ -27,6 +27,8 @@ } & > ul { + font-weight: lighter; + font-size: 0.75em; list-style: none; text-align: right; } diff --git a/conversejs/custom/plugins/notes/styles/muc-note.scss b/conversejs/custom/plugins/notes/styles/muc-note.scss index d3f698d0..d0dc986a 100644 --- a/conversejs/custom/plugins/notes/styles/muc-note.scss +++ b/conversejs/custom/plugins/notes/styles/muc-note.scss @@ -20,8 +20,11 @@ column-gap: 0.25em; width: 100%; - .note-description { + .note-content { flex-grow: 2; + } + + .note-description { white-space: pre-wrap; } diff --git a/conversejs/custom/plugins/notes/styles/muc-notes.scss b/conversejs/custom/plugins/notes/styles/muc-notes.scss index 8cea37b8..2dedc47b 100644 --- a/conversejs/custom/plugins/notes/styles/muc-notes.scss +++ b/conversejs/custom/plugins/notes/styles/muc-notes.scss @@ -18,4 +18,21 @@ padding-left: 0.25em; padding-right: 0.25em; } + + .notes-filters { + border: 1px solid var(--chatroom-head-bg-color); + border-radius: 4px; + display: flex; + flex-flow: row nowrap; + justify-content: space-between; + align-items: center; + margin: 0.25em 0; + padding: 0.25em; + column-gap: 0.25em; + width: 100%; + + livechat-converse-muc-note-occupant { + flex-grow: 2; + } + } } diff --git a/conversejs/custom/plugins/notes/templates/muc-note-occupant.js b/conversejs/custom/plugins/notes/templates/muc-note-occupant.js index 1ed19b9d..6de7e36c 100644 --- a/conversejs/custom/plugins/notes/templates/muc-note-occupant.js +++ b/conversejs/custom/plugins/notes/templates/muc-note-occupant.js @@ -27,7 +27,7 @@ export function tplMucNoteOccupant (el, occupant) { ${ el.full_display - ? html`