peertube-plugin-livechat/conversejs/custom/plugins/tasks/task-lists.js

49 lines
1.5 KiB
JavaScript
Raw Normal View History

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
import { Collection } from '@converse/skeletor/src/collection.js'
import { ChatRoomTaskList } from './task-list'
2024-04-30 15:11:10 +00:00
import { initStorage } from '@converse/headless/utils/storage.js'
/**
* A list of {@link _converse.exports.ChatRoomTaskList} instances, representing task lists associated to a MUC.
* @class
* @namespace _converse.exports.ChatRoomTaskLists
* @memberOf _converse
*/
class ChatRoomTaskLists extends Collection {
model = ChatRoomTaskList
2024-04-30 15:11:10 +00:00
initialize (models, options) {
2024-04-30 16:30:44 +00:00
this.model = ChatRoomTaskList // don't know why, must do it again here
2024-04-30 15:11:10 +00:00
super.initialize(arguments)
this.chatroom = options.chatroom
const id = `converse-livechat-tasks-lists-${this.chatroom.get('jid')}`
initStorage(this, id, 'session')
this.on('change:name', () => this.sort())
}
comparator (tasklist1, tasklist2) {
// Case insensitive on task list name.
const name1 = tasklist1.get('name').toLowerCase()
const name2 = tasklist2.get('name').toLowerCase()
return name1 < name2 ? -1 : name1 > name2 ? 1 : 0
}
async createTaskList (data) {
const name = data?.name
if (!name) { throw new Error('Missing name') }
2024-05-03 13:03:24 +00:00
console.log('Creating task list ' + name + '...')
2024-05-05 22:13:20 +00:00
await this.chatroom.taskManager.createItem(this, { name })
2024-05-03 13:03:24 +00:00
console.log('Task list ' + name + ' created.')
}
}
export {
ChatRoomTaskLists
}