2021-02-11 15:05:04 +01:00
|
|
|
import BaseChatView from 'shared/chat/baseview.js';
|
2020-12-06 20:42:12 +01:00
|
|
|
import log from '@converse/headless/log';
|
2021-02-11 11:43:02 +01:00
|
|
|
import tpl_muc from './templates/muc.js';
|
2020-12-06 20:42:12 +01:00
|
|
|
import { __ } from 'i18n';
|
|
|
|
import { _converse, api, converse } from '@converse/headless/core';
|
2021-05-07 10:14:33 +02:00
|
|
|
import { render } from "lit";
|
|
|
|
|
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
|
|
|
|
2020-09-09 14:37:43 +02:00
|
|
|
async initialize () {
|
2020-12-08 12:54:14 +01:00
|
|
|
const jid = this.getAttribute('jid');
|
2021-04-19 15:23:58 +02:00
|
|
|
this.model = await api.rooms.get(jid);
|
2021-04-08 10:17:26 +02:00
|
|
|
_converse.chatboxviews.add(jid, this);
|
2020-09-09 14:37:43 +02:00
|
|
|
this.initDebounced();
|
|
|
|
|
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);
|
2020-09-09 14:37:43 +02:00
|
|
|
this.listenTo(this.model, 'change:composing_spoiler', this.renderMessageForm);
|
2021-01-25 22:04:01 +01:00
|
|
|
this.listenTo(this.model, 'change:hidden', () => this.afterShown());
|
2021-02-10 11:44:04 +01:00
|
|
|
this.listenTo(this.model, 'change:minimized', () => this.afterShown());
|
2020-09-09 14:37:43 +02:00
|
|
|
this.listenTo(this.model, 'show', this.show);
|
2021-03-13 11:37:07 +01:00
|
|
|
this.listenTo(this.model.session, 'change:connection_status', this.updateAfterTransition);
|
|
|
|
this.listenTo(this.model.session, 'change:view', this.render);
|
2020-09-09 14:37:43 +02:00
|
|
|
|
|
|
|
await this.render();
|
|
|
|
|
|
|
|
// Need to be registered after render has been called.
|
|
|
|
this.listenTo(this.model.messages, 'add', this.onMessageAdded);
|
|
|
|
this.listenTo(this.model.occupants, 'change:show', this.showJoinOrLeaveNotification);
|
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
this.updateAfterTransition();
|
2020-09-09 14:37:43 +02:00
|
|
|
this.model.maybeShow();
|
2020-10-28 13:02:12 +01:00
|
|
|
this.scrollDown();
|
2020-09-09 14:37:43 +02:00
|
|
|
/**
|
|
|
|
* Triggered once a { @link _converse.ChatRoomView } has been opened
|
|
|
|
* @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-05-07 10:14:33 +02:00
|
|
|
render(tpl_muc({ 'model': this.model }), this);
|
2020-09-09 14:37:43 +02:00
|
|
|
!this.model.get('hidden') && this.show();
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2019-05-24 20:50:30 +02:00
|
|
|
|
2020-09-09 14:37:43 +02:00
|
|
|
/**
|
|
|
|
* Callback method that gets called after the chat has become visible.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#afterShown
|
|
|
|
*/
|
|
|
|
afterShown () {
|
2021-01-25 22:04:01 +01:00
|
|
|
if (!this.model.get('hidden') && !this.model.get('minimized')) {
|
|
|
|
this.model.clearUnreadMsgCounter();
|
|
|
|
this.scrollDown();
|
|
|
|
}
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-02-10 11:23:55 +01:00
|
|
|
|
2020-09-09 14:37:43 +02:00
|
|
|
/**
|
2021-05-07 10:14:33 +02:00
|
|
|
* Closes this chat, which implies leaving the MUC as well.
|
2020-09-09 14:37:43 +02:00
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#close
|
|
|
|
*/
|
2021-05-07 10:14:33 +02:00
|
|
|
close (ev) {
|
2020-12-06 20:42:12 +01:00
|
|
|
if (_converse.router.history.getFragment() === 'converse/room?jid=' + this.model.get('jid')) {
|
2020-09-09 14:37:43 +02:00
|
|
|
_converse.router.navigate('');
|
|
|
|
}
|
2021-05-07 10:14:33 +02:00
|
|
|
return super.close(ev);
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2020-09-09 14:37:43 +02:00
|
|
|
async destroy () {
|
|
|
|
const messages = [__('Are you sure you want to destroy this groupchat?')];
|
2020-12-06 20:42:12 +01:00
|
|
|
let fields = [
|
|
|
|
{
|
|
|
|
'name': 'challenge',
|
|
|
|
'label': __('Please enter the XMPP address of this groupchat to confirm'),
|
|
|
|
'challenge': this.model.get('jid'),
|
|
|
|
'placeholder': __('name@example.org'),
|
|
|
|
'required': true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'reason',
|
|
|
|
'label': __('Optional reason for destroying this groupchat'),
|
|
|
|
'placeholder': __('Reason')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'newjid',
|
|
|
|
'label': __('Optional XMPP address for a new groupchat that replaces this one'),
|
|
|
|
'placeholder': __('replacement@example.org')
|
|
|
|
}
|
|
|
|
];
|
2020-09-09 14:37:43 +02:00
|
|
|
try {
|
|
|
|
fields = await api.confirm(__('Confirm'), messages, fields);
|
|
|
|
const reason = fields.filter(f => f.name === 'reason').pop()?.value;
|
|
|
|
const newjid = fields.filter(f => f.name === 'newjid').pop()?.value;
|
2020-12-06 20:42:12 +01:00
|
|
|
return this.model.sendDestroyIQ(reason, newjid).then(() => this.close());
|
2020-09-09 14:37:43 +02:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
}
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2018-08-09 13:07:32 +02:00
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
updateAfterTransition () {
|
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-03-13 11:37:07 +01:00
|
|
|
this.render();
|
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);
|