Task lists WIP:
* disco support
This commit is contained in:
parent
b4f4eca5ea
commit
8aa12eb575
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user