2024-04-29 14:46:21 +00:00
|
|
|
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'
|
2024-04-29 14:46:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of {@link _converse.ChatRoomTaskList} instances, representing task lists associated to a MUC.
|
|
|
|
* @class
|
|
|
|
* @namespace _converse.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
|
|
|
|
}
|
|
|
|
|
2024-05-02 15:53:08 +00:00
|
|
|
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.')
|
2024-05-02 15:53:08 +00:00
|
|
|
}
|
2024-04-29 14:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
ChatRoomTaskLists
|
|
|
|
}
|