diff --git a/conversejs/custom/plugins/tasks/index.js b/conversejs/custom/plugins/tasks/index.js index 1521393a..4d8b2c1a 100644 --- a/conversejs/custom/plugins/tasks/index.js +++ b/conversejs/custom/plugins/tasks/index.js @@ -3,6 +3,7 @@ import { ChatRoomTaskLists } from './task-lists.js' import { ChatRoomTaskList } from './task-list.js' import { ChatRoomTasks } from './tasks.js' import { getHeadingButtons, initOrDestroyChatRoomTaskLists } from './utils.js' +import { XMLNS_TASK, XMLNS_TASKLIST } from './constants.js' import './muc-task-view.js' // FIXME: here or in another file? import './muc-task-list-view.js' // FIXME: here or in another file? import './muc-task-lists-view.js' // FIXME: here or in another file? @@ -25,13 +26,21 @@ converse.plugins.add('livechat-converse-tasks', { initOrDestroyChatRoomTaskLists(muc) }) - // When the current user affiliation changes, we must also delete or initiliaze the TaskLists object: + // When the current user affiliation changes, we must also delete or initialize the TaskLists object: muc.occupants.on('change:affiliation', occupant => { if (occupant.get('jid') !== _converse.bare_jid) { // only for myself return } initOrDestroyChatRoomTaskLists(muc) }) + + // To be sure that everything works in any case, we also must listen for addition in muc.features. + muc.features.on('change:' + XMLNS_TASK, () => { + initOrDestroyChatRoomTaskLists(muc) + }) + muc.features.on('change:' + XMLNS_TASKLIST, () => { + initOrDestroyChatRoomTaskLists(muc) + }) }) // adding the "Tasks" button in the MUC heading buttons: diff --git a/conversejs/custom/plugins/tasks/utils.js b/conversejs/custom/plugins/tasks/utils.js index 5c5929ea..bdd1cea5 100644 --- a/conversejs/custom/plugins/tasks/utils.js +++ b/conversejs/custom/plugins/tasks/utils.js @@ -14,9 +14,6 @@ export function getHeadingButtons (view, buttons) { return buttons } - // TODO: use disco to discover the feature. - // (if the chat is remote, the server could use a livechat version that does not support this feature) - // Adding a "Open task list" button. buttons.unshift({ // eslint-disable-next-line no-undef @@ -96,6 +93,12 @@ export function initOrDestroyChatRoomTaskLists (mucModel) { return _destroyChatRoomTaskLists(mucModel) } + // We must check disco features + // (if the chat is remote, the server could use a livechat version that does not support this feature) + if (!mucModel.features?.get?.(XMLNS_TASKLIST) || !mucModel.features?.get?.(XMLNS_TASK)) { + return _destroyChatRoomTaskLists(mucModel) + } + const myself = mucModel.getOwnOccupant() if (!myself || !['admin', 'owner'].includes(myself.get('affiliation'))) { // User must be admin or owner diff --git a/prosody-modules/mod_pubsub_peertubelivechat/mod_pubsub_peertubelivechat.lua b/prosody-modules/mod_pubsub_peertubelivechat/mod_pubsub_peertubelivechat.lua index d338db7e..958a0c1f 100644 --- a/prosody-modules/mod_pubsub_peertubelivechat/mod_pubsub_peertubelivechat.lua +++ b/prosody-modules/mod_pubsub_peertubelivechat/mod_pubsub_peertubelivechat.lua @@ -17,8 +17,6 @@ -- * unsubscribing users that have left the room (the front-end will subscribe again when needed) -- * unsubscribing users when losing their affiliation --- TODO: add disco support. - local pubsub = require "util.pubsub"; local jid_bare = require "util.jid".bare; local jid_split = require "util.jid".split; @@ -379,3 +377,9 @@ module:hook("muc-occupant-left", function (event) end; end end); + +-- Discovering support +module:hook("muc-disco#info", function (event) + event.reply:tag("feature", { var = xmlns_task }):up(); + event.reply:tag("feature", { var = xmlns_tasklist }):up(); +end);