2019-07-11 10:48:52 +02:00
|
|
|
/**
|
|
|
|
* @module converse-muc-views
|
2020-01-26 16:21:20 +01:00
|
|
|
* @copyright 2020, the Converse.js contributors
|
2019-09-11 15:23:58 +02:00
|
|
|
* @description XEP-0045 Multi-User Chat Views
|
|
|
|
* @license Mozilla Public License (MPLv2)
|
2019-07-11 10:48:52 +02:00
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
import "converse-modal";
|
2019-10-09 16:01:38 +02:00
|
|
|
import "@converse/headless/utils/muc";
|
2019-09-19 16:54:55 +02:00
|
|
|
import { Model } from 'skeletor.js/src/model.js';
|
2020-02-07 14:58:26 +01:00
|
|
|
import { View } from 'skeletor.js/src/view.js';
|
2020-04-06 14:27:44 +02:00
|
|
|
import { debounce, head, isString, isUndefined } from "lodash";
|
2020-03-06 11:41:16 +01:00
|
|
|
import { BootstrapModal } from "./converse-modal.js";
|
2020-02-10 11:23:55 +01:00
|
|
|
import { render } from "lit-html";
|
2020-01-26 17:55:24 +01:00
|
|
|
import { __ } from '@converse/headless/i18n';
|
2020-04-15 13:59:55 +02:00
|
|
|
import RoomDetailsModal from 'modals/muc-details.js';
|
2018-10-23 03:41:38 +02:00
|
|
|
import converse from "@converse/headless/converse-core";
|
2019-11-06 11:01:34 +01:00
|
|
|
import log from "@converse/headless/log";
|
2020-04-15 11:25:37 +02:00
|
|
|
import st from "@converse/headless/utils/stanza";
|
2020-01-23 10:18:41 +01:00
|
|
|
import tpl_add_chatroom_modal from "templates/add_chatroom_modal.js";
|
2020-03-18 16:55:32 +01:00
|
|
|
import tpl_chatroom from "templates/chatroom.js";
|
2019-04-10 23:25:14 +02:00
|
|
|
import tpl_chatroom_bottom_panel from "templates/chatroom_bottom_panel.html";
|
2018-10-23 03:41:38 +02:00
|
|
|
import tpl_chatroom_destroyed from "templates/chatroom_destroyed.html";
|
|
|
|
import tpl_chatroom_disconnect from "templates/chatroom_disconnect.html";
|
2020-02-07 14:58:26 +01:00
|
|
|
import tpl_chatroom_head from "templates/chatroom_head.js";
|
2019-11-28 17:01:08 +01:00
|
|
|
import tpl_chatroom_nickname_form from "templates/chatroom_nickname_form.html";
|
2018-10-23 03:41:38 +02:00
|
|
|
import tpl_info from "templates/info.html";
|
2020-01-23 10:18:41 +01:00
|
|
|
import tpl_list_chatrooms_modal from "templates/list_chatrooms_modal.js";
|
|
|
|
import tpl_moderator_tools_modal from "templates/moderator_tools_modal.js";
|
2020-04-15 11:25:37 +02:00
|
|
|
import tpl_muc_config_form from "templates/muc_config_form.js";
|
|
|
|
import tpl_muc_invite_modal from "templates/muc_invite_modal.js";
|
|
|
|
import tpl_muc_password_form from "templates/muc_password_form.js";
|
|
|
|
import tpl_muc_sidebar from "templates/muc_sidebar.js";
|
2018-10-23 03:41:38 +02:00
|
|
|
import tpl_room_description from "templates/room_description.html";
|
|
|
|
import tpl_room_panel from "templates/room_panel.html";
|
|
|
|
import tpl_spinner from "templates/spinner.html";
|
2019-05-13 18:50:25 +02:00
|
|
|
import xss from "xss/dist/xss";
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2020-01-26 18:36:25 +01:00
|
|
|
const { Strophe, sizzle, $iq, $pres } = converse.env;
|
2018-10-23 03:41:38 +02:00
|
|
|
const u = converse.env.utils;
|
2019-07-04 14:12:12 +02:00
|
|
|
|
|
|
|
const ROLES = ['moderator', 'participant', 'visitor'];
|
2020-02-22 21:12:40 +01:00
|
|
|
const AFFILIATIONS = ['owner', 'admin', 'member', 'outcast', 'none'];
|
2019-04-25 10:34:17 +02:00
|
|
|
const OWNER_COMMANDS = ['owner'];
|
2019-09-07 23:41:48 +02:00
|
|
|
const ADMIN_COMMANDS = ['admin', 'ban', 'deop', 'destroy', 'member', 'op', 'revoke'];
|
|
|
|
const MODERATOR_COMMANDS = ['kick', 'mute', 'voice', 'modtools'];
|
2019-04-25 10:34:17 +02:00
|
|
|
const VISITOR_COMMANDS = ['nick'];
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2019-05-26 17:53:32 +02:00
|
|
|
const COMMAND_TO_ROLE = {
|
|
|
|
'deop': 'participant',
|
|
|
|
'kick': 'none',
|
|
|
|
'mute': 'visitor',
|
|
|
|
'op': 'moderator',
|
|
|
|
'voice': 'participant'
|
|
|
|
}
|
|
|
|
const COMMAND_TO_AFFILIATION = {
|
|
|
|
'admin': 'admin',
|
|
|
|
'ban': 'outcast',
|
|
|
|
'member': 'member',
|
|
|
|
'owner': 'owner',
|
|
|
|
'revoke': 'none'
|
|
|
|
}
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
converse.plugins.add('converse-muc-views', {
|
|
|
|
/* Dependencies are other plugins which might be
|
|
|
|
* overridden or relied upon, and therefore need to be loaded before
|
|
|
|
* this plugin. They are "optional" because they might not be
|
|
|
|
* available, in which case any overrides applicable to them will be
|
|
|
|
* ignored.
|
|
|
|
*
|
|
|
|
* NB: These plugins need to have already been loaded via require.js.
|
|
|
|
*
|
|
|
|
* It's possible to make these dependencies "non-optional".
|
|
|
|
* If the setting "strict_plugin_dependencies" is set to true,
|
|
|
|
* an error will be raised if the plugin is not found.
|
|
|
|
*/
|
|
|
|
dependencies: ["converse-autocomplete", "converse-modal", "converse-controlbox", "converse-chatview"],
|
|
|
|
|
|
|
|
overrides: {
|
|
|
|
ControlBoxView: {
|
|
|
|
renderControlBoxPane () {
|
|
|
|
const { _converse } = this.__super__;
|
|
|
|
this.__super__.renderControlBoxPane.apply(this, arguments);
|
|
|
|
if (_converse.allow_muc) {
|
|
|
|
this.renderRoomsPanel();
|
|
|
|
}
|
2019-05-24 13:52:15 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize () {
|
2020-01-26 17:55:24 +01:00
|
|
|
const { _converse } = this;
|
2020-03-31 13:15:57 +02:00
|
|
|
const { api } = _converse;
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.promises.add(['roomsPanelRendered']);
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
|
|
// Configuration values for this plugin
|
|
|
|
// ====================================
|
|
|
|
// Refer to docs/source/configuration.rst for explanations of these
|
|
|
|
// configuration settings.
|
2020-03-31 13:15:57 +02:00
|
|
|
api.settings.update({
|
2018-10-23 03:41:38 +02:00
|
|
|
'auto_list_rooms': false,
|
2019-04-17 11:52:41 +02:00
|
|
|
'cache_muc_messages': true,
|
|
|
|
'locked_muc_nickname': false,
|
2020-02-22 21:12:40 +01:00
|
|
|
'modtools_disable_query': [],
|
|
|
|
'modtools_disable_assign': false,
|
2019-04-25 10:59:16 +02:00
|
|
|
'muc_disable_slash_commands': false,
|
2019-11-11 15:27:34 +01:00
|
|
|
'muc_mention_autocomplete_filter': 'contains',
|
2020-02-22 21:12:40 +01:00
|
|
|
'muc_mention_autocomplete_min_chars': 0,
|
2019-11-11 15:27:34 +01:00
|
|
|
'muc_mention_autocomplete_show_avatar': true,
|
2019-12-30 13:23:52 +01:00
|
|
|
'muc_roomid_policy': null,
|
|
|
|
'muc_roomid_policy_hint': null,
|
2020-02-22 21:12:40 +01:00
|
|
|
'roomconfig_whitelist': [],
|
|
|
|
'show_retraction_warning': true,
|
2018-10-23 03:41:38 +02:00
|
|
|
'visible_toolbar_buttons': {
|
|
|
|
'toggle_occupants': true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-24 13:52:15 +02:00
|
|
|
|
2019-09-11 11:28:28 +02:00
|
|
|
const viewWithRoomsPanel = {
|
|
|
|
renderRoomsPanel () {
|
|
|
|
if (this.roomspanel && u.isInDOM(this.roomspanel.el)) {
|
|
|
|
return this.roomspanel;
|
|
|
|
}
|
2019-10-11 20:29:12 +02:00
|
|
|
const id = `converse.roomspanel${_converse.bare_jid}`;
|
|
|
|
|
2019-09-11 11:28:28 +02:00
|
|
|
this.roomspanel = new _converse.RoomsPanel({
|
|
|
|
'model': new (_converse.RoomsPanelModel.extend({
|
2019-10-11 20:29:12 +02:00
|
|
|
id,
|
2019-12-17 13:39:32 +01:00
|
|
|
'browserStorage': _converse.createStore(id)
|
2019-09-11 11:28:28 +02:00
|
|
|
}))()
|
|
|
|
});
|
|
|
|
this.roomspanel.model.fetch();
|
|
|
|
this.el.querySelector('.controlbox-pane').insertAdjacentElement(
|
|
|
|
'beforeEnd', this.roomspanel.render().el);
|
2019-05-24 20:50:30 +02:00
|
|
|
|
2019-09-11 11:28:28 +02:00
|
|
|
/**
|
2020-01-30 19:37:00 +01:00
|
|
|
* Triggered once the section of the { @link _converse.ControlBoxView }
|
2019-09-11 11:28:28 +02:00
|
|
|
* which shows gropuchats has been rendered.
|
|
|
|
* @event _converse#roomsPanelRendered
|
|
|
|
* @example _converse.api.listen.on('roomsPanelRendered', () => { ... });
|
|
|
|
*/
|
2020-03-31 13:15:57 +02:00
|
|
|
api.trigger('roomsPanelRendered');
|
2019-09-11 11:28:28 +02:00
|
|
|
return this.roomspanel;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRoomsPanel () {
|
|
|
|
if (this.roomspanel && u.isInDOM(this.roomspanel.el)) {
|
|
|
|
return this.roomspanel;
|
|
|
|
} else {
|
|
|
|
return this.renderRoomsPanel();
|
|
|
|
}
|
|
|
|
}
|
2019-05-24 20:50:30 +02:00
|
|
|
}
|
2019-09-11 11:28:28 +02:00
|
|
|
|
2019-05-24 20:50:30 +02:00
|
|
|
if (_converse.ControlBoxView) {
|
2019-09-11 11:28:28 +02:00
|
|
|
Object.assign(_converse.ControlBoxView.prototype, viewWithRoomsPanel);
|
2019-05-24 20:50:30 +02:00
|
|
|
}
|
2019-05-24 13:52:15 +02:00
|
|
|
|
2019-03-29 23:47:56 +01:00
|
|
|
/* Insert groupchat info (based on returned #disco IQ stanza)
|
|
|
|
* @function insertRoomInfo
|
|
|
|
* @param { HTMLElement } el - The HTML DOM element that contains the info.
|
|
|
|
* @param { XMLElement } stanza - The IQ stanza containing the groupchat info.
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
function insertRoomInfo (el, stanza) {
|
2019-03-04 17:49:44 +01:00
|
|
|
// All MUC features found here: https://xmpp.org/registrar/disco-features.html
|
2018-10-23 03:41:38 +02:00
|
|
|
el.querySelector('span.spinner').remove();
|
|
|
|
el.querySelector('a.room-info').classList.add('selected');
|
|
|
|
el.insertAdjacentHTML(
|
|
|
|
'beforeEnd',
|
|
|
|
tpl_room_description({
|
|
|
|
'jid': stanza.getAttribute('from'),
|
2020-03-24 12:26:34 +01:00
|
|
|
'desc': head(sizzle('field[var="muc#roominfo_description"] value', stanza))?.textContent,
|
|
|
|
'occ': head(sizzle('field[var="muc#roominfo_occupants"] value', stanza))?.textContent,
|
2018-10-23 03:41:38 +02:00
|
|
|
'hidden': sizzle('feature[var="muc_hidden"]', stanza).length,
|
|
|
|
'membersonly': sizzle('feature[var="muc_membersonly"]', stanza).length,
|
|
|
|
'moderated': sizzle('feature[var="muc_moderated"]', stanza).length,
|
|
|
|
'nonanonymous': sizzle('feature[var="muc_nonanonymous"]', stanza).length,
|
|
|
|
'open': sizzle('feature[var="muc_open"]', stanza).length,
|
|
|
|
'passwordprotected': sizzle('feature[var="muc_passwordprotected"]', stanza).length,
|
|
|
|
'persistent': sizzle('feature[var="muc_persistent"]', stanza).length,
|
|
|
|
'publicroom': sizzle('feature[var="muc_publicroom"]', stanza).length,
|
|
|
|
'semianonymous': sizzle('feature[var="muc_semianonymous"]', stanza).length,
|
|
|
|
'temporary': sizzle('feature[var="muc_temporary"]', stanza).length,
|
|
|
|
'unmoderated': sizzle('feature[var="muc_unmoderated"]', stanza).length,
|
|
|
|
'label_desc': __('Description:'),
|
|
|
|
'label_jid': __('Groupchat Address (JID):'),
|
|
|
|
'label_occ': __('Participants:'),
|
|
|
|
'label_features': __('Features:'),
|
|
|
|
'label_requires_auth': __('Requires authentication'),
|
|
|
|
'label_hidden': __('Hidden'),
|
|
|
|
'label_requires_invite': __('Requires an invitation'),
|
|
|
|
'label_moderated': __('Moderated'),
|
|
|
|
'label_non_anon': __('Non-anonymous'),
|
|
|
|
'label_open_room': __('Open'),
|
|
|
|
'label_permanent_room': __('Permanent'),
|
|
|
|
'label_public': __('Public'),
|
|
|
|
'label_semi_anon': __('Semi-anonymous'),
|
|
|
|
'label_temp_room': __('Temporary'),
|
|
|
|
'label_unmoderated': __('Unmoderated')
|
|
|
|
}));
|
|
|
|
}
|
2018-02-22 17:39:44 +01:00
|
|
|
|
2019-09-07 22:00:28 +02:00
|
|
|
/**
|
|
|
|
* Show/hide extra information about a groupchat in a listing.
|
|
|
|
* @function toggleRoomInfo
|
|
|
|
* @param { Event }
|
|
|
|
*/
|
2018-10-25 22:42:38 +02:00
|
|
|
function toggleRoomInfo (ev) {
|
2019-09-07 22:00:28 +02:00
|
|
|
const parent_el = u.ancestor(ev.target, '.room-item');
|
|
|
|
const div_el = parent_el.querySelector('div.room-info');
|
2018-10-23 03:41:38 +02:00
|
|
|
if (div_el) {
|
2018-10-25 22:42:38 +02:00
|
|
|
u.slideIn(div_el).then(u.removeElement)
|
2018-10-23 03:41:38 +02:00
|
|
|
parent_el.querySelector('a.room-info').classList.remove('selected');
|
|
|
|
} else {
|
|
|
|
parent_el.insertAdjacentHTML('beforeend', tpl_spinner());
|
2020-03-31 13:15:57 +02:00
|
|
|
api.disco.info(ev.target.getAttribute('data-room-jid'), null)
|
2018-10-25 22:42:38 +02:00
|
|
|
.then(stanza => insertRoomInfo(parent_el, stanza))
|
2019-11-06 11:01:34 +01:00
|
|
|
.catch(e => log.error(e));
|
2018-02-22 17:39:44 +01:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2018-02-22 17:39:44 +01:00
|
|
|
|
2018-09-12 15:06:08 +02:00
|
|
|
|
2020-03-06 11:41:16 +01:00
|
|
|
_converse.ModeratorToolsModal = BootstrapModal.extend({
|
2020-01-23 10:18:41 +01:00
|
|
|
id: "converse-modtools-modal",
|
2019-07-04 14:12:12 +02:00
|
|
|
|
|
|
|
initialize (attrs) {
|
|
|
|
this.chatroomview = attrs.chatroomview;
|
2020-03-06 11:41:16 +01:00
|
|
|
BootstrapModal.prototype.initialize.apply(this, arguments);
|
2019-07-04 14:12:12 +02:00
|
|
|
|
2020-03-23 13:14:18 +01:00
|
|
|
this.affiliations_filter = '';
|
|
|
|
this.roles_filter = '';
|
|
|
|
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:role', () => {
|
2020-03-23 17:55:11 +01:00
|
|
|
this.users_with_role = this.chatroomview.model.getOccupantsWithRole(this.model.get('role'));
|
2019-07-04 14:12:12 +02:00
|
|
|
this.render();
|
|
|
|
});
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:affiliation', async () => {
|
2019-07-04 14:12:12 +02:00
|
|
|
this.loading_users_with_affiliation = true;
|
|
|
|
this.users_with_affiliation = null;
|
|
|
|
this.render();
|
2020-03-23 17:55:11 +01:00
|
|
|
const chatroom = this.chatroomview.model;
|
2019-07-04 14:12:12 +02:00
|
|
|
const affiliation = this.model.get('affiliation');
|
2020-02-21 16:20:30 +01:00
|
|
|
if (this.shouldFetchAffiliationsList()) {
|
2020-03-23 17:55:11 +01:00
|
|
|
this.users_with_affiliation = await chatroom.getAffiliationList(affiliation);
|
2019-07-04 14:12:12 +02:00
|
|
|
} else {
|
2020-03-23 17:55:11 +01:00
|
|
|
this.users_with_affiliation = chatroom.getOccupantsWithAffiliation(affiliation);
|
2019-07-04 14:12:12 +02:00
|
|
|
}
|
|
|
|
this.loading_users_with_affiliation = false;
|
|
|
|
this.render();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
2020-02-22 21:12:40 +01:00
|
|
|
const occupant = this.chatroomview.model.occupants.findWhere({'jid': _converse.bare_jid});
|
2019-07-04 14:12:12 +02:00
|
|
|
return tpl_moderator_tools_modal(Object.assign(this.model.toJSON(), {
|
2020-03-23 13:14:18 +01:00
|
|
|
'affiliations_filter': this.affiliations_filter,
|
2020-02-21 15:22:59 +01:00
|
|
|
'assignAffiliation': ev => this.assignAffiliation(ev),
|
|
|
|
'assignRole': ev => this.assignRole(ev),
|
2020-03-23 13:14:18 +01:00
|
|
|
'assignable_affiliations': this.getAssignableAffiliations(occupant),
|
|
|
|
'assignable_roles': this.getAssignableRoles(occupant),
|
|
|
|
'filterAffiliationResults': ev => this.filterAffiliationResults(ev),
|
|
|
|
'filterRoleResults': ev => this.filterRoleResults(ev),
|
2019-07-04 14:12:12 +02:00
|
|
|
'loading_users_with_affiliation': this.loading_users_with_affiliation,
|
2020-02-21 15:22:59 +01:00
|
|
|
'queryAffiliation': ev => this.queryAffiliation(ev),
|
|
|
|
'queryRole': ev => this.queryRole(ev),
|
2020-02-22 21:12:40 +01:00
|
|
|
'queryable_affiliations': AFFILIATIONS.filter(a => !_converse.modtools_disable_query.includes(a)),
|
|
|
|
'queryable_roles': ROLES.filter(a => !_converse.modtools_disable_query.includes(a)),
|
2020-03-23 13:14:18 +01:00
|
|
|
'roles_filter': this.roles_filter,
|
2020-02-21 15:22:59 +01:00
|
|
|
'switchTab': ev => this.switchTab(ev),
|
|
|
|
'toggleForm': ev => this.toggleForm(ev),
|
2019-07-04 14:12:12 +02:00
|
|
|
'users_with_affiliation': this.users_with_affiliation,
|
|
|
|
'users_with_role': this.users_with_role
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2020-02-22 21:12:40 +01:00
|
|
|
getAssignableAffiliations (occupant) {
|
|
|
|
const disabled = _converse.modtools_disable_assign;
|
|
|
|
if (!Array.isArray(disabled)) {
|
|
|
|
return disabled ? [] : AFFILIATIONS;
|
|
|
|
} else if (occupant.get('affiliation') === 'owner') {
|
|
|
|
return AFFILIATIONS.filter(a => !disabled.includes(a));
|
|
|
|
} else if (occupant.get('affiliation') === 'admin') {
|
|
|
|
return AFFILIATIONS.filter(a => !['owner', ...disabled].includes(a));
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getAssignableRoles (occupant) {
|
|
|
|
const disabled = _converse.modtools_disable_assign;
|
|
|
|
if (!Array.isArray(disabled)) {
|
|
|
|
return disabled ? [] : ROLES;
|
|
|
|
} else if (occupant.get('role') === 'moderator') {
|
|
|
|
return ROLES.filter(r => !disabled.includes(r));
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-21 16:20:30 +01:00
|
|
|
shouldFetchAffiliationsList () {
|
|
|
|
const affiliation = this.model.get('affiliation');
|
|
|
|
if (affiliation === 'none') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const chatroom = this.chatroomview.model;
|
|
|
|
const auto_fetched_affs = chatroom.occupants.getAutoFetchedAffiliationLists();
|
|
|
|
if (auto_fetched_affs.includes(affiliation)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-04 14:12:12 +02:00
|
|
|
toggleForm (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
const form_class = ev.target.getAttribute('data-form');
|
|
|
|
const form = u.ancestor(ev.target, '.list-group-item').querySelector(`.${form_class}`);
|
|
|
|
if (u.hasClass('hidden', form)) {
|
|
|
|
u.removeClass('hidden', form);
|
|
|
|
} else {
|
|
|
|
u.addClass('hidden', form);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-23 13:14:18 +01:00
|
|
|
filterRoleResults (ev) {
|
|
|
|
this.roles_filter = ev.target.value;
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
filterAffiliationResults (ev) {
|
|
|
|
this.affiliations_filter = ev.target.value;
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
2019-07-04 14:12:12 +02:00
|
|
|
queryRole (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
const data = new FormData(ev.target);
|
|
|
|
const role = data.get('role');
|
|
|
|
this.model.set({'role': null}, {'silent': true});
|
|
|
|
this.model.set({'role': role});
|
|
|
|
},
|
|
|
|
|
|
|
|
queryAffiliation (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
const data = new FormData(ev.target);
|
|
|
|
const affiliation = data.get('affiliation');
|
|
|
|
this.model.set({'affiliation': null}, {'silent': true});
|
|
|
|
this.model.set({'affiliation': affiliation});
|
|
|
|
},
|
|
|
|
|
|
|
|
assignAffiliation (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
const data = new FormData(ev.target);
|
|
|
|
const affiliation = data.get('affiliation');
|
|
|
|
const attrs = {
|
|
|
|
'jid': data.get('jid'),
|
|
|
|
'reason': data.get('reason')
|
|
|
|
}
|
|
|
|
const current_affiliation = this.model.get('affiliation');
|
|
|
|
this.chatroomview.model.setAffiliation(affiliation, [attrs])
|
|
|
|
.then(async () => {
|
|
|
|
this.alert(__('Affiliation changed'), 'primary');
|
|
|
|
await this.chatroomview.model.occupants.fetchMembers()
|
|
|
|
this.model.set({'affiliation': null}, {'silent': true});
|
|
|
|
this.model.set({'affiliation': current_affiliation});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.alert(__('Sorry, something went wrong while trying to set the affiliation'), 'danger');
|
2019-11-06 11:01:34 +01:00
|
|
|
log.error(err);
|
2019-07-04 14:12:12 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
assignRole (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
const data = new FormData(ev.target);
|
2019-09-07 23:41:48 +02:00
|
|
|
const occupant = this.chatroomview.model.getOccupant(data.get('jid') || data.get('nick'));
|
2019-07-04 14:12:12 +02:00
|
|
|
const role = data.get('role');
|
|
|
|
const reason = data.get('reason');
|
|
|
|
const current_role = this.model.get('role');
|
|
|
|
this.chatroomview.model.setRole(occupant, role, reason,
|
|
|
|
() => {
|
|
|
|
this.alert(__('Role changed'), 'primary');
|
|
|
|
this.model.set({'role': null}, {'silent': true});
|
|
|
|
this.model.set({'role': current_role});
|
|
|
|
},
|
|
|
|
(e) => {
|
|
|
|
if (sizzle(`not-allowed[xmlns="${Strophe.NS.STANZAS}"]`, e).length) {
|
|
|
|
this.alert(__('You\'re not allowed to make that change'), 'danger');
|
|
|
|
} else {
|
|
|
|
this.alert(__('Sorry, something went wrong while trying to set the role'), 'danger');
|
2019-09-07 23:41:48 +02:00
|
|
|
if (u.isErrorObject(e)) {
|
2019-11-06 11:01:34 +01:00
|
|
|
log.error(e);
|
2019-09-07 23:41:48 +02:00
|
|
|
}
|
2019-07-04 14:12:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-03-06 11:41:16 +01:00
|
|
|
_converse.ListChatRoomsModal = BootstrapModal.extend({
|
2020-01-23 10:18:41 +01:00
|
|
|
id: "list-chatrooms-modal",
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
|
|
initialize () {
|
2020-04-15 11:25:37 +02:00
|
|
|
this.items = [];
|
|
|
|
this.loading_items = false;
|
|
|
|
|
2020-03-06 11:41:16 +01:00
|
|
|
BootstrapModal.prototype.initialize.apply(this, arguments);
|
2019-02-26 10:34:41 +01:00
|
|
|
if (_converse.muc_domain && !this.model.get('muc_domain')) {
|
|
|
|
this.model.save('muc_domain', _converse.muc_domain);
|
|
|
|
}
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:muc_domain', this.onDomainChange);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
2019-02-26 10:34:41 +01:00
|
|
|
const muc_domain = this.model.get('muc_domain') || _converse.muc_domain;
|
2020-04-15 11:25:37 +02:00
|
|
|
return tpl_list_chatrooms_modal(
|
|
|
|
Object.assign(this.model.toJSON(), {
|
|
|
|
'show_form': !_converse.locked_muc_domain,
|
|
|
|
'server_placeholder': muc_domain ? muc_domain : __('conference.example.org'),
|
|
|
|
'items': this.items,
|
|
|
|
'loading_items': this.loading_items,
|
|
|
|
'openRoom': ev => this.openRoom(ev),
|
|
|
|
'setDomainFromEvent': ev => this.setDomainFromEvent(ev),
|
|
|
|
'submitForm': ev => this.showRooms(ev),
|
|
|
|
'toggleRoomInfo': ev => this.toggleRoomInfo(ev)
|
|
|
|
}));
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
afterRender () {
|
2019-02-26 10:34:41 +01:00
|
|
|
if (_converse.locked_muc_domain) {
|
|
|
|
this.updateRoomsList();
|
|
|
|
} else {
|
|
|
|
this.el.addEventListener('shown.bs.modal',
|
|
|
|
() => this.el.querySelector('input[name="server"]').focus(),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
openRoom (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const jid = ev.target.getAttribute('data-room-jid');
|
|
|
|
const name = ev.target.getAttribute('data-room-name');
|
|
|
|
this.modal.hide();
|
2020-04-15 12:24:34 +02:00
|
|
|
api.rooms.open(jid, {'name': name}, true);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleRoomInfo (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
toggleRoomInfo(ev);
|
|
|
|
},
|
|
|
|
|
2019-10-09 16:01:38 +02:00
|
|
|
onDomainChange () {
|
2020-04-15 11:25:37 +02:00
|
|
|
_converse.auto_list_rooms && this.updateRoomsList();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2020-04-15 11:25:37 +02:00
|
|
|
/**
|
|
|
|
* Handle the IQ stanza returned from the server, containing
|
|
|
|
* all its public groupchats.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#onRoomsFound
|
|
|
|
* @param { HTMLElement } iq
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
onRoomsFound (iq) {
|
2020-04-15 11:25:37 +02:00
|
|
|
const rooms = iq ? sizzle('query item', iq) : [];
|
2019-05-14 11:38:41 +02:00
|
|
|
if (rooms.length) {
|
2020-04-15 11:25:37 +02:00
|
|
|
this.model.set({'feedback_text': __('Groupchats found')}, {'silent': true});
|
|
|
|
this.items = rooms.map(st.getAttributes);
|
|
|
|
this.loading_items = false;
|
|
|
|
this.render();
|
2018-10-23 03:41:38 +02:00
|
|
|
} else {
|
2020-04-15 11:25:37 +02:00
|
|
|
this.model.set('feedback_text', __('No groupchats found'));
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2018-02-22 17:39:44 +01:00
|
|
|
|
2020-04-15 11:25:37 +02:00
|
|
|
/**
|
|
|
|
* Send an IQ stanza to the server asking for all groupchats
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#updateRoomsList
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
updateRoomsList () {
|
2018-10-25 07:32:44 +02:00
|
|
|
const iq = $iq({
|
|
|
|
'to': this.model.get('muc_domain'),
|
|
|
|
'from': _converse.connection.jid,
|
|
|
|
'type': "get"
|
|
|
|
}).c("query", {xmlns: Strophe.NS.DISCO_ITEMS});
|
2020-03-31 13:15:57 +02:00
|
|
|
api.sendIQ(iq)
|
2018-10-25 07:32:44 +02:00
|
|
|
.then(iq => this.onRoomsFound(iq))
|
2020-04-15 11:25:37 +02:00
|
|
|
.catch(() => this.onRoomsFound())
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
showRooms (ev) {
|
|
|
|
ev.preventDefault();
|
2020-04-15 11:25:37 +02:00
|
|
|
this.loading_items = true;
|
|
|
|
this.render();
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
const data = new FormData(ev.target);
|
2019-04-05 12:49:24 +02:00
|
|
|
this.model.setDomain(data.get('server'));
|
2018-10-23 03:41:38 +02:00
|
|
|
this.updateRoomsList();
|
|
|
|
},
|
|
|
|
|
2019-04-05 12:49:24 +02:00
|
|
|
setDomainFromEvent (ev) {
|
|
|
|
this.model.setDomain(ev.target.value);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setNick (ev) {
|
|
|
|
this.model.save({nick: ev.target.value});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-03-06 11:41:16 +01:00
|
|
|
_converse.AddChatRoomModal = BootstrapModal.extend({
|
2020-01-23 10:18:41 +01:00
|
|
|
id: 'add-chatroom-modal',
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
|
|
events: {
|
2019-12-30 13:23:52 +01:00
|
|
|
'submit form.add-chatroom': 'openChatRoom',
|
|
|
|
'keyup .roomjid-input': 'checkRoomidPolicy',
|
|
|
|
'change .roomjid-input': 'checkRoomidPolicy'
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-02-26 10:34:41 +01:00
|
|
|
initialize () {
|
2020-03-06 11:41:16 +01:00
|
|
|
BootstrapModal.prototype.initialize.apply(this, arguments);
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:muc_domain', this.render);
|
2019-12-30 13:23:52 +01:00
|
|
|
this.muc_roomid_policy_error_msg = null;
|
2019-02-26 10:34:41 +01:00
|
|
|
},
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
toHTML () {
|
2019-02-26 10:34:41 +01:00
|
|
|
let placeholder = '';
|
|
|
|
if (!_converse.locked_muc_domain) {
|
|
|
|
const muc_domain = this.model.get('muc_domain') || _converse.muc_domain;
|
|
|
|
placeholder = muc_domain ? `name@${muc_domain}` : __('name@conference.example.org');
|
|
|
|
}
|
2019-04-29 09:07:15 +02:00
|
|
|
return tpl_add_chatroom_modal(Object.assign(this.model.toJSON(), {
|
2019-03-26 12:16:18 +01:00
|
|
|
'_converse': _converse,
|
2019-02-26 10:34:41 +01:00
|
|
|
'label_room_address': _converse.muc_domain ? __('Groupchat name') : __('Groupchat address'),
|
2019-12-30 13:23:52 +01:00
|
|
|
'chatroom_placeholder': placeholder,
|
|
|
|
'muc_roomid_policy_error_msg': this.muc_roomid_policy_error_msg,
|
|
|
|
'muc_roomid_policy_hint': xss.filterXSS(_converse.muc_roomid_policy_hint, {'whiteList': {b: [], br: [], em: []}})
|
2018-10-23 03:41:38 +02:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
afterRender () {
|
|
|
|
this.el.addEventListener('shown.bs.modal', () => {
|
|
|
|
this.el.querySelector('input[name="chatroom"]').focus();
|
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
parseRoomDataFromEvent (form) {
|
|
|
|
const data = new FormData(form);
|
|
|
|
const jid = data.get('chatroom');
|
2019-03-26 13:29:33 +01:00
|
|
|
let nick;
|
|
|
|
if (_converse.locked_muc_nickname) {
|
|
|
|
nick = _converse.getDefaultMUCNickname();
|
|
|
|
if (!nick) {
|
|
|
|
throw new Error("Using locked_muc_nickname but no nickname found!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nick = data.get('nickname').trim();
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
return {
|
|
|
|
'jid': jid,
|
2019-03-26 13:29:33 +01:00
|
|
|
'nick': nick
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
openChatRoom (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const data = this.parseRoomDataFromEvent(ev.target);
|
|
|
|
if (data.nick === "") {
|
|
|
|
// Make sure defaults apply if no nick is provided.
|
|
|
|
data.nick = undefined;
|
|
|
|
}
|
2019-02-26 10:34:41 +01:00
|
|
|
let jid;
|
|
|
|
if (_converse.locked_muc_domain || (_converse.muc_domain && !u.isValidJID(data.jid))) {
|
|
|
|
jid = `${Strophe.escapeNode(data.jid)}@${_converse.muc_domain}`;
|
|
|
|
} else {
|
|
|
|
jid = data.jid
|
2019-04-05 12:49:24 +02:00
|
|
|
this.model.setDomain(jid);
|
2019-02-26 10:34:41 +01:00
|
|
|
}
|
2020-04-15 12:24:34 +02:00
|
|
|
api.rooms.open(jid, Object.assign(data, {jid}), true);
|
2018-10-23 03:41:38 +02:00
|
|
|
this.modal.hide();
|
|
|
|
ev.target.reset();
|
2019-12-30 13:23:52 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
checkRoomidPolicy () {
|
|
|
|
if (_converse.muc_roomid_policy && _converse.muc_domain) {
|
|
|
|
let jid = this.el.querySelector('.roomjid-input').value;
|
|
|
|
if (converse.locked_muc_domain || !u.isValidJID(jid)) {
|
|
|
|
jid = `${Strophe.escapeNode(jid)}@${_converse.muc_domain}`;
|
|
|
|
}
|
|
|
|
const roomid = Strophe.getNodeFromJid(jid);
|
|
|
|
const roomdomain = Strophe.getDomainFromJid(jid);
|
|
|
|
if (_converse.muc_domain !== roomdomain ||
|
|
|
|
_converse.muc_roomid_policy.test(roomid)) {
|
|
|
|
this.muc_roomid_policy_error_msg = null;
|
|
|
|
} else {
|
|
|
|
this.muc_roomid_policy_error_msg = __('Groupchat id is invalid.');
|
|
|
|
}
|
|
|
|
this.render();
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
});
|
2018-02-22 17:39:44 +01:00
|
|
|
|
2018-03-26 21:11:32 +02:00
|
|
|
|
2019-03-29 15:47:23 +01:00
|
|
|
/**
|
2019-09-19 16:54:55 +02:00
|
|
|
* NativeView which renders a groupchat, based upon
|
2019-11-08 09:49:58 +01:00
|
|
|
* { @link _converse.ChatBoxView } for normal one-on-one chat boxes.
|
2019-03-29 15:47:23 +01:00
|
|
|
* @class
|
|
|
|
* @namespace _converse.ChatRoomView
|
|
|
|
* @memberOf _converse
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
_converse.ChatRoomView = _converse.ChatBoxView.extend({
|
|
|
|
length: 300,
|
|
|
|
tagName: 'div',
|
|
|
|
className: 'chatbox chatroom hidden',
|
|
|
|
is_chatroom: true,
|
|
|
|
events: {
|
|
|
|
'change input.fileupload': 'onFileSelection',
|
|
|
|
'click .chat-msg__action-edit': 'onMessageEditButtonClicked',
|
2019-09-24 15:33:41 +02:00
|
|
|
'click .chat-msg__action-retract': 'onMessageRetractButtonClicked',
|
2018-10-23 03:41:38 +02:00
|
|
|
'click .chatbox-navback': 'showControlBox',
|
|
|
|
'click .hide-occupants': 'hideOccupants',
|
|
|
|
'click .new-msgs-indicator': 'viewUnreadMessages',
|
2019-11-28 17:01:08 +01:00
|
|
|
// Arrow functions don't work here because you can't bind a different `this` param to them.
|
|
|
|
'click .occupant-nick': function (ev) {this.insertIntoTextArea(ev.target.textContent) },
|
2018-10-23 03:41:38 +02:00
|
|
|
'click .send-button': 'onFormSubmitted',
|
|
|
|
'click .toggle-call': 'toggleCall',
|
|
|
|
'click .toggle-occupants': 'toggleOccupants',
|
|
|
|
'click .upload-file': 'toggleFileUpload',
|
2019-11-28 17:01:08 +01:00
|
|
|
'dragover .chat-textarea': 'onDragOver',
|
|
|
|
'drop .chat-textarea': 'onDrop',
|
|
|
|
'input .chat-textarea': 'inputChanged',
|
2019-05-26 10:58:52 +02:00
|
|
|
'keydown .chat-textarea': 'onKeyDown',
|
|
|
|
'keyup .chat-textarea': 'onKeyUp',
|
2019-12-04 16:01:34 +01:00
|
|
|
'mousedown .dragresize-occupants-left': 'onStartResizeOccupants',
|
2019-06-16 14:16:35 +02:00
|
|
|
'paste .chat-textarea': 'onPaste',
|
2019-11-28 17:01:08 +01:00
|
|
|
'submit .muc-nickname-form': 'submitNickname'
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-12-02 14:00:19 +01:00
|
|
|
async initialize () {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.initDebounced();
|
|
|
|
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model.messages, 'add', this.onMessageAdded);
|
2020-02-27 02:42:09 +01:00
|
|
|
this.listenTo(this.model.messages, 'change:edited', this.onMessageEdited);
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model.messages, 'rendered', this.scrollDown);
|
2019-05-21 09:56:27 +02:00
|
|
|
this.model.messages.on('reset', () => {
|
2020-03-24 13:41:13 +01:00
|
|
|
this.msgs_container.innerHTML = '';
|
2019-05-21 09:56:27 +02:00
|
|
|
this.removeAll();
|
|
|
|
});
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2019-12-10 15:40:33 +01:00
|
|
|
this.listenTo(this.model.session, 'change:connection_status', this.onConnectionStatusChanged);
|
2020-03-18 19:32:03 +01:00
|
|
|
|
2020-04-06 14:27:44 +02:00
|
|
|
this.listenTo(this.model, 'change', debounce(() => this.renderHeading(), 250));
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:hidden_occupants', this.updateOccupantsToggle);
|
|
|
|
this.listenTo(this.model, 'configurationNeeded', this.getAndRenderConfigurationForm);
|
|
|
|
this.listenTo(this.model, 'destroy', this.hide);
|
|
|
|
this.listenTo(this.model, 'show', this.show);
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model.features, 'change:moderated', this.renderBottomPanel);
|
2020-02-10 11:23:55 +01:00
|
|
|
this.listenTo(this.model.features, 'change:open', this.renderHeading);
|
2019-04-11 23:10:57 +02:00
|
|
|
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model.occupants, 'add', this.onOccupantAdded);
|
|
|
|
this.listenTo(this.model.occupants, 'remove', this.onOccupantRemoved);
|
|
|
|
this.listenTo(this.model.occupants, 'change:show', this.showJoinOrLeaveNotification);
|
|
|
|
this.listenTo(this.model.occupants, 'change:role', this.onOccupantRoleChanged);
|
|
|
|
this.listenTo(this.model.occupants, 'change:affiliation', this.onOccupantAffiliationChanged);
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2019-12-04 16:01:34 +01:00
|
|
|
// Bind so that we can pass it to addEventListener and removeEventListener
|
|
|
|
this.onMouseMove = this.onMouseMove.bind(this);
|
|
|
|
this.onMouseUp = this.onMouseUp.bind(this);
|
|
|
|
|
2020-03-31 17:22:05 +02:00
|
|
|
await this.render();
|
2020-04-10 16:49:02 +02:00
|
|
|
|
|
|
|
// Needs to be registered after render has been called.
|
|
|
|
this.listenTo(this.model.notifications, 'change', this.renderNotifications);
|
|
|
|
|
2020-01-27 13:20:23 +01:00
|
|
|
this.createSidebarView();
|
2019-12-02 14:00:19 +01:00
|
|
|
await this.updateAfterMessagesFetched();
|
2020-04-10 16:49:02 +02:00
|
|
|
|
|
|
|
// Register later due to await
|
|
|
|
const user_settings = await _converse.api.user.settings.getModel();
|
|
|
|
this.listenTo(user_settings, 'change:mucs_with_hidden_subject', this.renderHeading);
|
|
|
|
|
2019-06-01 16:16:30 +02:00
|
|
|
this.onConnectionStatusChanged();
|
2020-02-02 15:38:37 +01:00
|
|
|
this.model.maybeShow();
|
2020-04-10 16:49:02 +02:00
|
|
|
|
2019-03-29 15:47:23 +01:00
|
|
|
/**
|
2019-12-18 12:42:40 +01:00
|
|
|
* Triggered once a { @link _converse.ChatRoomView } has been opened
|
|
|
|
* @event _converse#chatRoomViewInitialized
|
2019-03-29 15:47:23 +01:00
|
|
|
* @type { _converse.ChatRoomView }
|
2019-12-18 12:42:40 +01:00
|
|
|
* @example _converse.api.listen.on('chatRoomViewInitialized', view => { ... });
|
2019-03-29 15:47:23 +01:00
|
|
|
*/
|
2020-03-31 13:15:57 +02:00
|
|
|
api.trigger('chatRoomViewInitialized', this);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2020-03-31 17:22:05 +02:00
|
|
|
async render () {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.el.setAttribute('id', this.model.get('box_id'));
|
2020-03-18 19:32:03 +01:00
|
|
|
render(tpl_chatroom({
|
|
|
|
'muc_show_logs_before_join': _converse.muc_show_logs_before_join,
|
|
|
|
'show_send_button': _converse.show_send_button
|
|
|
|
}), this.el);
|
2020-03-31 22:43:55 +02:00
|
|
|
this.notifications = this.el.querySelector('.chat-content__notifications');
|
2020-03-24 13:41:13 +01:00
|
|
|
this.content = this.el.querySelector('.chat-content');
|
|
|
|
this.msgs_container = this.el.querySelector('.chat-content__messages');
|
2020-03-31 22:43:55 +02:00
|
|
|
|
|
|
|
this.renderBottomPanel();
|
|
|
|
if (!_converse.muc_show_logs_before_join &&
|
|
|
|
this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
|
|
|
|
this.showSpinner();
|
2019-11-08 09:49:58 +01:00
|
|
|
}
|
2020-03-31 22:43:55 +02:00
|
|
|
// Render header as late as possible since it's async and we
|
|
|
|
// want the rest of the DOM elements to be available ASAP.
|
|
|
|
// Otherwise e.g. this.notifications is not yet defined when accessed elsewhere.
|
|
|
|
await this.renderHeading();
|
|
|
|
!this.model.get('hidden') && this.show();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-22 18:41:01 +01:00
|
|
|
|
2020-03-31 22:43:55 +02:00
|
|
|
renderNotifications () {
|
|
|
|
const actors_per_state = this.model.notifications.toJSON();
|
|
|
|
const states = api.settings.get('muc_show_join_leave') ?
|
|
|
|
[...converse.CHAT_STATES, ...converse.MUC_TRAFFIC_STATES] :
|
|
|
|
converse.CHAT_STATES;
|
|
|
|
|
|
|
|
const message = states.reduce((result, state) => {
|
2020-03-18 19:32:03 +01:00
|
|
|
const existing_actors = actors_per_state[state];
|
2020-03-24 09:31:56 +01:00
|
|
|
if (!(existing_actors?.length)) {
|
2020-03-18 19:32:03 +01:00
|
|
|
return result;
|
|
|
|
}
|
2020-03-24 12:49:35 +01:00
|
|
|
const actors = existing_actors.map(a => this.model.getOccupant(a)?.getDisplayName() || a);
|
2020-03-18 19:32:03 +01:00
|
|
|
if (actors.length === 1) {
|
|
|
|
if (state === 'composing') {
|
|
|
|
return `${result} ${__('%1$s is typing', actors[0])}\n`;
|
|
|
|
} else if (state === 'paused') {
|
|
|
|
return `${result} ${__('%1$s has stopped typing', actors[0])}\n`;
|
|
|
|
} else if (state === _converse.GONE) {
|
|
|
|
return `${result} ${__('%1$s has gone away', actors[0])}\n`;
|
2020-03-31 22:43:55 +02:00
|
|
|
} else if (state === 'entered') {
|
|
|
|
return `${result} ${__('%1$s has entered the groupchat', actors[0])}\n`;
|
|
|
|
} else if (state === 'exited') {
|
|
|
|
return `${result} ${__('%1$s has left the groupchat', actors[0])}\n`;
|
2020-03-18 19:32:03 +01:00
|
|
|
}
|
|
|
|
} else if (actors.length > 1) {
|
|
|
|
let actors_str;
|
|
|
|
if (actors.length > 3) {
|
|
|
|
actors_str = `${Array.from(actors).slice(0, 2).join(', ')} and others`;
|
|
|
|
} else {
|
|
|
|
const last_actor = actors.pop();
|
|
|
|
actors_str = __('%1$s and %2$s', actors.join(', '), last_actor);
|
|
|
|
}
|
2020-03-31 22:43:55 +02:00
|
|
|
|
2020-03-18 19:32:03 +01:00
|
|
|
if (state === 'composing') {
|
|
|
|
return `${result} ${__('%1$s are typing', actors_str)}\n`;
|
|
|
|
} else if (state === 'paused') {
|
|
|
|
return `${result} ${__('%1$s have stopped typing', actors_str)}\n`;
|
|
|
|
} else if (state === _converse.GONE) {
|
|
|
|
return `${result} ${__('%1$s have gone away', actors_str)}\n`;
|
2020-03-31 22:43:55 +02:00
|
|
|
} else if (state === 'entered') {
|
|
|
|
return `${result} ${__('%1$s have entered the groupchat', actors_str)}\n`;
|
|
|
|
} else if (state === 'exited') {
|
|
|
|
return `${result} ${__('%1$s have left the groupchat', actors_str)}\n`;
|
2020-03-18 19:32:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, '');
|
2020-03-31 22:43:55 +02:00
|
|
|
this.notifications.innerHTML = message;
|
|
|
|
message.includes('\n') && this.scrollDown();
|
2020-03-18 19:32:03 +01:00
|
|
|
},
|
|
|
|
|
2020-01-21 11:08:59 +01:00
|
|
|
/**
|
|
|
|
* Renders the MUC heading if any relevant attributes have changed.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#renderHeading
|
|
|
|
* @param { _converse.ChatRoom } [item]
|
|
|
|
*/
|
2020-03-31 17:22:05 +02:00
|
|
|
async renderHeading () {
|
|
|
|
const tpl = await this.generateHeadingTemplate();
|
|
|
|
render(tpl, this.el.querySelector('.chat-head-chatroom'));
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2020-02-10 11:23:55 +01:00
|
|
|
|
2019-04-10 23:25:14 +02:00
|
|
|
renderBottomPanel () {
|
|
|
|
const container = this.el.querySelector('.bottom-panel');
|
2019-12-10 15:40:33 +01:00
|
|
|
const entered = this.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED;
|
2019-11-28 17:01:08 +01:00
|
|
|
const can_edit = entered && !(this.model.features.get('moderated') && this.model.getOwnRole() === 'visitor');
|
2019-11-29 10:38:17 +01:00
|
|
|
container.innerHTML = tpl_chatroom_bottom_panel({__, can_edit, entered});
|
2019-11-28 17:01:08 +01:00
|
|
|
if (entered && can_edit) {
|
2019-10-29 11:30:31 +01:00
|
|
|
this.renderMessageForm();
|
|
|
|
this.initMentionAutoComplete();
|
2019-04-10 23:25:14 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-27 13:20:23 +01:00
|
|
|
createSidebarView () {
|
2019-05-15 14:47:04 +02:00
|
|
|
this.model.occupants.chatroomview = this;
|
2020-01-27 13:20:23 +01:00
|
|
|
this.sidebar_view = new _converse.MUCSidebar({'model': this.model.occupants});
|
2019-05-15 14:47:04 +02:00
|
|
|
const container_el = this.el.querySelector('.chatroom-body');
|
2019-12-04 16:01:34 +01:00
|
|
|
const occupants_width = this.model.get('occupants_width');
|
2020-01-27 13:20:23 +01:00
|
|
|
if (this.sidebar_view && occupants_width !== undefined) {
|
|
|
|
this.sidebar_view.el.style.flex = "0 0 " + occupants_width + "px";
|
2019-12-04 16:01:34 +01:00
|
|
|
}
|
2020-01-27 13:20:23 +01:00
|
|
|
container_el.insertAdjacentElement('beforeend', this.sidebar_view.el);
|
2019-12-04 16:01:34 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onStartResizeOccupants (ev) {
|
|
|
|
this.resizing = true;
|
|
|
|
this.el.addEventListener('mousemove', this.onMouseMove);
|
|
|
|
this.el.addEventListener('mouseup', this.onMouseUp);
|
|
|
|
|
2020-01-27 13:20:23 +01:00
|
|
|
const style = window.getComputedStyle(this.sidebar_view.el);
|
2019-12-04 16:01:34 +01:00
|
|
|
this.width = parseInt(style.width.replace(/px$/, ''), 10);
|
|
|
|
this.prev_pageX = ev.pageX;
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseMove (ev) {
|
|
|
|
if (this.resizing) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const delta = this.prev_pageX - ev.pageX;
|
2020-01-27 13:20:23 +01:00
|
|
|
this.resizeSidebarView(delta, ev.pageX);
|
2019-12-04 16:01:34 +01:00
|
|
|
this.prev_pageX = ev.pageX;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseUp (ev) {
|
|
|
|
if (this.resizing) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.resizing = false;
|
|
|
|
this.el.removeEventListener('mousemove', this.onMouseMove);
|
|
|
|
this.el.removeEventListener('mouseup', this.onMouseUp);
|
2020-01-27 13:20:23 +01:00
|
|
|
const element_position = this.sidebar_view.el.getBoundingClientRect();
|
|
|
|
const occupants_width = this.calculateSidebarWidth(element_position, 0);
|
2019-12-04 16:01:34 +01:00
|
|
|
const attrs = {occupants_width};
|
|
|
|
_converse.connection.connected ? this.model.save(attrs) : this.model.set(attrs);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-27 13:20:23 +01:00
|
|
|
resizeSidebarView (delta, current_mouse_position) {
|
|
|
|
const element_position = this.sidebar_view.el.getBoundingClientRect();
|
2019-12-04 16:01:34 +01:00
|
|
|
if (this.is_minimum) {
|
|
|
|
this.is_minimum = element_position.left < current_mouse_position;
|
|
|
|
} else if (this.is_maximum) {
|
|
|
|
this.is_maximum = element_position.left > current_mouse_position;
|
|
|
|
} else {
|
2020-01-27 13:20:23 +01:00
|
|
|
const occupants_width = this.calculateSidebarWidth(element_position, delta);
|
|
|
|
this.sidebar_view.el.style.flex = "0 0 " + occupants_width + "px";
|
2019-12-04 16:01:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-27 13:20:23 +01:00
|
|
|
calculateSidebarWidth(element_position, delta) {
|
2019-12-04 16:01:34 +01:00
|
|
|
let occupants_width = element_position.width + delta;
|
|
|
|
const room_width = this.el.clientWidth;
|
|
|
|
// keeping display in boundaries
|
|
|
|
if (occupants_width < (room_width * 0.20)) {
|
|
|
|
// set pixel to 20% width
|
|
|
|
occupants_width = (room_width * 0.20);
|
|
|
|
this.is_minimum = true;
|
|
|
|
} else if (occupants_width > (room_width * 0.75)) {
|
|
|
|
// set pixel to 75% width
|
|
|
|
occupants_width = (room_width * 0.75);
|
|
|
|
this.is_maximum = true;
|
|
|
|
} else if ((room_width - occupants_width) < 250) {
|
|
|
|
// resize occupants if chat-area becomes smaller than 250px (min-width property set in css)
|
|
|
|
occupants_width = room_width - 250;
|
|
|
|
this.is_maximum = true;
|
|
|
|
} else {
|
|
|
|
this.is_maximum = false;
|
|
|
|
this.is_minimum = false;
|
|
|
|
}
|
|
|
|
return occupants_width;
|
2019-05-15 14:47:04 +02:00
|
|
|
},
|
|
|
|
|
2019-05-27 22:45:51 +02:00
|
|
|
getAutoCompleteList () {
|
2020-02-21 12:30:37 +01:00
|
|
|
return this.model.getAllKnownNicknames().map(nick => ({'label': nick, 'value': `@${nick}`}));
|
2019-05-27 22:45:51 +02:00
|
|
|
},
|
|
|
|
|
2019-11-11 15:27:34 +01:00
|
|
|
getAutoCompleteListItem(text, input) {
|
|
|
|
input = input.trim();
|
|
|
|
const element = document.createElement("li");
|
|
|
|
element.setAttribute("aria-selected", "false");
|
|
|
|
|
|
|
|
if (_converse.muc_mention_autocomplete_show_avatar) {
|
|
|
|
const img = document.createElement("img");
|
|
|
|
let dataUri = "data:" + _converse.DEFAULT_IMAGE_TYPE + ";base64," + _converse.DEFAULT_IMAGE;
|
|
|
|
|
|
|
|
if (_converse.vcards) {
|
|
|
|
const vcard = _converse.vcards.findWhere({'nickname': text});
|
|
|
|
if (vcard) dataUri = "data:" + vcard.get('image_type') + ";base64," + vcard.get('image');
|
|
|
|
}
|
|
|
|
|
|
|
|
img.setAttribute("src", dataUri);
|
|
|
|
img.setAttribute("width", "22");
|
|
|
|
img.setAttribute("class", "avatar avatar-autocomplete");
|
|
|
|
element.appendChild(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
const regex = new RegExp("(" + input + ")", "ig");
|
|
|
|
const parts = input ? text.split(regex) : [text];
|
|
|
|
|
|
|
|
parts.forEach(txt => {
|
|
|
|
if (input && txt.match(regex)) {
|
|
|
|
const match = document.createElement("mark");
|
|
|
|
match.textContent = txt;
|
|
|
|
element.appendChild(match);
|
|
|
|
} else {
|
|
|
|
element.appendChild(document.createTextNode(txt));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2019-03-03 20:56:48 +01:00
|
|
|
initMentionAutoComplete () {
|
2019-03-28 12:35:40 +01:00
|
|
|
this.mention_auto_complete = new _converse.AutoComplete(this.el, {
|
2018-10-23 03:41:38 +02:00
|
|
|
'auto_first': true,
|
|
|
|
'auto_evaluate': false,
|
2019-06-19 14:51:34 +02:00
|
|
|
'min_chars': _converse.muc_mention_autocomplete_min_chars,
|
2018-10-23 03:41:38 +02:00
|
|
|
'match_current_word': true,
|
2019-05-27 22:45:51 +02:00
|
|
|
'list': () => this.getAutoCompleteList(),
|
2019-11-11 15:27:34 +01:00
|
|
|
'filter': _converse.muc_mention_autocomplete_filter == 'contains' ? _converse.FILTER_CONTAINS : _converse.FILTER_STARTSWITH,
|
2019-03-04 09:42:16 +01:00
|
|
|
'ac_triggers': ["Tab", "@"],
|
2019-11-11 15:27:34 +01:00
|
|
|
'include_triggers': [],
|
|
|
|
'item': this.getAutoCompleteListItem
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
2019-03-28 12:35:40 +01:00
|
|
|
this.mention_auto_complete.on('suggestion-box-selectcomplete', () => (this.auto_completing = false));
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-22 15:51:44 +01:00
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
|
|
|
* Get the nickname value from the form and then join the groupchat with it.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#submitNickname
|
|
|
|
* @param { Event }
|
|
|
|
*/
|
|
|
|
submitNickname (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const nick = ev.target.nick.value.trim();
|
2019-12-09 16:54:50 +01:00
|
|
|
nick && this.model.join(nick);
|
2019-11-28 17:01:08 +01:00
|
|
|
},
|
|
|
|
|
2019-05-26 10:58:52 +02:00
|
|
|
onKeyDown (ev) {
|
|
|
|
if (this.mention_auto_complete.onKeyDown(ev)) {
|
2018-10-23 03:41:38 +02:00
|
|
|
return;
|
2018-02-21 22:29:21 +01:00
|
|
|
}
|
2019-06-16 14:16:35 +02:00
|
|
|
return _converse.ChatBoxView.prototype.onKeyDown.call(this, ev);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-05-26 10:58:52 +02:00
|
|
|
onKeyUp (ev) {
|
2019-03-28 12:35:40 +01:00
|
|
|
this.mention_auto_complete.evaluate(ev);
|
2019-06-16 14:16:35 +02:00
|
|
|
return _converse.ChatBoxView.prototype.onKeyUp.call(this, ev);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-09-24 15:33:41 +02:00
|
|
|
async onMessageRetractButtonClicked (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const msg_el = u.ancestor(ev.target, '.message');
|
|
|
|
const msgid = msg_el.getAttribute('data-msgid');
|
|
|
|
const time = msg_el.getAttribute('data-isodate');
|
|
|
|
const message = this.model.messages.findWhere({msgid, time});
|
|
|
|
const retraction_warning =
|
|
|
|
__("Be aware that other XMPP/Jabber clients (and servers) may "+
|
|
|
|
"not yet support retractions and that this message may not "+
|
|
|
|
"be removed everywhere.");
|
|
|
|
|
2020-03-26 10:35:08 +01:00
|
|
|
if (message.mayBeRetracted()) {
|
2019-09-24 15:33:41 +02:00
|
|
|
const messages = [__('Are you sure you want to retract this message?')];
|
|
|
|
if (_converse.show_retraction_warning) {
|
|
|
|
messages[1] = retraction_warning;
|
|
|
|
}
|
2020-04-15 09:13:50 +02:00
|
|
|
!!(await api.confirm(__('Confirm'), messages)) && this.retractOwnMessage(message);
|
2020-03-26 10:35:08 +01:00
|
|
|
} else if (await message.mayBeModerated()) {
|
|
|
|
if (message.get('sender') === 'me') {
|
|
|
|
let messages = [__('Are you sure you want to retract this message?')];
|
|
|
|
if (_converse.show_retraction_warning) {
|
|
|
|
messages = [messages[0], retraction_warning, messages[1]]
|
|
|
|
}
|
2020-04-15 09:13:50 +02:00
|
|
|
!!(await api.confirm(__('Confirm'), messages)) && this.retractOtherMessage(message);
|
2020-03-26 10:35:08 +01:00
|
|
|
} else {
|
|
|
|
let messages = [
|
|
|
|
__('You are about to retract this message.'),
|
|
|
|
__('You may optionally include a message, explaining the reason for the retraction.')
|
|
|
|
];
|
|
|
|
if (_converse.show_retraction_warning) {
|
|
|
|
messages = [messages[0], retraction_warning, messages[1]]
|
|
|
|
}
|
2020-03-31 13:15:57 +02:00
|
|
|
const reason = await api.prompt(
|
2020-03-26 10:35:08 +01:00
|
|
|
__('Message Retraction'),
|
|
|
|
messages,
|
|
|
|
__('Optional reason')
|
|
|
|
);
|
2020-04-15 09:13:50 +02:00
|
|
|
(reason !== false) && this.retractOtherMessage(message, reason);
|
2019-09-24 15:33:41 +02:00
|
|
|
}
|
2020-03-26 10:35:08 +01:00
|
|
|
} else {
|
|
|
|
const err_msg = __(`Sorry, you're not allowed to retract this message`);
|
2020-03-31 13:15:57 +02:00
|
|
|
api.alert('error', __('Error'), err_msg);
|
2019-09-24 15:33:41 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retract one of your messages in this groupchat.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#retractOwnMessage
|
|
|
|
* @param { _converse.Message } message - The message which we're retracting.
|
|
|
|
*/
|
|
|
|
retractOwnMessage(message) {
|
2020-02-18 15:42:55 +01:00
|
|
|
this.model.retractOwnMessage(message)
|
2019-09-24 15:33:41 +02:00
|
|
|
.catch(e => {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __('Sorry, something went wrong while trying to retract your message.');
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
|
|
|
!u.isErrorStanza(e) && this.model.createMessage({'message': e.message, 'type': 'error'});
|
2019-09-24 15:33:41 +02:00
|
|
|
log.error(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retract someone else's message in this groupchat.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#retractOtherMessage
|
|
|
|
* @param { _converse.Message } message - The message which we're retracting.
|
|
|
|
* @param { string } [reason] - The reason for retracting the message.
|
|
|
|
*/
|
|
|
|
async retractOtherMessage (message, reason) {
|
2020-02-18 16:06:59 +01:00
|
|
|
const result = await this.model.retractOtherMessage(message, reason);
|
2019-09-24 15:33:41 +02:00
|
|
|
if (result === null) {
|
|
|
|
const err_msg = __(`A timeout occurred while trying to retract the message`);
|
2020-03-31 13:15:57 +02:00
|
|
|
api.alert('error', __('Error'), err_msg);
|
|
|
|
log(err_msg, Strophe.LogLevel.WARN);
|
2019-09-24 15:33:41 +02:00
|
|
|
} else if (u.isErrorStanza(result)) {
|
|
|
|
const err_msg = __(`Sorry, you're not allowed to retract this message.`);
|
2020-03-31 13:15:57 +02:00
|
|
|
api.alert('error', __('Error'), err_msg);
|
|
|
|
log(err_msg, Strophe.LogLevel.WARN);
|
|
|
|
log(result, Strophe.LogLevel.WARN);
|
2019-09-24 15:33:41 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-04 14:12:12 +02:00
|
|
|
showModeratorToolsModal (affiliation) {
|
2019-09-07 23:41:48 +02:00
|
|
|
if (!this.verifyRoles(['moderator'])) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-21 11:08:59 +01:00
|
|
|
if (isUndefined(this.model.modtools_modal)) {
|
2019-09-19 16:54:55 +02:00
|
|
|
const model = new Model({'affiliation': affiliation});
|
2019-07-04 14:12:12 +02:00
|
|
|
this.modtools_modal = new _converse.ModeratorToolsModal({'model': model, 'chatroomview': this});
|
|
|
|
} else {
|
|
|
|
this.modtools_modal.set('affiliation', affiliation);
|
|
|
|
}
|
|
|
|
this.modtools_modal.show();
|
|
|
|
},
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
showRoomDetailsModal (ev) {
|
|
|
|
ev.preventDefault();
|
2019-07-29 10:19:05 +02:00
|
|
|
if (this.model.room_details_modal === undefined) {
|
2020-04-15 13:59:55 +02:00
|
|
|
this.model.room_details_modal = new RoomDetailsModal({'model': this.model});
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
this.model.room_details_modal.show(ev);
|
|
|
|
},
|
2018-06-04 19:53:33 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
showChatStateNotification (message) {
|
|
|
|
if (message.get('sender') === 'me') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return _converse.ChatBoxView.prototype.showChatStateNotification.apply(this, arguments);
|
|
|
|
},
|
2018-06-04 19:53:33 +02:00
|
|
|
|
2019-07-10 09:47:13 +02:00
|
|
|
onOccupantAffiliationChanged (occupant) {
|
|
|
|
if (occupant.get('jid') === _converse.bare_jid) {
|
|
|
|
this.renderHeading();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-13 11:10:25 +02:00
|
|
|
onOccupantRoleChanged (occupant) {
|
2019-07-10 09:47:13 +02:00
|
|
|
if (occupant.get('jid') === _converse.bare_jid) {
|
|
|
|
this.renderBottomPanel();
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-06-04 19:53:33 +02:00
|
|
|
|
2020-04-06 17:21:38 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of objects which represent buttons for the groupchat header.
|
|
|
|
* @emits _converse#getHeadingButtons
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#getHeadingButtons
|
|
|
|
*/
|
2020-04-06 14:27:44 +02:00
|
|
|
getHeadingButtons (subject_hidden) {
|
2020-04-15 13:59:55 +02:00
|
|
|
const buttons = [];
|
|
|
|
buttons.push({
|
2020-02-10 11:23:55 +01:00
|
|
|
'i18n_text': __('Details'),
|
|
|
|
'i18n_title': __('Show more information about this groupchat'),
|
|
|
|
'handler': ev => this.showRoomDetailsModal(ev),
|
|
|
|
'a_class': 'show-room-details-modal',
|
|
|
|
'icon_class': 'fa-info-circle',
|
|
|
|
'name': 'details'
|
2020-04-15 13:59:55 +02:00
|
|
|
});
|
|
|
|
|
2020-02-07 14:58:26 +01:00
|
|
|
if (this.model.getOwnAffiliation() === 'owner') {
|
2020-02-10 11:23:55 +01:00
|
|
|
buttons.push({
|
|
|
|
'i18n_text': __('Configure'),
|
|
|
|
'i18n_title': __('Configure this groupchat'),
|
|
|
|
'handler': ev => this.getAndRenderConfigurationForm(ev),
|
|
|
|
'a_class': 'configure-chatroom-button',
|
|
|
|
'icon_class': 'fa-wrench',
|
|
|
|
'name': 'configure'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-22 20:14:12 +01:00
|
|
|
if (this.model.invitesAllowed()) {
|
|
|
|
buttons.push({
|
|
|
|
'i18n_text': __('Invite'),
|
|
|
|
'i18n_title': __('Invite someone to join this groupchat'),
|
|
|
|
'handler': ev => this.showInviteModal(ev),
|
|
|
|
'a_class': 'open-invite-modal',
|
|
|
|
'icon_class': 'fa-user-plus',
|
|
|
|
'name': 'invite'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const subject = this.model.get('subject');
|
|
|
|
if (subject && subject.text) {
|
2020-02-10 11:23:55 +01:00
|
|
|
buttons.push({
|
2020-03-31 17:22:05 +02:00
|
|
|
'i18n_text': subject_hidden ? __('Show topic') : __('Hide topic'),
|
|
|
|
'i18n_title': subject_hidden ?
|
2020-02-10 11:23:55 +01:00
|
|
|
__('Show the topic message in the heading') :
|
|
|
|
__('Hide the topic in the heading'),
|
|
|
|
'handler': ev => this.toggleTopic(ev),
|
2020-04-06 14:27:44 +02:00
|
|
|
'a_class': 'hide-topic',
|
2020-02-10 11:23:55 +01:00
|
|
|
'icon_class': 'fa-minus-square',
|
|
|
|
'name': 'toggle-topic'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:13:50 +02:00
|
|
|
|
|
|
|
const conn_status = this.model.session.get('connection_status');
|
|
|
|
if (conn_status === converse.ROOMSTATUS.ENTERED) {
|
|
|
|
const allowed_commands = this.getAllowedCommands();
|
|
|
|
if (allowed_commands.includes('modtools')) {
|
|
|
|
buttons.push({
|
|
|
|
'i18n_text': __('Moderate'),
|
|
|
|
'i18n_title': __('Moderate this groupchat'),
|
|
|
|
'handler': () => this.showModeratorToolsModal(),
|
|
|
|
'a_class': 'moderate-chatroom-button',
|
|
|
|
'icon_class': 'fa-user-cog',
|
|
|
|
'name': 'moderate'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (allowed_commands.includes('destroy')) {
|
|
|
|
buttons.push({
|
|
|
|
'i18n_text': __('Destroy'),
|
|
|
|
'i18n_title': __('Remove this groupchat'),
|
|
|
|
'handler': ev => this.destroy(ev),
|
|
|
|
'a_class': 'destroy-chatroom-button',
|
|
|
|
'icon_class': 'fa-trash',
|
|
|
|
'name': 'destroy'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
if (!api.settings.get("singleton")) {
|
2020-02-10 11:23:55 +01:00
|
|
|
buttons.push({
|
|
|
|
'i18n_text': __('Leave'),
|
|
|
|
'i18n_title': __('Leave and close this groupchat'),
|
|
|
|
'handler': async ev => {
|
|
|
|
const messages = [__('Are you sure you want to leave this groupchat?')];
|
2020-03-31 13:15:57 +02:00
|
|
|
const result = await api.confirm(__('Confirm'), messages);
|
2020-02-10 11:23:55 +01:00
|
|
|
result && this.close(ev);
|
|
|
|
},
|
|
|
|
'a_class': 'close-chatbox-button',
|
2020-03-31 13:15:57 +02:00
|
|
|
'standalone': api.settings.get("view_mode") === 'overlayed',
|
2020-02-10 11:23:55 +01:00
|
|
|
'icon_class': 'fa-sign-out-alt',
|
|
|
|
'name': 'signout'
|
|
|
|
});
|
|
|
|
}
|
2020-04-06 17:21:38 +02:00
|
|
|
return _converse.api.hook('getHeadingButtons', this, buttons);
|
2020-02-07 14:58:26 +01:00
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
2020-02-10 11:23:55 +01:00
|
|
|
* Returns the groupchat heading TemplateResult to be rendered.
|
2019-11-28 17:01:08 +01:00
|
|
|
* @private
|
2020-02-07 14:58:26 +01:00
|
|
|
* @method _converse.ChatRoomView#generateHeadingTemplate
|
2019-11-28 17:01:08 +01:00
|
|
|
*/
|
2020-03-31 17:22:05 +02:00
|
|
|
async generateHeadingTemplate () {
|
2020-04-08 14:31:18 +02:00
|
|
|
const subject_hidden = await this.model.isSubjectHidden();
|
2020-04-06 17:21:38 +02:00
|
|
|
const heading_btns = await this.getHeadingButtons(subject_hidden);
|
2020-02-10 11:23:55 +01:00
|
|
|
const standalone_btns = heading_btns.filter(b => b.standalone);
|
|
|
|
const dropdown_btns = heading_btns.filter(b => !b.standalone);
|
2018-10-23 03:41:38 +02:00
|
|
|
return tpl_chatroom_head(
|
2019-04-29 09:07:15 +02:00
|
|
|
Object.assign(this.model.toJSON(), {
|
2020-02-07 14:58:26 +01:00
|
|
|
_converse,
|
2020-04-06 14:27:44 +02:00
|
|
|
subject_hidden,
|
2020-02-10 11:23:55 +01:00
|
|
|
'dropdown_btns': dropdown_btns.map(b => this.getHeadingDropdownItem(b)),
|
|
|
|
'standalone_btns': standalone_btns.map(b => this.getHeadingStandaloneButton(b)),
|
2019-05-29 12:57:54 +02:00
|
|
|
'title': this.model.getDisplayName(),
|
2018-10-23 03:41:38 +02:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2020-04-08 14:31:18 +02:00
|
|
|
toggleTopic () {
|
|
|
|
this.model.toggleSubjectHiddenState();
|
2020-02-10 11:23:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
showInviteModal (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
if (this.muc_invite_modal === undefined) {
|
|
|
|
this.muc_invite_modal = new _converse.MUCInviteModal({'model': new Model()});
|
|
|
|
// TODO: remove once we have API for sending direct invite
|
|
|
|
this.muc_invite_modal.chatroomview = this;
|
|
|
|
}
|
|
|
|
this.muc_invite_modal.show(ev);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2019-12-03 10:55:46 +01:00
|
|
|
/**
|
|
|
|
* Callback method that gets called after the chat has become visible.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#afterShown
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
afterShown () {
|
2019-12-03 10:55:46 +01:00
|
|
|
// Override from converse-chatview, specifically to avoid
|
|
|
|
// the 'active' chat state from being sent out prematurely.
|
|
|
|
// This is instead done in `onConnectionStatusChanged` below.
|
2018-10-23 03:41:38 +02:00
|
|
|
if (u.isPersistableModel(this.model)) {
|
|
|
|
this.model.clearUnreadMsgCounter();
|
|
|
|
}
|
2019-06-19 11:04:09 +02:00
|
|
|
this.scrollDown();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-05-20 10:06:37 +02:00
|
|
|
onConnectionStatusChanged () {
|
2019-12-10 15:40:33 +01:00
|
|
|
const conn_status = this.model.session.get('connection_status');
|
2019-05-20 10:06:37 +02:00
|
|
|
if (conn_status === converse.ROOMSTATUS.NICKNAME_REQUIRED) {
|
2019-11-28 17:01:08 +01:00
|
|
|
this.renderNicknameForm();
|
2019-06-11 12:16:27 +02:00
|
|
|
} else if (conn_status === converse.ROOMSTATUS.PASSWORD_REQUIRED) {
|
|
|
|
this.renderPasswordForm();
|
2019-05-20 10:06:37 +02:00
|
|
|
} else if (conn_status === converse.ROOMSTATUS.CONNECTING) {
|
2019-05-19 22:11:26 +02:00
|
|
|
this.showSpinner();
|
2019-05-20 10:06:37 +02:00
|
|
|
} else if (conn_status === converse.ROOMSTATUS.ENTERED) {
|
2019-11-29 10:38:17 +01:00
|
|
|
this.renderBottomPanel();
|
2018-10-23 03:41:38 +02:00
|
|
|
this.hideSpinner();
|
2020-01-09 14:28:43 +01:00
|
|
|
this.maybeFocus();
|
2019-06-11 12:16:27 +02:00
|
|
|
} else if (conn_status === converse.ROOMSTATUS.DISCONNECTED) {
|
|
|
|
this.showDisconnectMessage();
|
|
|
|
} else if (conn_status === converse.ROOMSTATUS.DESTROYED) {
|
|
|
|
this.showDestroyedMessage();
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
2018-08-10 14:09:21 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
getToolbarOptions () {
|
2019-04-29 09:07:15 +02:00
|
|
|
return Object.assign(
|
2018-10-23 03:41:38 +02:00
|
|
|
_converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments),
|
|
|
|
{
|
|
|
|
'label_hide_occupants': __('Hide the list of participants'),
|
2019-07-10 09:47:13 +02:00
|
|
|
'show_occupants_toggle': _converse.visible_toolbar_buttons.toggle_occupants
|
2018-08-14 14:05:33 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
);
|
|
|
|
},
|
2018-08-10 14:09:21 +02:00
|
|
|
|
2019-05-15 14:47:04 +02:00
|
|
|
/**
|
|
|
|
* Closes this chat box, which implies leaving the groupchat as well.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#close
|
|
|
|
*/
|
2019-10-24 14:29:15 +02:00
|
|
|
async close () {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.hide();
|
2019-09-19 16:54:55 +02:00
|
|
|
if (_converse.router.history.getFragment() === "converse/room?jid="+this.model.get('jid')) {
|
2018-10-23 03:41:38 +02:00
|
|
|
_converse.router.navigate('');
|
|
|
|
}
|
2019-10-24 14:29:15 +02:00
|
|
|
await this.model.leave();
|
2019-10-11 20:29:12 +02:00
|
|
|
return _converse.ChatBoxView.prototype.close.apply(this, arguments);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-05-15 14:47:04 +02:00
|
|
|
updateOccupantsToggle () {
|
2018-10-23 03:41:38 +02:00
|
|
|
const icon_el = this.el.querySelector('.toggle-occupants');
|
2019-05-15 14:47:04 +02:00
|
|
|
const chat_area = this.el.querySelector('.chat-area');
|
2018-10-23 03:41:38 +02:00
|
|
|
if (this.model.get('hidden_occupants')) {
|
|
|
|
u.removeClass('fa-angle-double-right', icon_el);
|
|
|
|
u.addClass('fa-angle-double-left', icon_el);
|
2018-10-26 16:37:56 +02:00
|
|
|
u.addClass('full', chat_area);
|
2018-10-23 03:41:38 +02:00
|
|
|
} else {
|
|
|
|
u.addClass('fa-angle-double-right', icon_el);
|
|
|
|
u.removeClass('fa-angle-double-left', icon_el);
|
2018-10-26 16:37:56 +02:00
|
|
|
u.removeClass('full', chat_area);
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
2018-08-14 14:05:33 +02:00
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
2020-02-10 11:23:55 +01:00
|
|
|
* Hide the right sidebar containing the chat occupants.
|
2019-11-28 17:01:08 +01:00
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#hideOccupants
|
|
|
|
*/
|
2019-10-09 16:01:38 +02:00
|
|
|
hideOccupants (ev) {
|
2018-10-23 03:41:38 +02:00
|
|
|
if (ev) {
|
2018-06-04 19:53:33 +02:00
|
|
|
ev.preventDefault();
|
2018-10-23 03:41:38 +02:00
|
|
|
ev.stopPropagation();
|
|
|
|
}
|
|
|
|
this.model.save({'hidden_occupants': true});
|
2019-06-19 11:04:09 +02:00
|
|
|
this.scrollDown();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
2020-02-10 11:23:55 +01:00
|
|
|
* Show or hide the right sidebar containing the chat occupants.
|
2019-11-28 17:01:08 +01:00
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#toggleOccupants
|
|
|
|
*/
|
2019-05-15 14:47:04 +02:00
|
|
|
toggleOccupants (ev) {
|
2018-10-23 03:41:38 +02:00
|
|
|
if (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
}
|
2019-05-15 14:47:04 +02:00
|
|
|
this.model.save({'hidden_occupants': !this.model.get('hidden_occupants')});
|
2019-06-19 11:04:09 +02:00
|
|
|
this.scrollDown();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-09-07 11:53:50 +02:00
|
|
|
|
2019-04-25 10:34:17 +02:00
|
|
|
verifyRoles (roles, occupant, show_error=true) {
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!Array.isArray(roles)) {
|
|
|
|
throw new TypeError('roles must be an Array');
|
|
|
|
}
|
|
|
|
if (!roles.length) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 13:07:16 +02:00
|
|
|
occupant = occupant || this.model.occupants.findWhere({'jid': _converse.bare_jid});
|
|
|
|
if (occupant) {
|
|
|
|
const role = occupant.get('role');
|
|
|
|
if (roles.includes(role)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2019-05-14 11:38:41 +02:00
|
|
|
if (show_error) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __('Forbidden: you do not have the necessary role in order to do that.');
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2019-05-14 11:38:41 +02:00
|
|
|
}
|
|
|
|
return false;
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-04-25 10:34:17 +02:00
|
|
|
verifyAffiliations (affiliations, occupant, show_error=true) {
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!Array.isArray(affiliations)) {
|
|
|
|
throw new TypeError('affiliations must be an Array');
|
|
|
|
}
|
|
|
|
if (!affiliations.length) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 13:07:16 +02:00
|
|
|
occupant = occupant || this.model.occupants.findWhere({'jid': _converse.bare_jid});
|
|
|
|
if (occupant) {
|
|
|
|
const a = occupant.get('affiliation');
|
|
|
|
if (affiliations.includes(a)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2019-05-14 11:38:41 +02:00
|
|
|
if (show_error) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __('Forbidden: you do not have the necessary affiliation in order to do that.');
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2019-05-14 11:38:41 +02:00
|
|
|
}
|
|
|
|
return false;
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-05-26 17:53:32 +02:00
|
|
|
validateRoleOrAffiliationChangeArgs (command, args) {
|
|
|
|
if (!args) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __(
|
|
|
|
'Error: the "%1$s" command takes two arguments, the user\'s nickname and optionally a reason.',
|
|
|
|
command
|
2018-02-21 22:29:21 +01:00
|
|
|
);
|
2020-04-19 08:03:44 +02:00
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2018-10-23 03:41:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-26 17:53:32 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
getNickOrJIDFromCommandArgs (args) {
|
2020-04-19 06:49:03 +02:00
|
|
|
if (u.isValidJID(args.trim())) {
|
|
|
|
return args.trim();
|
|
|
|
}
|
2019-05-27 12:24:46 +02:00
|
|
|
if (!args.startsWith('@')) {
|
|
|
|
args = '@'+ args;
|
|
|
|
}
|
2019-10-09 16:01:38 +02:00
|
|
|
const [text, references] = this.model.parseTextForReferences(args); // eslint-disable-line no-unused-vars
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!references.length) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __("Error: couldn't find a groupchat participant based on your arguments");
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2019-06-18 12:36:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (references.length > 1) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __("Error: found multiple groupchat participant based on your arguments");
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2019-06-18 12:36:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const nick_or_jid = references.pop().value;
|
2019-07-04 08:13:47 +02:00
|
|
|
const reason = args.split(nick_or_jid, 2)[1];
|
|
|
|
if (reason && !reason.startsWith(' ')) {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __("Error: couldn't find a groupchat participant based on your arguments");
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2019-06-18 12:36:16 +02:00
|
|
|
return;
|
2019-05-26 17:53:32 +02:00
|
|
|
}
|
2019-06-18 12:36:16 +02:00
|
|
|
return nick_or_jid;
|
2019-05-26 17:53:32 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setAffiliation (command, args, required_affiliations) {
|
|
|
|
const affiliation = COMMAND_TO_AFFILIATION[command];
|
|
|
|
if (!affiliation) {
|
|
|
|
throw Error(`ChatRoomView#setAffiliation called with invalid command: ${command}`);
|
|
|
|
}
|
|
|
|
if (!this.verifyAffiliations(required_affiliations)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!this.validateRoleOrAffiliationChangeArgs(command, args)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-18 12:36:16 +02:00
|
|
|
const nick_or_jid = this.getNickOrJIDFromCommandArgs(args);
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!nick_or_jid) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-19 06:49:03 +02:00
|
|
|
|
|
|
|
let jid;
|
2019-05-27 12:24:46 +02:00
|
|
|
const reason = args.split(nick_or_jid, 2)[1].trim();
|
2019-05-26 17:53:32 +02:00
|
|
|
const occupant = this.model.getOccupant(nick_or_jid);
|
2020-04-19 06:49:03 +02:00
|
|
|
if (occupant) {
|
|
|
|
jid = occupant.get('jid');
|
|
|
|
} else {
|
|
|
|
if (u.isValidJID(nick_or_jid)) {
|
|
|
|
jid = nick_or_jid;
|
|
|
|
} else {
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __(
|
2020-04-19 06:49:03 +02:00
|
|
|
"Couldn't find a participant with that nickname. "+
|
|
|
|
"They might have left the groupchat."
|
2020-04-19 08:03:44 +02:00
|
|
|
);
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2020-04-19 06:49:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-26 17:53:32 +02:00
|
|
|
}
|
2020-04-19 06:49:03 +02:00
|
|
|
const attrs = { jid, reason };
|
|
|
|
if (occupant && _converse.auto_register_muc_nickname) {
|
2019-05-26 17:53:32 +02:00
|
|
|
attrs['nick'] = occupant.get('nick');
|
|
|
|
}
|
|
|
|
this.model.setAffiliation(affiliation, [attrs])
|
|
|
|
.then(() => this.model.occupants.fetchMembers())
|
|
|
|
.catch(err => this.onCommandError(err));
|
|
|
|
},
|
|
|
|
|
|
|
|
getReason (args) {
|
|
|
|
return args.includes(',') ? args.slice(args.indexOf(',')+1).trim() : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
setRole (command, args, required_affiliations=[], required_roles=[]) {
|
|
|
|
/* Check that a command to change a groupchat user's role or
|
|
|
|
* affiliation has anough arguments.
|
|
|
|
*/
|
|
|
|
const role = COMMAND_TO_ROLE[command];
|
|
|
|
if (!role) {
|
|
|
|
throw Error(`ChatRoomView#setRole called with invalid command: ${command}`);
|
|
|
|
}
|
|
|
|
if (!this.verifyAffiliations(required_affiliations) || !this.verifyRoles(required_roles)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!this.validateRoleOrAffiliationChangeArgs(command, args)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-18 12:36:16 +02:00
|
|
|
const nick_or_jid = this.getNickOrJIDFromCommandArgs(args);
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!nick_or_jid) {
|
2018-10-23 03:41:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-27 12:24:46 +02:00
|
|
|
const reason = args.split(nick_or_jid, 2)[1].trim();
|
2019-05-26 17:53:32 +02:00
|
|
|
// We're guaranteed to have an occupant due to getNickOrJIDFromCommandArgs
|
|
|
|
const occupant = this.model.getOccupant(nick_or_jid);
|
|
|
|
this.model.setRole(occupant, role, reason, undefined, this.onCommandError.bind(this));
|
2018-10-23 03:41:38 +02:00
|
|
|
return true;
|
|
|
|
},
|
2018-05-30 16:55:14 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
onCommandError (err) {
|
2019-11-06 11:01:34 +01:00
|
|
|
log.fatal(err);
|
2020-04-19 08:03:44 +02:00
|
|
|
const message =
|
2020-01-16 13:01:57 +01:00
|
|
|
__("Sorry, an error happened while running the command.") + " " +
|
2020-04-19 08:03:44 +02:00
|
|
|
__("Check your browser's developer console for details.");
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-08-09 13:07:32 +02:00
|
|
|
|
2019-07-04 14:12:12 +02:00
|
|
|
getAllowedCommands () {
|
2020-01-16 14:20:33 +01:00
|
|
|
let allowed_commands = ['clear', 'help', 'me', 'nick', 'register'];
|
2020-01-17 14:50:25 +01:00
|
|
|
if (this.model.config.get('changesubject') || ['owner', 'admin'].includes(this.model.getOwnAffiliation())) {
|
2020-01-16 14:20:33 +01:00
|
|
|
allowed_commands = [...allowed_commands, ...['subject', 'topic']];
|
|
|
|
}
|
2019-07-04 14:12:12 +02:00
|
|
|
const occupant = this.model.occupants.findWhere({'jid': _converse.bare_jid});
|
|
|
|
if (this.verifyAffiliations(['owner'], occupant, false)) {
|
|
|
|
allowed_commands = allowed_commands.concat(OWNER_COMMANDS).concat(ADMIN_COMMANDS);
|
|
|
|
} else if (this.verifyAffiliations(['admin'], occupant, false)) {
|
|
|
|
allowed_commands = allowed_commands.concat(ADMIN_COMMANDS);
|
|
|
|
}
|
|
|
|
if (this.verifyRoles(['moderator'], occupant, false)) {
|
|
|
|
allowed_commands = allowed_commands.concat(MODERATOR_COMMANDS).concat(VISITOR_COMMANDS);
|
|
|
|
} else if (!this.verifyRoles(['visitor', 'participant', 'moderator'], occupant, false)) {
|
|
|
|
allowed_commands = allowed_commands.concat(VISITOR_COMMANDS);
|
|
|
|
}
|
2020-01-16 14:20:33 +01:00
|
|
|
allowed_commands.sort();
|
2020-02-21 13:21:25 +01:00
|
|
|
|
|
|
|
if (Array.isArray(_converse.muc_disable_slash_commands)) {
|
|
|
|
return allowed_commands.filter(c => !_converse.muc_disable_slash_commands.includes(c));
|
|
|
|
} else {
|
|
|
|
return allowed_commands;
|
|
|
|
}
|
2019-07-04 14:12:12 +02:00
|
|
|
},
|
|
|
|
|
2020-04-15 09:13:50 +02:00
|
|
|
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);
|
2020-02-22 20:14:12 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
parseMessageForCommands (text) {
|
2019-05-14 11:38:41 +02:00
|
|
|
if (_converse.muc_disable_slash_commands && !Array.isArray(_converse.muc_disable_slash_commands)) {
|
2018-12-10 15:38:41 +01:00
|
|
|
return _converse.ChatBoxView.prototype.parseMessageForCommands.apply(this, arguments);
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2019-05-26 17:53:32 +02:00
|
|
|
text = text.replace(/^\s*/, "");
|
|
|
|
const command = (text.match(/^\/([a-zA-Z]*) ?/) || ['']).pop().toLowerCase();
|
|
|
|
if (!command) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-04 14:12:12 +02:00
|
|
|
const args = text.slice(('/'+command).length+1).trim();
|
2020-02-21 13:21:25 +01:00
|
|
|
const disabled_commands = Array.isArray(_converse.muc_disable_slash_commands) ?
|
|
|
|
_converse.muc_disable_slash_commands : [];
|
2020-01-17 13:56:58 +01:00
|
|
|
const allowed_commands = this.getAllowedCommands();
|
|
|
|
if (!allowed_commands.includes(command)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-14 20:31:43 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
switch (command) {
|
2019-04-25 10:34:17 +02:00
|
|
|
case 'admin': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setAffiliation(command, args, ['owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'ban': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setAffiliation(command, args, ['admin', 'owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
2019-07-04 14:12:12 +02:00
|
|
|
case 'modtools': {
|
|
|
|
this.showModeratorToolsModal(args);
|
|
|
|
break;
|
|
|
|
}
|
2019-04-25 10:34:17 +02:00
|
|
|
case 'deop': {
|
|
|
|
// FIXME: /deop only applies to setting a moderators
|
|
|
|
// role to "participant" (which only admin/owner can
|
|
|
|
// do). Moderators can however set non-moderator's role
|
|
|
|
// to participant (e.g. visitor => participant).
|
|
|
|
// Currently we don't distinguish between these two
|
|
|
|
// cases.
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setRole(command, args, ['admin', 'owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'destroy': {
|
2019-05-26 17:53:32 +02:00
|
|
|
if (!this.verifyAffiliations(['owner'])) {
|
2018-12-22 18:27:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-04-15 09:13:50 +02:00
|
|
|
this.destroy().catch(e => this.onCommandError(e));
|
2018-12-22 18:27:07 +01:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'help': {
|
|
|
|
this.showHelpMessages([`<strong>${__("You can run the following commands")}</strong>`]);
|
|
|
|
this.showHelpMessages([
|
2018-10-23 03:41:38 +02:00
|
|
|
`<strong>/admin</strong>: ${__("Change user's affiliation to admin")}`,
|
2019-06-25 16:50:02 +02:00
|
|
|
`<strong>/ban</strong>: ${__('Ban user by changing their affiliation to outcast')}`,
|
2019-04-25 10:34:17 +02:00
|
|
|
`<strong>/clear</strong>: ${__('Clear the chat area')}`,
|
2019-11-15 09:41:01 +01:00
|
|
|
`<strong>/close</strong>: ${__('Close this groupchat')}`,
|
2018-10-23 03:41:38 +02:00
|
|
|
`<strong>/deop</strong>: ${__('Change user role to participant')}`,
|
2019-02-22 18:21:26 +01:00
|
|
|
`<strong>/destroy</strong>: ${__('Remove this groupchat')}`,
|
2018-10-23 03:41:38 +02:00
|
|
|
`<strong>/help</strong>: ${__('Show this menu')}`,
|
|
|
|
`<strong>/kick</strong>: ${__('Kick user from groupchat')}`,
|
|
|
|
`<strong>/me</strong>: ${__('Write in 3rd person')}`,
|
|
|
|
`<strong>/member</strong>: ${__('Grant membership to a user')}`,
|
2019-07-04 14:12:12 +02:00
|
|
|
`<strong>/modtools</strong>: ${__('Opens up the moderator tools GUI')}`,
|
2018-10-23 03:41:38 +02:00
|
|
|
`<strong>/mute</strong>: ${__("Remove user's ability to post messages")}`,
|
|
|
|
`<strong>/nick</strong>: ${__('Change your nickname')}`,
|
|
|
|
`<strong>/op</strong>: ${__('Grant moderator role to user')}`,
|
|
|
|
`<strong>/owner</strong>: ${__('Grant ownership of this groupchat')}`,
|
2019-04-25 10:34:17 +02:00
|
|
|
`<strong>/register</strong>: ${__("Register your nickname")}`,
|
2019-06-25 16:50:02 +02:00
|
|
|
`<strong>/revoke</strong>: ${__("Revoke the user's current affiliation")}`,
|
2018-10-23 03:41:38 +02:00
|
|
|
`<strong>/subject</strong>: ${__('Set groupchat subject')}`,
|
|
|
|
`<strong>/topic</strong>: ${__('Set groupchat subject (alias for /subject)')}`,
|
|
|
|
`<strong>/voice</strong>: ${__('Allow muted user to post messages')}`
|
2019-04-25 10:34:17 +02:00
|
|
|
].filter(line => disabled_commands.every(c => (!line.startsWith(c+'<', 9))))
|
|
|
|
.filter(line => allowed_commands.some(c => line.startsWith(c+'<', 9)))
|
|
|
|
);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
} case 'kick': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setRole(command, args, [], ['moderator']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'mute': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setRole(command, args, [], ['moderator']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
case 'member': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setAffiliation(command, args, ['admin', 'owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'nick': {
|
2018-10-23 03:41:38 +02:00
|
|
|
if (!this.verifyRoles(['visitor', 'participant', 'moderator'])) {
|
2018-02-21 22:29:21 +01:00
|
|
|
break;
|
2019-06-11 11:23:42 +02:00
|
|
|
} else if (args.length === 0) {
|
2019-06-11 12:16:27 +02:00
|
|
|
// e.g. Your nickname is "coolguy69"
|
2020-04-19 08:03:44 +02:00
|
|
|
const message = __('Your nickname is "%1$s"', this.model.get('nick'));
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
|
|
|
|
2019-06-11 11:23:42 +02:00
|
|
|
} else {
|
|
|
|
const jid = Strophe.getBareJidFromJid(this.model.get('jid'));
|
2020-03-31 13:15:57 +02:00
|
|
|
api.send($pres({
|
2019-06-11 11:23:42 +02:00
|
|
|
from: _converse.connection.jid,
|
|
|
|
to: `${jid}/${args}`,
|
2019-10-11 15:32:38 +02:00
|
|
|
id: u.getUniqueId()
|
2019-06-11 11:23:42 +02:00
|
|
|
}).tree());
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
case 'owner':
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setAffiliation(command, args, ['owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
case 'op': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setRole(command, args, ['admin', 'owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'register': {
|
2018-10-23 03:41:38 +02:00
|
|
|
if (args.length > 1) {
|
2020-04-19 08:03:44 +02:00
|
|
|
this.model.createMessage({
|
|
|
|
'message': __('Error: invalid number of arguments'),
|
|
|
|
'type': 'error'
|
|
|
|
});
|
2018-10-23 03:41:38 +02:00
|
|
|
} else {
|
|
|
|
this.model.registerNickname().then(err_msg => {
|
2020-04-19 08:03:44 +02:00
|
|
|
err_msg && this.model.createMessage({'message': err_msg, 'type': 'error'});
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
|
|
|
case 'revoke': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setAffiliation(command, args, ['admin', 'owner']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
case 'topic':
|
|
|
|
case 'subject':
|
2019-05-26 17:53:32 +02:00
|
|
|
this.model.setSubject(args);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
case 'voice': {
|
2019-05-26 17:53:32 +02:00
|
|
|
this.setRole(command, args, [], ['moderator']);
|
2018-10-23 03:41:38 +02:00
|
|
|
break;
|
2019-04-25 10:34:17 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
default:
|
2018-12-10 15:38:41 +01:00
|
|
|
return _converse.ChatBoxView.prototype.parseMessageForCommands.apply(this, arguments);
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-03-29 23:47:56 +01:00
|
|
|
/**
|
|
|
|
* Renders a form given an IQ stanza containing the current
|
|
|
|
* groupchat configuration.
|
|
|
|
* Returns a promise which resolves once the user has
|
|
|
|
* either submitted the form, or canceled it.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#renderConfigurationForm
|
|
|
|
* @param { XMLElement } stanza: The IQ stanza containing the groupchat config.
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
renderConfigurationForm (stanza) {
|
2019-04-24 11:03:27 +02:00
|
|
|
this.hideChatRoomContents();
|
|
|
|
this.model.save('config_stanza', stanza.outerHTML);
|
|
|
|
if (!this.config_form) {
|
|
|
|
const { _converse } = this.__super__;
|
|
|
|
this.config_form = new _converse.MUCConfigForm({
|
|
|
|
'model': this.model,
|
|
|
|
'chatroomview': this
|
|
|
|
});
|
|
|
|
const container_el = this.el.querySelector('.chatroom-body');
|
|
|
|
container_el.insertAdjacentElement('beforeend', this.config_form.el);
|
|
|
|
}
|
|
|
|
u.showElement(this.config_form.el);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
|
|
|
* Renders a form which allows the user to choose theirnickname.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#renderNicknameForm
|
|
|
|
*/
|
|
|
|
renderNicknameForm () {
|
|
|
|
const heading = _converse.muc_show_logs_before_join ?
|
|
|
|
__('Choose a nickname to enter') :
|
|
|
|
__('Please choose your nickname');
|
|
|
|
|
2019-12-03 15:02:34 +01:00
|
|
|
const html = tpl_chatroom_nickname_form(Object.assign({
|
2019-11-28 17:01:08 +01:00
|
|
|
heading,
|
|
|
|
'label_nickname': __('Nickname'),
|
|
|
|
'label_join': __('Enter groupchat'),
|
2019-12-03 15:02:34 +01:00
|
|
|
}, this.model.toJSON()));
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
if (_converse.muc_show_logs_before_join) {
|
|
|
|
const container = this.el.querySelector('.muc-bottom-panel');
|
|
|
|
container.innerHTML = html;
|
|
|
|
u.addClass('muc-bottom-panel--nickname', container);
|
|
|
|
} else {
|
|
|
|
this.hideChatRoomContents();
|
|
|
|
const container = this.el.querySelector('.chatroom-body');
|
|
|
|
container.insertAdjacentHTML('beforeend', html);
|
|
|
|
}
|
2019-12-10 15:40:33 +01:00
|
|
|
u.safeSave(this.model.session, {'connection_status': converse.ROOMSTATUS.NICKNAME_REQUIRED});
|
2019-11-28 17:01:08 +01:00
|
|
|
},
|
|
|
|
|
2020-01-26 18:36:25 +01:00
|
|
|
/**
|
|
|
|
* Remove the configuration form without submitting and return to the chat view.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#closeForm
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
closeForm () {
|
2019-04-24 11:03:27 +02:00
|
|
|
sizzle('.chatroom-form-container', this.el).forEach(e => u.addClass('hidden', e));
|
2018-10-23 03:41:38 +02:00
|
|
|
this.renderAfterTransition();
|
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
|
|
|
* Start the process of configuring a groupchat, either by
|
|
|
|
* rendering a configuration form, or by auto-configuring
|
|
|
|
* based on the "roomconfig" data stored on the
|
|
|
|
* {@link _converse.ChatRoom}.
|
|
|
|
* Stores the new configuration on the {@link _converse.ChatRoom}
|
|
|
|
* once completed.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#getAndRenderConfigurationForm
|
|
|
|
* @param { Event } ev - DOM event that might be passed in if this
|
|
|
|
* method is called due to a user action. In this
|
|
|
|
* case, auto-configure won't happen, regardless of
|
|
|
|
* the settings.
|
|
|
|
*/
|
2019-10-09 16:01:38 +02:00
|
|
|
getAndRenderConfigurationForm () {
|
2019-04-24 13:12:00 +02:00
|
|
|
if (!this.config_form || !u.isVisible(this.config_form.el)) {
|
|
|
|
this.showSpinner();
|
|
|
|
this.model.fetchRoomConfiguration()
|
|
|
|
.then(iq => this.renderConfigurationForm(iq))
|
2019-11-06 11:01:34 +01:00
|
|
|
.catch(e => log.error(e));
|
2019-04-24 13:12:00 +02:00
|
|
|
} else {
|
|
|
|
this.closeForm();
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
hideChatRoomContents () {
|
2019-11-28 17:01:08 +01:00
|
|
|
const container_el = this.el.querySelector('.chatroom-body');
|
|
|
|
if (container_el !== null) {
|
|
|
|
[].forEach.call(container_el.children, child => child.classList.add('hidden'));
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-06-11 12:16:27 +02:00
|
|
|
renderPasswordForm () {
|
2019-04-24 11:03:27 +02:00
|
|
|
this.hideChatRoomContents();
|
2019-06-11 12:16:27 +02:00
|
|
|
const message = this.model.get('password_validation_message');
|
|
|
|
this.model.save('password_validation_message', undefined);
|
|
|
|
|
2019-04-24 11:03:27 +02:00
|
|
|
if (!this.password_form) {
|
|
|
|
this.password_form = new _converse.MUCPasswordForm({
|
2019-09-19 16:54:55 +02:00
|
|
|
'model': new Model({
|
2019-06-16 12:14:29 +02:00
|
|
|
'validation_message': message
|
|
|
|
}),
|
2019-04-25 08:35:44 +02:00
|
|
|
'chatroomview': this,
|
2019-04-24 11:03:27 +02:00
|
|
|
});
|
|
|
|
const container_el = this.el.querySelector('.chatroom-body');
|
|
|
|
container_el.insertAdjacentElement('beforeend', this.password_form.el);
|
|
|
|
} else {
|
2019-06-11 12:16:27 +02:00
|
|
|
this.password_form.model.set('validation_message', message);
|
2019-04-24 11:03:27 +02:00
|
|
|
}
|
|
|
|
u.showElement(this.password_form.el);
|
2019-12-10 15:40:33 +01:00
|
|
|
this.model.session.save('connection_status', converse.ROOMSTATUS.PASSWORD_REQUIRED);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2019-06-11 12:16:27 +02:00
|
|
|
showDestroyedMessage () {
|
2018-10-23 03:41:38 +02:00
|
|
|
u.hideElement(this.el.querySelector('.chat-area'));
|
|
|
|
u.hideElement(this.el.querySelector('.occupants'));
|
2019-05-14 11:38:41 +02:00
|
|
|
sizzle('.spinner', this.el).forEach(u.removeElement);
|
|
|
|
|
2019-06-11 12:16:27 +02:00
|
|
|
const reason = this.model.get('destroyed_reason');
|
|
|
|
const moved_jid = this.model.get('moved_jid');
|
|
|
|
this.model.save({
|
|
|
|
'destroyed_reason': undefined,
|
|
|
|
'moved_jid': undefined
|
|
|
|
});
|
2018-10-23 03:41:38 +02:00
|
|
|
const container = this.el.querySelector('.disconnect-container');
|
|
|
|
container.innerHTML = tpl_chatroom_destroyed({
|
|
|
|
'__':__,
|
|
|
|
'jid': moved_jid,
|
|
|
|
'reason': reason ? `"${reason}"` : null
|
|
|
|
});
|
|
|
|
const switch_el = container.querySelector('a.switch-chat');
|
|
|
|
if (switch_el) {
|
2019-12-08 20:42:09 +01:00
|
|
|
switch_el.addEventListener('click', async ev => {
|
2018-10-23 03:41:38 +02:00
|
|
|
ev.preventDefault();
|
2020-03-31 13:15:57 +02:00
|
|
|
const room = await api.rooms.get(moved_jid, null, true);
|
2019-12-08 20:42:09 +01:00
|
|
|
room.maybeShow(true);
|
|
|
|
this.model.destroy();
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
u.showElement(container);
|
|
|
|
},
|
2018-10-10 22:28:32 +02:00
|
|
|
|
2019-06-11 12:16:27 +02:00
|
|
|
showDisconnectMessage () {
|
|
|
|
const message = this.model.get('disconnection_message');
|
|
|
|
if (!message) {
|
|
|
|
return;
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
u.hideElement(this.el.querySelector('.chat-area'));
|
|
|
|
u.hideElement(this.el.querySelector('.occupants'));
|
2019-05-14 11:38:41 +02:00
|
|
|
sizzle('.spinner', this.el).forEach(u.removeElement);
|
2019-06-11 12:16:27 +02:00
|
|
|
|
|
|
|
const messages = [message];
|
|
|
|
const actor = this.model.get('disconnection_actor');
|
|
|
|
if (actor) {
|
|
|
|
messages.push(__('This action was done by %1$s.', actor));
|
|
|
|
}
|
|
|
|
const reason = this.model.get('disconnection_reason');
|
|
|
|
if (reason) {
|
|
|
|
messages.push(__('The reason given is: "%1$s".', reason));
|
|
|
|
}
|
|
|
|
this.model.save({
|
|
|
|
'disconnection_message': undefined,
|
|
|
|
'disconnection_reason': undefined,
|
|
|
|
'disconnection_actor': undefined
|
|
|
|
});
|
2018-10-23 03:41:38 +02:00
|
|
|
const container = this.el.querySelector('.disconnect-container');
|
2020-01-21 11:08:59 +01:00
|
|
|
container.innerHTML = tpl_chatroom_disconnect({messages})
|
2018-10-23 03:41:38 +02:00
|
|
|
u.showElement(container);
|
|
|
|
},
|
|
|
|
|
2019-12-18 11:57:31 +01:00
|
|
|
removeEmptyHistoryFeedback () {
|
2020-03-24 13:41:13 +01:00
|
|
|
const el = this.msgs_container.firstElementChild;
|
2020-02-20 13:04:19 +01:00
|
|
|
if (_converse.muc_show_logs_before_join && el && el.matches('.empty-history-feedback')) {
|
2020-03-24 13:41:13 +01:00
|
|
|
this.msgs_container.removeChild(this.msgs_container.firstElementChild);
|
2019-11-28 17:01:08 +01:00
|
|
|
}
|
2019-12-18 11:57:31 +01:00
|
|
|
},
|
|
|
|
|
2019-12-18 12:42:40 +01:00
|
|
|
insertDayIndicator () {
|
2019-12-18 11:57:31 +01:00
|
|
|
this.removeEmptyHistoryFeedback();
|
|
|
|
return _converse.ChatBoxView.prototype.insertDayIndicator.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
insertMessage (view) {
|
|
|
|
this.removeEmptyHistoryFeedback();
|
2019-11-28 17:01:08 +01:00
|
|
|
return _converse.ChatBoxView.prototype.insertMessage.call(this, view);
|
|
|
|
},
|
|
|
|
|
2019-05-14 13:54:19 +02:00
|
|
|
insertNotification (message) {
|
2019-12-18 11:57:31 +01:00
|
|
|
this.removeEmptyHistoryFeedback();
|
2020-03-24 13:41:13 +01:00
|
|
|
this.msgs_container.insertAdjacentHTML(
|
2019-05-14 13:54:19 +02:00
|
|
|
'beforeend',
|
|
|
|
tpl_info({
|
|
|
|
'isodate': (new Date()).toISOString(),
|
|
|
|
'extra_classes': 'chat-event',
|
|
|
|
'message': message
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
onOccupantAdded (occupant) {
|
2019-07-10 09:47:13 +02:00
|
|
|
if (occupant.get('jid') === _converse.bare_jid) {
|
|
|
|
this.renderHeading();
|
2019-07-12 13:50:39 +02:00
|
|
|
this.renderBottomPanel();
|
2019-07-10 09:47:13 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-10-11 14:04:47 +02:00
|
|
|
|
2019-06-17 21:42:55 +02:00
|
|
|
/**
|
2019-06-26 17:52:45 +02:00
|
|
|
* Working backwards, get today's most recent join/leave notification
|
|
|
|
* from the same user (if any exists) after the most recent chat message.
|
2019-06-17 21:42:55 +02:00
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#getPreviousJoinOrLeaveNotification
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {string} nick
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
getPreviousJoinOrLeaveNotification (el, nick) {
|
2019-06-26 17:52:45 +02:00
|
|
|
const today = (new Date()).toISOString().split('T')[0];
|
|
|
|
while (el !== null) {
|
|
|
|
if (!el.classList.contains('chat-info')) {
|
2018-07-31 13:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-26 17:52:45 +02:00
|
|
|
// Check whether el is still from today.
|
|
|
|
// We don't use `Dayjs.same` here, since it's about 4 times slower.
|
|
|
|
const date = el.getAttribute('data-isodate');
|
|
|
|
if (date && date.split('T')[0] !== today) {
|
|
|
|
return;
|
2018-10-13 13:23:55 +02:00
|
|
|
}
|
2020-03-24 12:26:34 +01:00
|
|
|
const data = el?.dataset || {};
|
2018-10-23 03:41:38 +02:00
|
|
|
if (data.join === nick ||
|
|
|
|
data.leave === nick ||
|
|
|
|
data.leavejoin === nick ||
|
|
|
|
data.joinleave === nick) {
|
|
|
|
return el;
|
2018-04-08 19:44:53 +02:00
|
|
|
}
|
2019-06-19 11:04:09 +02:00
|
|
|
el = el.previousElementSibling;
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
|
|
|
* Rerender the groupchat after some kind of transition. For
|
|
|
|
* example after the spinner has been removed or after a
|
|
|
|
* form has been submitted and removed.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#renderAfterTransition
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
renderAfterTransition () {
|
2019-12-10 15:40:33 +01:00
|
|
|
const conn_status = this.model.session.get('connection_status')
|
|
|
|
if (conn_status == converse.ROOMSTATUS.NICKNAME_REQUIRED) {
|
2019-11-28 17:01:08 +01:00
|
|
|
this.renderNicknameForm();
|
2019-12-10 15:40:33 +01:00
|
|
|
} else if (conn_status == converse.ROOMSTATUS.PASSWORD_REQUIRED) {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.renderPasswordForm();
|
2019-12-10 15:40:33 +01:00
|
|
|
} else if (conn_status == converse.ROOMSTATUS.ENTERED) {
|
2019-07-10 09:47:13 +02:00
|
|
|
this.hideChatRoomContents();
|
2019-05-15 14:47:04 +02:00
|
|
|
u.showElement(this.el.querySelector('.chat-area'));
|
|
|
|
u.showElement(this.el.querySelector('.occupants'));
|
2019-06-19 11:04:09 +02:00
|
|
|
this.scrollDown();
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
showSpinner () {
|
2019-05-14 11:38:41 +02:00
|
|
|
sizzle('.spinner', this.el).forEach(u.removeElement);
|
2019-04-24 11:03:27 +02:00
|
|
|
this.hideChatRoomContents();
|
2018-10-23 03:41:38 +02:00
|
|
|
const container_el = this.el.querySelector('.chatroom-body');
|
|
|
|
container_el.insertAdjacentHTML('afterbegin', tpl_spinner());
|
|
|
|
},
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
|
|
|
* Check if the spinner is being shown and if so, hide it.
|
|
|
|
* Also make sure then that the chat area and occupants
|
|
|
|
* list are both visible.
|
|
|
|
* @private
|
|
|
|
* @method _converse.ChatRoomView#hideSpinner
|
|
|
|
*/
|
2018-10-23 03:41:38 +02:00
|
|
|
hideSpinner () {
|
|
|
|
const spinner = this.el.querySelector('.spinner');
|
2019-08-05 01:39:57 +02:00
|
|
|
if (spinner !== null) {
|
2018-10-23 03:41:38 +02:00
|
|
|
u.removeElement(spinner);
|
|
|
|
this.renderAfterTransition();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2018-02-21 22:29:21 +01:00
|
|
|
|
|
|
|
|
2019-11-28 17:01:08 +01:00
|
|
|
/**
|
2019-09-19 16:54:55 +02:00
|
|
|
* View which renders MUC section of the control box.
|
2019-11-28 17:01:08 +01:00
|
|
|
* @class
|
|
|
|
* @namespace _converse.RoomsPanel
|
|
|
|
* @memberOf _converse
|
|
|
|
*/
|
2019-09-19 16:54:55 +02:00
|
|
|
_converse.RoomsPanel = View.extend({
|
2018-10-23 03:41:38 +02:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'controlbox-section',
|
|
|
|
id: 'chatrooms',
|
|
|
|
events: {
|
2018-11-07 11:09:41 +01:00
|
|
|
'click a.controlbox-heading__btn.show-add-muc-modal': 'showAddRoomModal',
|
|
|
|
'click a.controlbox-heading__btn.show-list-muc-modal': 'showListRoomsModal'
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
|
|
|
this.el.innerHTML = tpl_room_panel({
|
|
|
|
'heading_chatrooms': __('Groupchats'),
|
|
|
|
'title_new_room': __('Add a new groupchat'),
|
|
|
|
'title_list_rooms': __('Query for groupchats')
|
|
|
|
});
|
|
|
|
return this;
|
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
showAddRoomModal (ev) {
|
2019-07-29 10:19:05 +02:00
|
|
|
if (this.add_room_modal === undefined) {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.add_room_modal = new _converse.AddChatRoomModal({'model': this.model});
|
2018-02-21 22:29:21 +01:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
this.add_room_modal.show(ev);
|
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
showListRoomsModal(ev) {
|
2019-07-29 10:19:05 +02:00
|
|
|
if (this.list_rooms_modal === undefined) {
|
2018-10-23 03:41:38 +02:00
|
|
|
this.list_rooms_modal = new _converse.ListChatRoomsModal({'model': this.model});
|
|
|
|
}
|
|
|
|
this.list_rooms_modal.show(ev);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-30 12:57:11 +01:00
|
|
|
_converse.MUCConfigForm = View.extend({
|
2020-01-26 18:36:25 +01:00
|
|
|
className: 'chatroom-form-container muc-config-form',
|
2019-04-24 11:03:27 +02:00
|
|
|
|
|
|
|
initialize (attrs) {
|
|
|
|
this.chatroomview = attrs.chatroomview;
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.chatroomview.model.features, 'change:passwordprotected', this.render);
|
|
|
|
this.listenTo(this.chatroomview.model.features, 'change:config_stanza', this.render);
|
2019-04-24 11:03:27 +02:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
|
|
|
const stanza = u.toStanza(this.model.get('config_stanza'));
|
|
|
|
const whitelist = _converse.roomconfig_whitelist;
|
|
|
|
let fields = sizzle('field', stanza);
|
|
|
|
if (whitelist.length) {
|
2020-01-21 11:08:59 +01:00
|
|
|
fields = fields.filter(f => whitelist.includes(f.getAttribute('var')));
|
2019-04-24 11:03:27 +02:00
|
|
|
}
|
|
|
|
const password_protected = this.model.features.get('passwordprotected');
|
|
|
|
const options = {
|
|
|
|
'new_password': !password_protected,
|
|
|
|
'fixed_username': this.model.get('jid')
|
|
|
|
};
|
2020-01-26 18:36:25 +01:00
|
|
|
return tpl_muc_config_form({
|
|
|
|
'closeConfigForm': ev => this.closeConfigForm(ev),
|
|
|
|
'fields': fields.map(f => u.xForm2webForm(f, stanza, options)),
|
2020-03-24 12:26:34 +01:00
|
|
|
'instructions': stanza.querySelector('instructions')?.textContent,
|
2020-01-26 18:36:25 +01:00
|
|
|
'submitConfigForm': ev => this.submitConfigForm(ev),
|
2020-03-24 12:26:34 +01:00
|
|
|
'title': stanza.querySelector('title')?.textContent
|
2019-04-24 11:03:27 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-16 13:01:57 +01:00
|
|
|
async submitConfigForm (ev) {
|
2019-04-24 11:03:27 +02:00
|
|
|
ev.preventDefault();
|
2020-01-16 13:01:57 +01:00
|
|
|
const inputs = sizzle(':input:not([type=button]):not([type=submit])', ev.target);
|
|
|
|
const configArray = inputs.map(u.webForm2xForm);
|
|
|
|
try {
|
|
|
|
await this.model.sendConfiguration(configArray);
|
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
2020-04-19 08:03:44 +02:00
|
|
|
const message =
|
2020-01-16 13:01:57 +01:00
|
|
|
__("Sorry, an error occurred while trying to submit the config form.") + " " +
|
2020-04-19 08:03:44 +02:00
|
|
|
__("Check your browser's developer console for details.");
|
|
|
|
this.model.createMessage({message, 'type': 'error'});
|
2020-01-16 13:01:57 +01:00
|
|
|
}
|
|
|
|
await this.model.refreshDiscoInfo();
|
2019-04-24 11:03:27 +02:00
|
|
|
this.chatroomview.closeForm();
|
|
|
|
},
|
|
|
|
|
|
|
|
closeConfigForm (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.chatroomview.closeForm();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-30 12:57:11 +01:00
|
|
|
_converse.MUCPasswordForm = View.extend({
|
2020-01-26 18:36:25 +01:00
|
|
|
className: 'chatroom-form-container muc-password-form',
|
2019-04-24 11:03:27 +02:00
|
|
|
|
|
|
|
initialize (attrs) {
|
|
|
|
this.chatroomview = attrs.chatroomview;
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.model, 'change:validation_message', this.render);
|
2019-04-24 11:03:27 +02:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
2020-01-26 18:36:25 +01:00
|
|
|
return tpl_muc_password_form({
|
2019-04-24 11:03:27 +02:00
|
|
|
'jid': this.model.get('jid'),
|
2020-01-26 18:36:25 +01:00
|
|
|
'submitPassword': ev => this.submitPassword(ev),
|
|
|
|
'validation_message': this.model.get('validation_message')
|
2019-04-24 11:03:27 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
submitPassword (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const password = this.el.querySelector('input[type=password]').value;
|
2019-05-20 10:06:37 +02:00
|
|
|
this.chatroomview.model.join(this.chatroomview.model.get('nick'), password);
|
2019-04-25 08:35:44 +02:00
|
|
|
this.model.set('validation_message', null);
|
2019-04-24 11:03:27 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-03-06 11:41:16 +01:00
|
|
|
_converse.MUCInviteModal = BootstrapModal.extend({
|
2020-01-27 13:20:23 +01:00
|
|
|
id: "muc-invite-modal",
|
|
|
|
|
|
|
|
initialize () {
|
2020-03-06 11:41:16 +01:00
|
|
|
BootstrapModal.prototype.initialize.apply(this, arguments);
|
2020-01-27 13:20:23 +01:00
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
this.initInviteWidget();
|
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
|
|
|
return tpl_muc_invite_modal(Object.assign(
|
|
|
|
this.model.toJSON(), {
|
|
|
|
'submitInviteForm': ev => this.submitInviteForm(ev)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
initInviteWidget () {
|
|
|
|
if (this.invite_auto_complete) {
|
|
|
|
this.invite_auto_complete.destroy();
|
|
|
|
}
|
|
|
|
const list = _converse.roster.map(i => ({'label': i.getDisplayName(), 'value': i.get('jid')}));
|
|
|
|
const el = this.el.querySelector('.suggestion-box').parentElement;
|
|
|
|
this.invite_auto_complete = new _converse.AutoComplete(el, {
|
|
|
|
'min_chars': 1,
|
|
|
|
'list': list
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
submitInviteForm (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
// TODO: Add support for sending an invite to multiple JIDs
|
|
|
|
const data = new FormData(ev.target);
|
|
|
|
const jid = data.get('invitee_jids');
|
|
|
|
const reason = data.get('reason');
|
|
|
|
if (u.isValidJID(jid)) {
|
|
|
|
// TODO: Create and use API here
|
|
|
|
this.chatroomview.model.directInvite(jid, reason);
|
|
|
|
this.modal.hide();
|
|
|
|
} else {
|
|
|
|
this.model.set({'invalid_invite_jid': true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-30 12:57:11 +01:00
|
|
|
_converse.MUCSidebar = View.extend({
|
2018-10-23 03:41:38 +02:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'occupants col-md-3 col-4',
|
|
|
|
|
2019-05-14 20:38:25 +02:00
|
|
|
async initialize () {
|
2020-01-26 18:36:25 +01:00
|
|
|
this.chatroomview = this.model.chatroomview;
|
|
|
|
this.listenTo(this.model, 'add', this.render);
|
|
|
|
this.listenTo(this.model, 'remove', this.render);
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
this.listenTo(this.chatroomview.model.features, 'change', this.render);
|
2019-09-06 14:34:59 +02:00
|
|
|
this.listenTo(this.chatroomview.model, 'change:hidden_occupants', this.setVisibility);
|
2018-10-23 03:41:38 +02:00
|
|
|
this.render();
|
2019-05-14 20:38:25 +02:00
|
|
|
await this.model.fetched;
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2020-01-26 18:36:25 +01:00
|
|
|
toHTML () {
|
|
|
|
return tpl_muc_sidebar(
|
2019-04-29 09:07:15 +02:00
|
|
|
Object.assign(this.chatroomview.model.toJSON(), {
|
2020-01-30 21:59:51 +01:00
|
|
|
_converse,
|
2020-01-26 18:36:25 +01:00
|
|
|
'features': this.chatroomview.model.features,
|
2020-02-10 11:23:55 +01:00
|
|
|
'occupants': this.model.models
|
2018-10-23 03:41:38 +02:00
|
|
|
})
|
|
|
|
);
|
2020-01-26 18:36:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
afterRender () {
|
2019-05-15 14:47:04 +02:00
|
|
|
this.setVisibility();
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-05-15 14:47:04 +02:00
|
|
|
setVisibility () {
|
|
|
|
if (this.chatroomview.model.get('hidden_occupants')) {
|
|
|
|
u.hideElement(this.el);
|
|
|
|
} else {
|
|
|
|
u.showElement(this.el);
|
|
|
|
this.setOccupantsHeight();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
setOccupantsHeight () {
|
2020-01-27 13:20:23 +01:00
|
|
|
// TODO: remove the features section in sidebar and then this as well
|
2018-10-23 03:41:38 +02:00
|
|
|
const el = this.el.querySelector('.chatroom-features');
|
2020-01-26 18:36:25 +01:00
|
|
|
if (el) {
|
|
|
|
this.el.querySelector('.occupant-list').style.cssText =
|
|
|
|
`height: calc(100% - ${el.offsetHeight}px - 5em);`;
|
|
|
|
}
|
2020-01-27 13:20:23 +01:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
2018-02-21 22:29:21 +01:00
|
|
|
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
function setMUCDomain (domain, controlboxview) {
|
2019-09-11 11:28:28 +02:00
|
|
|
controlboxview.getRoomsPanel().model.save('muc_domain', Strophe.getDomainFromJid(domain));
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
function setMUCDomainFromDisco (controlboxview) {
|
|
|
|
/* Check whether service discovery for the user's domain
|
|
|
|
* returned MUC information and use that to automatically
|
|
|
|
* set the MUC domain in the "Add groupchat" modal.
|
|
|
|
*/
|
|
|
|
function featureAdded (feature) {
|
|
|
|
if (!feature) { return; }
|
|
|
|
if (feature.get('var') === Strophe.NS.MUC) {
|
|
|
|
feature.entity.getIdentity('conference', 'text').then(identity => {
|
|
|
|
if (identity) {
|
|
|
|
setMUCDomain(feature.get('from'), controlboxview);
|
|
|
|
}
|
|
|
|
});
|
2018-02-21 22:29:21 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-31 13:15:57 +02:00
|
|
|
api.waitUntil('discoInitialized').then(() => {
|
|
|
|
api.listen.on('serviceDiscovered', featureAdded);
|
2018-10-23 03:41:38 +02:00
|
|
|
// Features could have been added before the controlbox was
|
|
|
|
// initialized. We're only interested in MUC
|
|
|
|
_converse.disco_entities.each(entity => featureAdded(entity.features.findWhere({'var': Strophe.NS.MUC })));
|
2019-11-06 11:01:34 +01:00
|
|
|
}).catch(e => log.error(e));
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
function fetchAndSetMUCDomain (controlboxview) {
|
|
|
|
if (controlboxview.model.get('connected')) {
|
2019-09-11 11:28:28 +02:00
|
|
|
if (!controlboxview.getRoomsPanel().model.get('muc_domain')) {
|
2019-07-29 10:19:05 +02:00
|
|
|
if (_converse.muc_domain === undefined) {
|
2018-10-23 03:41:38 +02:00
|
|
|
setMUCDomainFromDisco(controlboxview);
|
|
|
|
} else {
|
|
|
|
setMUCDomain(_converse.muc_domain, controlboxview);
|
2018-02-21 22:29:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
2018-02-21 22:29:21 +01:00
|
|
|
|
2019-06-05 14:43:59 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
/************************ BEGIN Event Handlers ************************/
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('chatBoxViewsInitialized', () => {
|
2018-10-13 20:55:05 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
function openChatRoomFromURIClicked (ev) {
|
|
|
|
ev.preventDefault();
|
2020-03-31 13:15:57 +02:00
|
|
|
api.rooms.open(ev.target.href);
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
_converse.chatboxviews.delegate('click', 'a.open-chatroom', openChatRoomFromURIClicked);
|
2018-08-28 14:58:33 +02:00
|
|
|
|
2019-11-08 09:49:58 +01:00
|
|
|
async function addView (model) {
|
2019-06-05 14:43:59 +02:00
|
|
|
const views = _converse.chatboxviews;
|
|
|
|
if (!views.get(model.get('id')) &&
|
|
|
|
model.get('type') === _converse.CHATROOMS_TYPE &&
|
|
|
|
model.isValid()
|
|
|
|
) {
|
2019-11-08 09:49:58 +01:00
|
|
|
await model.initialized;
|
|
|
|
return views.add(model.get('id'), new _converse.ChatRoomView({model}));
|
2018-02-21 22:29:21 +01:00
|
|
|
}
|
2019-06-05 14:43:59 +02:00
|
|
|
}
|
|
|
|
_converse.chatboxes.on('add', addView);
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
2018-05-02 15:29:06 +02:00
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('clearSession', () => {
|
2019-02-20 22:58:59 +01:00
|
|
|
const view = _converse.chatboxviews.get('controlbox');
|
|
|
|
if (view && view.roomspanel) {
|
2019-08-01 10:26:35 +02:00
|
|
|
view.roomspanel.model.destroy();
|
2019-02-20 22:58:59 +01:00
|
|
|
view.roomspanel.remove();
|
|
|
|
delete view.roomspanel;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('controlBoxInitialized', (view) => {
|
2018-10-23 03:41:38 +02:00
|
|
|
if (!_converse.allow_muc) {
|
|
|
|
return;
|
2018-05-02 15:29:06 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
fetchAndSetMUCDomain(view);
|
2019-09-07 22:00:28 +02:00
|
|
|
view.model.on('change:connected', () => fetchAndSetMUCDomain(view));
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
|
|
|
/************************ END Event Handlers ************************/
|
|
|
|
|
|
|
|
|
|
|
|
/************************ BEGIN API ************************/
|
2019-04-29 09:07:15 +02:00
|
|
|
Object.assign(_converse.api, {
|
2018-10-23 03:41:38 +02:00
|
|
|
/**
|
|
|
|
* The "roomviews" namespace groups methods relevant to chatroom
|
|
|
|
* (aka groupchats) views.
|
|
|
|
*
|
|
|
|
* @namespace _converse.api.roomviews
|
|
|
|
* @memberOf _converse.api
|
|
|
|
*/
|
2019-09-24 15:33:41 +02:00
|
|
|
roomviews: {
|
2018-11-21 14:57:49 +01:00
|
|
|
/**
|
|
|
|
* Retrieves a groupchat (aka chatroom) view. The chat should already be open.
|
|
|
|
*
|
|
|
|
* @method _converse.api.roomviews.get
|
|
|
|
* @param {String|string[]} name - e.g. 'coven@conference.shakespeare.lit' or
|
|
|
|
* ['coven@conference.shakespeare.lit', 'cave@conference.shakespeare.lit']
|
2020-01-26 18:36:25 +01:00
|
|
|
* @returns {View} View representing the groupchat
|
2018-11-21 14:57:49 +01:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // To return a single view, provide the JID of the groupchat
|
|
|
|
* const view = _converse.api.roomviews.get('coven@conference.shakespeare.lit');
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // To return an array of views, provide an array of JIDs:
|
|
|
|
* const views = _converse.api.roomviews.get(['coven@conference.shakespeare.lit', 'cave@conference.shakespeare.lit']);
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* // To return views of all open groupchats, call the method without any parameters::
|
|
|
|
* const views = _converse.api.roomviews.get();
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
get (jids) {
|
2019-05-14 11:38:41 +02:00
|
|
|
if (Array.isArray(jids)) {
|
2020-03-31 13:15:57 +02:00
|
|
|
const views = api.chatviews.get(jids);
|
2018-11-21 14:57:49 +01:00
|
|
|
return views.filter(v => v.model.get('type') === _converse.CHATROOMS_TYPE)
|
|
|
|
} else {
|
2020-03-31 13:15:57 +02:00
|
|
|
const view = api.chatviews.get(jids);
|
2018-11-21 14:57:49 +01:00
|
|
|
if (view.model.get('type') === _converse.CHATROOMS_TYPE) {
|
|
|
|
return view;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-09-02 15:07:14 +02:00
|
|
|
/**
|
2018-10-23 03:41:38 +02:00
|
|
|
* Lets you close open chatrooms.
|
|
|
|
*
|
|
|
|
* You can call this method without any arguments to close
|
|
|
|
* all open chatrooms, or you can specify a single JID or
|
|
|
|
* an array of JIDs.
|
2018-09-02 15:07:14 +02:00
|
|
|
*
|
2018-10-23 03:41:38 +02:00
|
|
|
* @method _converse.api.roomviews.close
|
|
|
|
* @param {(String[]|String)} jids The JID or array of JIDs of the chatroom(s)
|
2019-10-24 14:29:15 +02:00
|
|
|
* @returns { Promise } - Promise which resolves once the views have been closed.
|
2018-09-02 15:07:14 +02:00
|
|
|
*/
|
2019-10-11 20:29:12 +02:00
|
|
|
close (jids) {
|
2019-05-14 11:38:41 +02:00
|
|
|
let views;
|
2019-07-29 10:19:05 +02:00
|
|
|
if (jids === undefined) {
|
2019-05-14 11:38:41 +02:00
|
|
|
views = _converse.chatboxviews;
|
2020-01-21 11:08:59 +01:00
|
|
|
} else if (isString(jids)) {
|
2019-05-14 11:38:41 +02:00
|
|
|
views = [_converse.chatboxviews.get(jids)].filter(v => v);
|
|
|
|
} else if (Array.isArray(jids)) {
|
|
|
|
views = jids.map(jid => _converse.chatboxviews.get(jid));
|
2018-09-02 15:07:14 +02:00
|
|
|
}
|
2019-10-24 14:29:15 +02:00
|
|
|
return Promise.all(views.map(v => (v.is_chatroom && v.model && v.close())))
|
2018-09-02 15:07:14 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|