Task lists WIP:
* fix mod pubsub * front-end WIP
This commit is contained in:
parent
82b741b4fc
commit
ff976ee0ad
@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
TODO: add documentation link for the task-list in the CHANGELOG.
|
||||
TODO: tag custom ConverseJS, and update build-conversejs.sh.
|
||||
|
||||
## ??? (Not Released Yet)
|
||||
|
||||
|
@ -14,7 +14,7 @@ set -x
|
||||
CONVERSE_VERSION="v10.1.6"
|
||||
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.
|
||||
CONVERSE_COMMIT=""
|
||||
CONVERSE_COMMIT="821b41e189b25316b9a044cb41ecc9b3f1910172"
|
||||
|
||||
# 2014-01-16: we are using a custom version, to wait for some PR to be apply upstream.
|
||||
# This version includes following changes:
|
||||
|
1
conversejs/custom/plugins/tasks/constants.js
Normal file
1
conversejs/custom/plugins/tasks/constants.js
Normal file
@ -0,0 +1 @@
|
||||
export const XMLNS_TASKLIST = 'https://livingston.frama.io/peertube-plugin-livechat/protocol/tasklist'
|
@ -1,11 +1,14 @@
|
||||
import { CustomElement } from 'shared/components/element.js'
|
||||
import { api } from '@converse/headless/core'
|
||||
import tplMucTaskLists from './templates/muc-task-lists'
|
||||
import { __ } from 'i18n'
|
||||
|
||||
export default class MUCTaskListsView extends CustomElement {
|
||||
static get properties () {
|
||||
return {
|
||||
model: { type: Object, attribute: true }
|
||||
model: { type: Object, attribute: true },
|
||||
new_task_list_name: { type: String, attribute: false },
|
||||
create_tasklist_error_message: { type: String, attribute: false }
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +23,29 @@ export default class MUCTaskListsView extends CustomElement {
|
||||
}
|
||||
|
||||
render () {
|
||||
return tplMucTaskLists(this.model)
|
||||
return tplMucTaskLists(this, this.model)
|
||||
}
|
||||
|
||||
async submitCreateTaskList (ev) {
|
||||
ev.preventDefault()
|
||||
const name = ev.target.name.value.trim()
|
||||
if (this.create_tasklist_error_message) {
|
||||
this.create_tasklist_error_message = ''
|
||||
}
|
||||
|
||||
if ((name ?? '') === '') { return }
|
||||
|
||||
try {
|
||||
await this.model.createTaskList({
|
||||
name
|
||||
})
|
||||
|
||||
this.new_task_list_name = ''
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
// eslint-disable-next-line no-undef
|
||||
this.create_tasklist_error_message = __(LOC_task_list_create_error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { Collection } from '@converse/skeletor/src/collection.js'
|
||||
import { ChatRoomTaskList } from './task-list'
|
||||
import { XMLNS_TASKLIST } from './constants'
|
||||
import { initStorage } from '@converse/headless/utils/storage.js'
|
||||
import { getUniqueId } from '@converse/headless/utils/core.js'
|
||||
import { converse, api } from '@converse/headless/core'
|
||||
const { $build } = converse.env
|
||||
|
||||
/**
|
||||
* A list of {@link _converse.ChatRoomTaskList} instances, representing task lists associated to a MUC.
|
||||
@ -75,6 +78,15 @@ class ChatRoomTaskLists extends Collection {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async createTaskList (data) {
|
||||
const name = data?.name
|
||||
if (!name) { throw new Error('Missing name') }
|
||||
|
||||
const item = $build('item').c('tasklist', { xmlns: XMLNS_TASKLIST })
|
||||
item.c('name').t(name)
|
||||
await api.pubsub.publish(this.chatroom.get('jid'), 'livechat-tasks', item)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
|
@ -2,7 +2,7 @@ import { html } from 'lit'
|
||||
import { repeat } from 'lit/directives/repeat.js'
|
||||
import { __ } from 'i18n'
|
||||
|
||||
export default function tplMucTaskLists (tasklists) {
|
||||
export default function tplMucTaskLists (el, tasklists) {
|
||||
if (!tasklists) { // if user losed rights
|
||||
return html`` // FIXME: add a message like "you dont have access"?
|
||||
}
|
||||
@ -14,24 +14,17 @@ export default function tplMucTaskLists (tasklists) {
|
||||
const i18nTaskListName = __(LOC_task_list_name)
|
||||
|
||||
return html`
|
||||
<form class="converse-form" @submit=${(ev) => {
|
||||
ev.preventDefault()
|
||||
const name = ev.target.name.value.trim()
|
||||
if ((name ?? '') === '') { return }
|
||||
|
||||
ev.target.name.value = ''
|
||||
|
||||
tasklists.create({
|
||||
name
|
||||
})
|
||||
}}
|
||||
>
|
||||
<form class="converse-form" @submit=${el.submitCreateTaskList}>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
${i18nCreateTaskList}
|
||||
<input type="text" value="" name="name" placeholder="${i18nTaskListName}" />
|
||||
<input type="text" value="${el.new_task_list_name}" name="name" placeholder="${i18nTaskListName}" />
|
||||
</label>
|
||||
<input type="submit" value="${i18nAdd}" class="btn btn-primary" />
|
||||
${!el.create_tasklist_error_message
|
||||
? ''
|
||||
: html`<div class="invalid-feedback d-block">${el.create_tasklist_error_message}</div>`
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
<div class="">
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { converse, _converse, api } from '../../../src/headless/core.js'
|
||||
import { __ } from 'i18n'
|
||||
const { Strophe, $iq } = converse.env
|
||||
|
||||
export function getHeadingButtons (view, buttons) {
|
||||
const muc = view.model
|
||||
@ -38,6 +39,32 @@ function _initChatRoomTaskLists (mucModel) {
|
||||
|
||||
mucModel.tasklists = new _converse.ChatRoomTaskLists(undefined, { chatroom: mucModel })
|
||||
mucModel.tasks = new _converse.ChatRoomTasks(undefined, { chatroom: mucModel })
|
||||
|
||||
// Requesting all items.
|
||||
const stanza = $iq({
|
||||
type: 'get',
|
||||
from: _converse.bare_jid,
|
||||
to: mucModel.get('jid')
|
||||
}).c('pubsub', { xmlns: Strophe.NS.PUBSUB })
|
||||
.c('items', { node: 'livechat-tasks' })
|
||||
|
||||
api.sendIQ(stanza).then(
|
||||
(iq) => {
|
||||
console.debug('task lists: ', iq)
|
||||
},
|
||||
(iq) => {
|
||||
if (iq === null || !iq?.querySelector) {
|
||||
console.error('Failed to retrieve tasks', iq)
|
||||
return
|
||||
}
|
||||
if (!iq.querySelector('error[type="cancel"] item-not-found')) {
|
||||
console.error('Failed to retrieve tasks:', iq)
|
||||
return
|
||||
}
|
||||
// This is totally normal when you open an empty task list.
|
||||
console.log('Not livechat-tasks node for now')
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function _destroyChatRoomTaskLists (mucModel) {
|
||||
@ -55,7 +82,7 @@ export function initOrDestroyChatRoomTaskLists (mucModel) {
|
||||
}
|
||||
|
||||
if (mucModel.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
|
||||
_destroyChatRoomTaskLists(mucModel)
|
||||
return _destroyChatRoomTaskLists(mucModel)
|
||||
}
|
||||
|
||||
const myself = mucModel.getOwnOccupant()
|
||||
|
@ -18,6 +18,7 @@ const locKeys = [
|
||||
'login_external_auth_alert_message',
|
||||
'tasks',
|
||||
'task_list_create',
|
||||
'task_list_create_error',
|
||||
'task_list_name'
|
||||
]
|
||||
|
||||
|
@ -437,4 +437,5 @@ login_external_auth_alert_message: "Authentication failed"
|
||||
|
||||
tasks: 'Tasks'
|
||||
task_list_create: 'Create new task list:'
|
||||
task_list_create_error: 'Error when saving the task list'
|
||||
task_list_name: 'Task list name'
|
@ -18,6 +18,8 @@ local jid_bare = require "util.jid".bare;
|
||||
local jid_split = require "util.jid".split;
|
||||
local jid_join = require "util.jid".join;
|
||||
local cache = require "util.cache";
|
||||
local st = require "util.stanza";
|
||||
local new_id = require "util.id".medium;
|
||||
local storagemanager = require "core.storagemanager";
|
||||
|
||||
local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
|
||||
@ -225,8 +227,8 @@ function get_mep_service(room_jid, room_host)
|
||||
};
|
||||
max_items = max_max_items;
|
||||
|
||||
autocreate_on_publish = false;
|
||||
autocreate_on_subscribe = false;
|
||||
autocreate_on_publish = true;
|
||||
autocreate_on_subscribe = true;
|
||||
|
||||
nodestore = nodestore(room_jid);
|
||||
itemstore = simple_itemstore(room_jid);
|
||||
@ -234,14 +236,17 @@ function get_mep_service(room_jid, room_host)
|
||||
-- subscriber_filter = get_subscriber_filter(room_jid);
|
||||
itemcheck = is_item_stanza;
|
||||
get_affiliation = function (jid)
|
||||
-- module:log("debug", "get_affiliation call for %q", jid);
|
||||
-- First checking if there is an affiliation on the room for this JID.
|
||||
local actor_jid = jid_bare(jid);
|
||||
local room_affiliation = room:get_affiliation(actor_jid);
|
||||
-- if user is banned, don't go any further
|
||||
if (room_affiliation == "outcast") then
|
||||
-- module:log("debug", "get_affiliation for %q: outcast (existing room affiliation)", jid);
|
||||
return "outcast";
|
||||
end
|
||||
if (room_affiliation == "owner" or room_affiliation == "admin") then
|
||||
-- module:log("debug", "get_affiliation for %q: publisher (because owner or admin affiliation)", jid);
|
||||
return "publisher"; -- always publisher! (see notes at the beginning of this file)
|
||||
end
|
||||
|
||||
@ -250,11 +255,13 @@ function get_mep_service(room_jid, room_host)
|
||||
if (actor_nick ~= nil) then
|
||||
local role = room:get_role(actor_nick);
|
||||
if valid_roles[role or "none"] >= valid_roles.moderator then
|
||||
module:log("debug", "get_affiliation for %q: publisher (because of current role)", jid);
|
||||
return "publisher"; -- always publisher! (see notes at the beginning of this file)
|
||||
end
|
||||
end
|
||||
|
||||
-- no access!
|
||||
-- module:log("debug", "get_affiliation for %q: outcast", jid);
|
||||
return "outcast";
|
||||
end;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user