2021-02-11 15:05:04 +01:00
|
|
|
import BaseChatView from 'shared/chat/baseview.js';
|
2021-02-11 11:43:02 +01:00
|
|
|
import tpl_muc from './templates/muc.js';
|
2020-12-06 20:42:12 +01:00
|
|
|
import { _converse, api, converse } from '@converse/headless/core';
|
2021-05-07 10:14:33 +02:00
|
|
|
|
2019-07-04 14:12:12 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
export default class MUCView extends BaseChatView {
|
|
|
|
length = 300
|
|
|
|
is_chatroom = true
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2021-06-04 21:42:22 +02:00
|
|
|
async initialize () {
|
2021-06-04 15:21:39 +02:00
|
|
|
this.model = await api.rooms.get(this.jid);
|
|
|
|
_converse.chatboxviews.add(this.jid, this);
|
2021-05-07 10:14:33 +02:00
|
|
|
this.setAttribute('id', this.model.get('box_id'));
|
|
|
|
|
2021-02-10 11:44:04 +01:00
|
|
|
this.listenTo(_converse, 'windowStateChanged', this.onWindowStateChanged);
|
2021-06-04 15:21:39 +02:00
|
|
|
this.listenTo(this.model, 'change:composing_spoiler', this.requestUpdateMessageForm);
|
2021-06-15 09:44:20 +02:00
|
|
|
this.listenTo(this.model.session, 'change:connection_status', this.onConnectionStatusChanged);
|
2021-06-04 15:21:39 +02:00
|
|
|
this.listenTo(this.model.session, 'change:view', this.requestUpdate);
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2021-06-15 09:44:20 +02:00
|
|
|
this.onConnectionStatusChanged();
|
2020-09-09 14:37:43 +02:00
|
|
|
this.model.maybeShow();
|
|
|
|
/**
|
2021-09-09 16:20:33 +02:00
|
|
|
* Triggered once a {@link _converse.ChatRoomView} has been opened
|
2020-09-09 14:37:43 +02:00
|
|
|
* @event _converse#chatRoomViewInitialized
|
|
|
|
* @type { _converse.ChatRoomView }
|
|
|
|
* @example _converse.api.listen.on('chatRoomViewInitialized', view => { ... });
|
|
|
|
*/
|
|
|
|
api.trigger('chatRoomViewInitialized', this);
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2019-10-11 20:29:12 +02:00
|
|
|
|
2021-02-11 22:32:55 +01:00
|
|
|
render () {
|
2021-06-04 21:42:22 +02:00
|
|
|
return tpl_muc({ 'model': this.model });
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2019-05-24 20:50:30 +02:00
|
|
|
|
2021-06-15 09:44:20 +02:00
|
|
|
onConnectionStatusChanged () {
|
2020-12-06 20:42:12 +01:00
|
|
|
const conn_status = this.model.session.get('connection_status');
|
2021-03-13 11:37:07 +01:00
|
|
|
if (conn_status === converse.ROOMSTATUS.CONNECTING) {
|
2021-05-13 15:45:12 +02:00
|
|
|
this.model.session.save({
|
2021-03-13 11:37:07 +01:00
|
|
|
'disconnection_actor': undefined,
|
|
|
|
'disconnection_message': undefined,
|
|
|
|
'disconnection_reason': undefined,
|
2021-05-13 15:45:12 +02:00
|
|
|
});
|
|
|
|
this.model.save({
|
2021-03-13 11:37:07 +01:00
|
|
|
'moved_jid': undefined,
|
|
|
|
'password_validation_message': undefined,
|
|
|
|
'reason': undefined,
|
|
|
|
});
|
2020-09-09 14:37:43 +02:00
|
|
|
}
|
2021-06-04 15:21:39 +02:00
|
|
|
this.requestUpdate();
|
2020-09-09 14:37:43 +02:00
|
|
|
}
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
api.elements.define('converse-muc', MUCView);
|