2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-07-11 15:53:50 +00:00
|
|
|
import { _converse, converse } from '../../../src/headless/index.js'
|
2024-04-29 14:46:21 +00:00
|
|
|
import { ChatRoomTaskLists } from './task-lists.js'
|
|
|
|
import { ChatRoomTaskList } from './task-list.js'
|
2024-04-30 16:30:44 +00:00
|
|
|
import { ChatRoomTasks } from './tasks.js'
|
2024-05-12 16:45:51 +00:00
|
|
|
import { getHeadingButtons, getMessageActionButtons, initOrDestroyChatRoomTaskLists } from './utils.js'
|
2024-05-10 09:33:41 +00:00
|
|
|
import { XMLNS_TASK, XMLNS_TASKLIST } from './constants.js'
|
2024-05-13 10:31:28 +00:00
|
|
|
import './components/muc-task-view.js'
|
|
|
|
import './components/muc-task-list-view.js'
|
|
|
|
import './components/muc-task-lists-view.js'
|
|
|
|
import './components/muc-task-app-view.js'
|
|
|
|
import './modals/pick-task-list.js'
|
2024-05-03 17:28:26 +00:00
|
|
|
|
2024-04-29 14:46:21 +00:00
|
|
|
converse.plugins.add('livechat-converse-tasks', {
|
2024-05-12 09:59:59 +00:00
|
|
|
dependencies: ['converse-muc', 'converse-disco', 'converse-pubsub'],
|
2024-04-29 14:46:21 +00:00
|
|
|
|
|
|
|
initialize () {
|
2024-07-15 15:46:45 +00:00
|
|
|
Object.assign(
|
|
|
|
_converse.exports,
|
|
|
|
{
|
|
|
|
ChatRoomTaskLists,
|
|
|
|
ChatRoomTaskList,
|
|
|
|
ChatRoomTasks
|
|
|
|
}
|
|
|
|
)
|
2024-04-29 14:46:21 +00:00
|
|
|
|
2024-05-11 15:37:20 +00:00
|
|
|
_converse.api.settings.extend({
|
2024-05-12 14:02:13 +00:00
|
|
|
livechat_task_app_enabled: false,
|
|
|
|
livechat_task_app_restore: false // should we open the app by default if it was previously oppened?
|
2024-05-11 15:37:20 +00:00
|
|
|
})
|
|
|
|
|
2024-04-30 15:11:10 +00:00
|
|
|
_converse.api.listen.on('chatRoomInitialized', muc => {
|
|
|
|
muc.session.on('change:connection_status', _session => {
|
|
|
|
// When joining a room, initializing the TaskLists object (if user has access),
|
|
|
|
// When disconnected from a room, destroying the Tasklists object:
|
|
|
|
initOrDestroyChatRoomTaskLists(muc)
|
|
|
|
})
|
|
|
|
|
2024-05-10 09:33:41 +00:00
|
|
|
// When the current user affiliation changes, we must also delete or initialize the TaskLists object:
|
2024-05-09 16:17:51 +00:00
|
|
|
muc.occupants.on('change:affiliation', occupant => {
|
2024-04-30 15:11:10 +00:00
|
|
|
if (occupant.get('jid') !== _converse.bare_jid) { // only for myself
|
|
|
|
return
|
|
|
|
}
|
|
|
|
initOrDestroyChatRoomTaskLists(muc)
|
|
|
|
})
|
2024-05-10 09:33:41 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
})
|
2024-04-30 15:11:10 +00:00
|
|
|
})
|
|
|
|
|
2024-04-30 07:21:18 +00:00
|
|
|
// adding the "Tasks" button in the MUC heading buttons:
|
2024-04-29 14:46:21 +00:00
|
|
|
_converse.api.listen.on('getHeadingButtons', getHeadingButtons)
|
2024-05-12 16:45:51 +00:00
|
|
|
|
|
|
|
// Adding buttons on message:
|
|
|
|
_converse.api.listen.on('getMessageActionButtons', getMessageActionButtons)
|
2024-04-29 14:46:21 +00:00
|
|
|
}
|
|
|
|
})
|