Skip to content

Commit

Permalink
Set MUC name in roomconfig when only a name was provided in the Add M…
Browse files Browse the repository at this point in the history
…UC modal.
  • Loading branch information
jcbrand committed Feb 12, 2025
1 parent 7527283 commit a3f4a61
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/headless/plugins/muc/muc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
getDiscoInfo () {
return api.disco
.getIdentity('conference', 'text', this.get('jid'))
.then((identity) => this.save({ 'name': identity?.get('name') }))
.then((identity) => this.save({ name: identity?.get('name') }))
.then(() => this.getDiscoInfoFields())
.then(() => this.getDiscoInfoFeatures())
.catch((e) => log.error(e));
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/muc-views/modals/add-muc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export default class AddMUCModal extends BaseModal {
const muc_service = await u.muc.getDefaultMUCService();
if (muc_service) {
settings.name = data.jid;
settings.auto_configure = true;
settings.roomconfig = {
roomname: data.jid,
};
jid = `${this.normalizeNode(data.jid)}@${muc_service}`.toLowerCase();
}
}
Expand Down
82 changes: 79 additions & 3 deletions src/plugins/muc-views/tests/muc-add-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { Promise, sizzle, u } = converse.env;

describe('The "Groupchats" Add modal', function () {

beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));

it('can be opened from a link in the "Groupchats" section of the controlbox',
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
const modal = await mock.openAddMUCModal(_converse);
Expand Down Expand Up @@ -112,25 +114,99 @@ describe('The "Groupchats" Add modal', function () {
[Strophe.NS.DISCO_ITEMS],
);

const nick = 'max';
const muc_jid = '[email protected]';
const own_jid = _converse.session.get('jid');

const modal = await mock.openAddMUCModal(_converse);
spyOn(_converse.ChatRoom.prototype, 'getDiscoInfo').and.callFake(() => Promise.resolve());

const name_input = modal.querySelector('input[name="chatroom"]');
name_input.value = 'The Lounge';

const nick_input = modal.querySelector('input[name="nickname"]');
nick_input.value = 'max';
nick_input.value = nick;

modal.querySelector('form input[type="submit"]').click();

await mock.waitUntilDiscoConfirmed(_converse, domain, [], [], ['muc.example.org'], 'items');
await mock.waitUntilDiscoConfirmed(_converse, 'muc.example.org', [], [Strophe.NS.MUC]);


await u.waitUntil(() => sizzle('.chatroom', _converse.el).filter(u.isVisible).length === 1);
expect(_converse.chatboxes.models.map(m => m.get('id')).includes('[email protected]')).toBe(true);
expect(_converse.chatboxes.models.map(m => m.get('id')).includes(muc_jid)).toBe(true);

const muc = _converse.chatboxes.get('[email protected]');
const muc = _converse.chatboxes.get(muc_jid);
expect(muc.get('name')).toBe('The Lounge');

await mock.getRoomFeatures(_converse, muc_jid);

// Own presence which states that the room is locked and needs to
// be configured (code 201)
const presence =
stx`<presence
id="5025e055-036c-4bc5-a227-706e7e352053"
to="${own_jid}"
from="${muc_jid}/${nick}"
xmlns="jabber:client">
<x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="owner" jid="${own_jid}" role="moderator"/>
<status code="110"/>
<status code="201"/>
</x>
</presence>`;
_converse.api.connection.get()._dataRecv(mock.createRequest(presence));

const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
const iq = await u.waitUntil(() => IQ_stanzas.filter(s => s.querySelector(`query[xmlns="${Strophe.NS.MUC_OWNER}"]`)).pop());

spyOn(muc, 'sendConfiguration').and.callThrough();

expect(iq).toEqualStanza(stx`
<iq id="${iq.getAttribute('id')}" to="${muc_jid}" type="get" xmlns="jabber:client">
<query xmlns="http://jabber.org/protocol/muc#owner"/>
</iq>`);

_converse.api.connection.get()._dataRecv(mock.createRequest(
stx`<iq xmlns="jabber:client"
type="result"
to="${own_jid}"
from="${muc_jid}" id="${iq.getAttribute('id')}">
<query xmlns="http://jabber.org/protocol/muc#owner">
<x xmlns="jabber:x:data" type="form">
<title>Configuration for ${muc_jid}</title>
<instructions>Complete and submit this form to configure the room.</instructions>
<field var="FORM_TYPE" type="hidden">
<value>http://jabber.org/protocol/muc#roomconfig</value>
</field>
<field type="text-single" var="muc#roomconfig_roomname" label="Name"><value></value></field>
<field type="text-single" var="muc#roomconfig_roomdesc" label="Description"><value/></field>
<field type="boolean" var="muc#roomconfig_persistentroom" label="Make Room Persistent?"/>
<field type="boolean" var="muc#roomconfig_publicroom" label="Make Room Publicly Searchable?"><value>1</value></field>
<field type="boolean" var="muc#roomconfig_changesubject" label="Allow Occupants to Change Subject?"/>
<field type="list-single" var="muc#roomconfig_whois" label="Who May Discover Real JIDs?"><option label="Moderators Only">
<value>moderators</value></option><option label="Anyone"><value>anyone</value></option>
</field>
<field label="Roles and Affiliations that May Retrieve Member List"
type="list-multi"
var="muc#roomconfig_getmemberlist">
<value>moderator</value>
<value>participant</value>
<value>visitor</value>
</field>
<field type="text-private" var="muc#roomconfig_roomsecret" label="Password"><value/></field>
<field type="boolean" var="muc#roomconfig_moderatedroom" label="Make Room Moderated?"/>
<field type="boolean" var="muc#roomconfig_membersonly" label="Make Room Members-Only?"/>
<field type="text-single" var="muc#roomconfig_historylength" label="Maximum Number of History Messages Returned by Room">
<value>20</value></field>
</x>
</query>
</iq>`));

await u.waitUntil(() => muc.sendConfiguration.calls.count() === 1);

const sent_stanza = IQ_stanzas.filter(s => s.getAttribute('type') === 'set').pop();
expect(sizzle('field[var="muc#roomconfig_roomname"] value', sent_stanza).pop().textContent.trim()).toBe('The Lounge');
})
);

Expand Down

0 comments on commit a3f4a61

Please sign in to comment.