Moderator notes WIP (#144)
This commit is contained in:
parent
704e660f37
commit
9c2b84027a
@ -76,7 +76,10 @@ export default class MUCNotesView extends DraggablesCustomElement {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await this.model.createNote({
|
await this.model.createNote({
|
||||||
description: description
|
description: description,
|
||||||
|
about_jid: ev.target.about_jid?.value || undefined,
|
||||||
|
about_nick: ev.target.about_nick?.value || undefined,
|
||||||
|
about_occupant_id: ev.target.about_occupant_id?.value || undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
this.closeCreateNoteForm()
|
this.closeCreateNoteForm()
|
||||||
|
51
conversejs/custom/plugins/notes/note-pubsub-manager.js
Normal file
51
conversejs/custom/plugins/notes/note-pubsub-manager.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { PubSubManager } from '../../shared/lib/pubsub-manager.js'
|
||||||
|
|
||||||
|
export class NotePubSubManager extends PubSubManager {
|
||||||
|
_additionalModelToData (item, data) {
|
||||||
|
super._additionalModelToData(item, data)
|
||||||
|
|
||||||
|
data.about_jid = item.get('about_jid')
|
||||||
|
data.about_occupant_id = item.get('about_occupant_id')
|
||||||
|
data.about_nick = item.get('about_nick')
|
||||||
|
}
|
||||||
|
|
||||||
|
_additionalDataToItemNode (data, item) {
|
||||||
|
super._additionalDataToItemNode(data, item)
|
||||||
|
|
||||||
|
const aboutAttributes = {}
|
||||||
|
if (data.about_jid !== undefined) {
|
||||||
|
aboutAttributes.jid = data.about_jid
|
||||||
|
}
|
||||||
|
if (data.about_nick !== undefined) {
|
||||||
|
aboutAttributes.nick = data.about_nick
|
||||||
|
}
|
||||||
|
const occupantId = data.about_occupant_id
|
||||||
|
|
||||||
|
if (occupantId !== undefined || Object.values(aboutAttributes).length) {
|
||||||
|
item.c('note-about', aboutAttributes)
|
||||||
|
if (occupantId) {
|
||||||
|
item.c('occupant-id', { xmlns: 'urn:xmpp:occupant-id:0', id: occupantId }).up()
|
||||||
|
}
|
||||||
|
item.up()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_additionalParseItemNode (itemNode, type, data) {
|
||||||
|
super._additionalParseItemNode(itemNode, type, data)
|
||||||
|
|
||||||
|
const about = itemNode.querySelector('& > note-about')
|
||||||
|
if (!about) { return }
|
||||||
|
|
||||||
|
data.about_jid = about.getAttribute('jid')
|
||||||
|
data.about_nick = about.getAttribute('nick')
|
||||||
|
|
||||||
|
const occupantIdEl = about.querySelector('& > occupant-id')
|
||||||
|
if (occupantIdEl) {
|
||||||
|
data.about_occupant_id = occupantIdEl.getAttribute('id')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,28 @@ class ChatRoomNote extends Model {
|
|||||||
async deleteItem () {
|
async deleteItem () {
|
||||||
return this.collection.chatroom.noteManager.deleteItems([this])
|
return this.collection.chatroom.noteManager.deleteItems([this])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAboutOccupant () {
|
||||||
|
const occupants = this.collection.chatroom?.occupants
|
||||||
|
if (!occupants?.findOccupant) { return undefined }
|
||||||
|
|
||||||
|
if (this.get('about_occupant_id')) {
|
||||||
|
const o = occupants.findOccupant({ occupant_id: this.get('about_occupant_id') })
|
||||||
|
if (o) { return o }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.get('about_nick') && !this.get('about_jid')) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const o = occupants.findOccupant({
|
||||||
|
nick: this.get('about_nick'),
|
||||||
|
jid: this.get('about_jid')
|
||||||
|
})
|
||||||
|
if (o) { return o }
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -9,10 +9,20 @@ export function tplMucNote (el, note) {
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const i18nDelete = __(LOC_moderator_note_delete)
|
const i18nDelete = __(LOC_moderator_note_delete)
|
||||||
|
|
||||||
|
const aboutOccupant = note.getAboutOccupant()
|
||||||
|
|
||||||
return !el.edit
|
return !el.edit
|
||||||
? html`
|
? html`
|
||||||
<div draggable="true" class="note-line draggables-line">
|
<div draggable="true" class="note-line draggables-line">
|
||||||
<div class="note-description">${note.get('description') ?? ''}</div>
|
<div class="note-description">${note.get('description') ?? ''}</div>
|
||||||
|
${
|
||||||
|
aboutOccupant
|
||||||
|
? html`
|
||||||
|
<livechat-converse-muc-note-occupant
|
||||||
|
.model=${aboutOccupant}
|
||||||
|
></livechat-converse-muc-note-occupant>`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
<button class="note-action" title="${__('Edit')}"
|
<button class="note-action" title="${__('Edit')}"
|
||||||
@click=${el.toggleEdit}
|
@click=${el.toggleEdit}
|
||||||
>
|
>
|
||||||
@ -27,6 +37,16 @@ export function tplMucNote (el, note) {
|
|||||||
: html`
|
: html`
|
||||||
<div class="note-line draggables-line">
|
<div class="note-line draggables-line">
|
||||||
<form class="converse-form" @submit=${el.saveNote}>
|
<form class="converse-form" @submit=${el.saveNote}>
|
||||||
|
${
|
||||||
|
aboutOccupant
|
||||||
|
? html`
|
||||||
|
<livechat-converse-muc-note-occupant
|
||||||
|
full_display=${true}
|
||||||
|
.model=${aboutOccupant}
|
||||||
|
></livechat-converse-muc-note-occupant>
|
||||||
|
`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
${_tplNoteForm(note)}
|
${_tplNoteForm(note)}
|
||||||
<fieldset class="form-group">
|
<fieldset class="form-group">
|
||||||
<input type="submit" class="btn btn-primary" value="${__('Ok')}" />
|
<input type="submit" class="btn btn-primary" value="${__('Ok')}" />
|
||||||
@ -53,9 +73,9 @@ function _tplNoteForm (note) {
|
|||||||
function _tplNoteOccupantFormFields (occupant) {
|
function _tplNoteOccupantFormFields (occupant) {
|
||||||
if (!occupant) { return '' }
|
if (!occupant) { return '' }
|
||||||
return html`
|
return html`
|
||||||
<input type="hidden" name="occupant_nick" value=${occupant.get('nick')} />
|
<input type="hidden" name="about_nick" value=${occupant.get('nick')} />
|
||||||
<input type="hidden" name="occupant_jid" value=${occupant.get('jid')} />
|
<input type="hidden" name="about_jid" value=${occupant.get('jid')} />
|
||||||
<input type="hidden" name="occupant_id" value=${occupant.get('occupant_id')} />
|
<input type="hidden" name="about_occupant_id" value=${occupant.get('occupant_id')} />
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { XMLNS_NOTE } from './constants.js'
|
import { XMLNS_NOTE } from './constants.js'
|
||||||
import { PubSubManager } from '../../shared/lib/pubsub-manager.js'
|
import { NotePubSubManager } from './note-pubsub-manager.js'
|
||||||
import { converse, _converse, api } from '../../../src/headless/index.js'
|
import { converse, _converse, api } from '../../../src/headless/index.js'
|
||||||
import { __ } from 'i18n'
|
import { __ } from 'i18n'
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ function _initChatRoomNotes (mucModel) {
|
|||||||
|
|
||||||
mucModel.notes = new _converse.exports.ChatRoomNotes(undefined, { chatroom: mucModel })
|
mucModel.notes = new _converse.exports.ChatRoomNotes(undefined, { chatroom: mucModel })
|
||||||
|
|
||||||
mucModel.noteManager = new PubSubManager(
|
mucModel.noteManager = new NotePubSubManager(
|
||||||
mucModel.get('jid'),
|
mucModel.get('jid'),
|
||||||
'livechat-notes', // the node name
|
'livechat-notes', // the node name
|
||||||
{
|
{
|
||||||
|
@ -123,6 +123,7 @@ export class PubSubManager {
|
|||||||
if (v === undefined) { continue }
|
if (v === undefined) { continue }
|
||||||
data[field] = v
|
data[field] = v
|
||||||
}
|
}
|
||||||
|
this._additionalModelToData(item, data)
|
||||||
|
|
||||||
console.log('Saving item...')
|
console.log('Saving item...')
|
||||||
await this._save(type, data, id)
|
await this._save(type, data, id)
|
||||||
@ -178,6 +179,8 @@ export class PubSubManager {
|
|||||||
item.c(fieldName).t(data[fieldName]).up()
|
item.c(fieldName).t(data[fieldName]).up()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._additionalDataToItemNode(data, item)
|
||||||
|
|
||||||
await api.pubsub.publish(this.roomJID, this.node, item)
|
await api.pubsub.publish(this.roomJID, this.node, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +339,7 @@ export class PubSubManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this._additionalParseItemNode(itemNode, type, data)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,4 +355,19 @@ export class PubSubManager {
|
|||||||
_typeFromCollection (collection) {
|
_typeFromCollection (collection) {
|
||||||
return Object.values(this.types).find(type => type.collection === collection)
|
return Object.values(this.types).find(type => type.collection === collection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overload to add some custom code for model to data conversion.
|
||||||
|
*/
|
||||||
|
_additionalModelToData (_item, _data) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overload to add some custom code for data to stanza conversion.
|
||||||
|
*/
|
||||||
|
_additionalDataToItemNode (_data, _item) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overload to add some custom code item parsing.
|
||||||
|
*/
|
||||||
|
_additionalParseItemNode (_itemNode, _type, _data) {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user