Move method to utils
This commit is contained in:
parent
c8304497b5
commit
8907adc236
|
@ -6,7 +6,7 @@ import tpl_muc_head from './templates/muc-head.js';
|
|||
import { Model } from '@converse/skeletor/src/model.js';
|
||||
import { __ } from 'i18n';
|
||||
import { _converse, api, converse } from "@converse/headless/core";
|
||||
import { showModeratorToolsModal } from './utils.js';
|
||||
import { destroyMUC, showModeratorToolsModal } from './utils.js';
|
||||
import {
|
||||
getHeadingDropdownItem,
|
||||
getHeadingStandaloneButton,
|
||||
|
@ -65,8 +65,9 @@ export default class MUCHeading extends ChatHeading {
|
|||
this.model.session.set('view', converse.MUC.VIEWS.CONFIG);
|
||||
}
|
||||
|
||||
destroy () {
|
||||
_converse.chatboxviews.get(this.getAttribute('jid'))?.destroy();
|
||||
destroy (ev) {
|
||||
ev.preventDefault();
|
||||
destroyMUC(this.model);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,7 +188,6 @@ export default class MUCHeading extends ChatHeading {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
api.elements.define('converse-muc-heading', MUCHeading);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import BaseChatView from 'shared/chat/baseview.js';
|
||||
import log from '@converse/headless/log';
|
||||
import tpl_muc from './templates/muc.js';
|
||||
import { __ } from 'i18n';
|
||||
import { _converse, api, converse } from '@converse/headless/core';
|
||||
|
||||
|
||||
|
@ -40,37 +38,6 @@ export default class MUCView extends BaseChatView {
|
|||
return tpl_muc({ 'model': this.model });
|
||||
}
|
||||
|
||||
async destroy () {
|
||||
const messages = [__('Are you sure you want to destroy this groupchat?')];
|
||||
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')
|
||||
}
|
||||
];
|
||||
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;
|
||||
return this.model.sendDestroyIQ(reason, newjid).then(() => this.close());
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
onConnectionStatusChanged () {
|
||||
const conn_status = this.model.session.get('connection_status');
|
||||
if (conn_status === converse.ROOMSTATUS.CONNECTING) {
|
||||
|
|
|
@ -31,6 +31,38 @@ export function clearHistory (jid) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function destroyMUC (model) {
|
||||
const messages = [__('Are you sure you want to destroy this groupchat?')];
|
||||
let fields = [
|
||||
{
|
||||
'name': 'challenge',
|
||||
'label': __('Please enter the XMPP address of this groupchat to confirm'),
|
||||
'challenge': 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')
|
||||
}
|
||||
];
|
||||
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;
|
||||
return model.sendDestroyIQ(reason, newjid).then(() => model.close());
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setMUCDomain (domain, controlboxview) {
|
||||
controlboxview.querySelector('converse-rooms-list')
|
||||
.model.save('muc_domain', Strophe.getDomainFromJid(domain));
|
||||
|
@ -305,8 +337,7 @@ export function parseMessageForMUCCommands (muc, text) {
|
|||
if (!muc.verifyAffiliations(['owner'])) {
|
||||
break;
|
||||
}
|
||||
const chatview = _converse.chatboxviews.get(muc.get('jid'));
|
||||
chatview.destroy().catch(e => muc.onCommandError(e));
|
||||
destroyMUC(muc).catch(e => muc.onCommandError(e));
|
||||
break;
|
||||
}
|
||||
case 'help': {
|
||||
|
|
Loading…
Reference in New Issue
Block a user