(service: BaseMultiChatsService)
| 126 | } |
| 127 | |
| 128 | async loadService(service: BaseMultiChatsService) { |
| 129 | if (!(service instanceof BaseMultiChatsService)) |
| 130 | throw new Error('MultiChatsView can only be used with MultiChatsService'); |
| 131 | // Changing service should reset selected item. |
| 132 | if (this.service && this.service != service) { |
| 133 | this.#selectedIndex = null; |
| 134 | this.#selectedItem = null; |
| 135 | } |
| 136 | if (!await super.loadService(service)) |
| 137 | return false; |
| 138 | |
| 139 | // Load existing chats. |
| 140 | if (this.service.chats.length == 0) |
| 141 | this.service.createChat(); |
| 142 | for (const chat of service.chats) { |
| 143 | const item = this.#createItemForChat(chat); |
| 144 | this.items.push(item); |
| 145 | this.#chatList.addChildView(item.view); |
| 146 | } |
| 147 | // Restore selected item, the index is read in restoreState. |
| 148 | this.items[this.#selectedIndex ?? 0]?.setSelected(true); |
| 149 | // Listen to events of service. |
| 150 | this.serviceConnections.add(service.onNewChat.connect(this.#onNewChat.bind(this))); |
| 151 | this.serviceConnections.add(service.onRemoveChat.connect(this.#onRemoveChat.bind(this))); |
| 152 | this.serviceConnections.add(service.onClearChats.connect(this.#onClearChats.bind(this))); |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | unload() { |
| 157 | super.unload(); |
no test coverage detected