1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587 |
- /*global mock, converse */
- const { $pres, Strophe, Promise, sizzle, stx, u } = converse.env;
- describe("Groupchats", function () {
- beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));
- describe("An instant groupchat", function () {
- it("will be created when muc_instant_rooms is set to true",
- mock.initConverse(['chatBoxesFetched'], { vcard: { nickname: '' } }, async function (_converse) {
- let IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
- const { api } = _converse;
- const muc_jid = 'lounge@montague.lit';
- const nick = 'nicky';
- const promise = api.rooms.open(muc_jid);
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await mock.waitForReservedNick(_converse, muc_jid, '');
- const muc = await promise;
- await muc.initialized;
- spyOn(muc, 'join').and.callThrough();
- const view = _converse.chatboxviews.get(muc_jid);
- const input = await u.waitUntil(() => view.querySelector('input[name="nick"]'), 1000);
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED);
- input.value = nick;
- view.querySelector('input[type=submit]').click();
- expect(view.model.join).toHaveBeenCalled();
- await mock.waitForNewMUCDiscoInfo(_converse, muc_jid);
- _converse.api.connection.get().IQ_stanzas = [];
- await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
- // The user has just entered the room (because join was called)
- // and receives their own presence from the server.
- // See example 24:
- // https://xmpp.org/extensions/xep-0045.html#enter-pres
- const presence =
- stx`<presence
- id="5025e055-036c-4bc5-a227-706e7e352053"
- to="romeo@montague.lit/orchard"
- from="lounge@montague.lit/nicky"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="owner" jid="romeo@montague.lit/orchard" role="moderator"/>
- <status code="110"/>
- <status code="201"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED);
- await mock.returnMemberLists(_converse, muc_jid);
- const num_info_msgs = await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-info').length);
- expect(num_info_msgs).toBe(1);
- const info_texts = Array.from(view.querySelectorAll('.chat-content .chat-info')).map(e => e.textContent.trim());
- expect(info_texts[0]).toBe('A new groupchat has been created');
- const csntext = await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent);
- expect(csntext.trim()).toEqual("nicky has entered the groupchat");
- // An instant room is created by saving the default configuratoin.
- //
- /* <iq to="myroom@conference.chat.example.org" type="set" xmlns="jabber:client" id="5025e055-036c-4bc5-a227-706e7e352053:sendIQ">
- * <query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query>
- * </iq>
- */
- const selector = `query[xmlns="${Strophe.NS.MUC_OWNER}"]`;
- IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
- const iq = await u.waitUntil(() => IQ_stanzas.filter(s => s.querySelector(selector)).pop());
- expect(Strophe.serialize(iq)).toBe(
- `<iq id="${iq.getAttribute('id')}" to="lounge@montague.lit" type="set" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/muc#owner"><x type="submit" xmlns="jabber:x:data"/>`+
- `</query></iq>`);
- }));
- });
- describe("A Groupchat", function () {
- it("will be visible when opened as the first chat in fullscreen-view",
- mock.initConverse(['discoInitialized'],
- { 'view_mode': 'fullscreen', 'auto_join_rooms': ['orchard@chat.shakespeare.lit']},
- async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'orchard@chat.shakespeare.lit';
- api.rooms.get(muc_jid);
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await mock.waitForReservedNick(_converse, muc_jid, 'romeo');
- await mock.receiveOwnMUCPresence(_converse, muc_jid, 'romeo');
- await api.waitUntil('roomsAutoJoined');
- const room = await u.waitUntil(() => _converse.chatboxes.get(muc_jid));
- expect(room.get('hidden')).toBe(false);
- }));
- it("Can be configured to show cached messages before being joined",
- mock.initConverse(['discoInitialized'],
- {
- muc_show_logs_before_join: true,
- archived_messages_page_size: 2,
- muc_nickname_from_jid: false,
- muc_clear_messages_on_leave: false,
- vcard: { nickname: '' },
- }, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'orchard@chat.shakespeare.lit';
- const nick = 'romeo';
- api.rooms.open(muc_jid);
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await mock.waitForReservedNick(_converse, muc_jid);
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await view.model.messages.fetched;
- view.model.messages.create({
- 'type': 'groupchat',
- 'to': muc_jid,
- 'from': `${_converse.bare_jid}/orchard`,
- 'body': 'Hello world',
- 'message': 'Hello world',
- 'time': '2021-02-02T12:00:00Z'
- });
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED);
- await u.waitUntil(() => view.querySelectorAll('converse-chat-message').length === 1);
- const sel = 'converse-message-history converse-chat-message .chat-msg__text';
- await u.waitUntil(() => view.querySelector(sel)?.textContent.trim());
- expect(view.querySelector(sel).textContent.trim()).toBe('Hello world')
- const nick_input = await u.waitUntil(() => view.querySelector('[name="nick"]'));
- nick_input.value = nick;
- view.querySelector('.muc-nickname-form input[type="submit"]').click();
- _converse.api.connection.get().IQ_stanzas = [];
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
- await mock.receiveOwnMUCPresence(_converse, muc_jid, nick);
- }));
- it("maintains its state across reloads",
- mock.initConverse([], {
- clear_messages_on_reconnection: true,
- enable_smacks: false
- }, async function (_converse) {
- const { api } = _converse;
- const nick = 'romeo';
- const sent_IQs = _converse.api.connection.get().IQ_stanzas;
- const muc_jid = 'lounge@montague.lit'
- await mock.openAndEnterMUC(_converse, muc_jid, nick, [], []);
- const view = _converse.chatboxviews.get(muc_jid);
- let iq_get = await u.waitUntil(() => sent_IQs.filter((iq) => sizzle(`query[xmlns="${Strophe.NS.MAM}"]`, iq).length).pop());
- expect(iq_get).toEqualStanza(stx`
- <iq id="${iq_get.getAttribute('id')}" to="${muc_jid}" type="set" xmlns="jabber:client">
- <query queryid="${iq_get.querySelector('query').getAttribute('queryid')}" xmlns="${Strophe.NS.MAM}">
- <set xmlns="http://jabber.org/protocol/rsm"><before></before><max>50</max></set>
- </query>
- </iq>`);
- const first_msg_id = _converse.api.connection.get().getUniqueId();
- const last_msg_id = _converse.api.connection.get().getUniqueId();
- _converse.api.connection.get()._dataRecv(mock.createRequest(
- stx`<message xmlns="jabber:client"
- to="romeo@montague.lit/orchard"
- from="${muc_jid}">
- <result xmlns="urn:xmpp:mam:2" queryid="${iq_get.querySelector('query').getAttribute('queryid')}" id="${first_msg_id}">
- <forwarded xmlns="urn:xmpp:forward:0">
- <delay xmlns="urn:xmpp:delay" stamp="2018-01-09T06:15:23Z"/>
- <message from="${muc_jid}/some1" type="groupchat">
- <body>1st Message</body>
- </message>
- </forwarded>
- </result>
- </message>`));
- let message = stx`<message xmlns="jabber:client"
- to="romeo@montague.lit/orchard"
- from="${muc_jid}">
- <result xmlns="urn:xmpp:mam:2" queryid="${iq_get.querySelector('query').getAttribute('queryid')}" id="${last_msg_id}">
- <forwarded xmlns="urn:xmpp:forward:0">
- <delay xmlns="urn:xmpp:delay" stamp="2018-01-09T06:16:23Z"/>
- <message from="${muc_jid}/some1" type="groupchat">
- <body>2nd Message</body>
- </message>
- </forwarded>
- </result>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- const result = stx`<iq type='result' id='${iq_get.getAttribute('id')}' xmlns="jabber:client">
- <fin xmlns='urn:xmpp:mam:2' complete="true">
- <set xmlns='http://jabber.org/protocol/rsm'>
- <first index='0'>${first_msg_id}</first>
- <last>${last_msg_id}</last>
- <count>2</count>
- </set>
- </fin>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(result));
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 2);
- while (sent_IQs.length) { sent_IQs.pop(); } // Clear so that we don't match the older query
- await _converse.api.connection.reconnect();
- await mock.waitForMUCDiscoInfo(_converse, muc_jid, []);
- await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
- // The user has just entered the room (because join was called)
- // and receives their own presence from the server.
- // See example 24: https://xmpp.org/extensions/xep-0045.html#enter-pres
- await mock.receiveOwnMUCPresence(_converse, muc_jid, nick);
- message = stx`
- <message xmlns="jabber:client" type="groupchat" id="918172de-d5c5-4da4-b388-446ef4a05bec" to="${_converse.jid}" xml:lang="en" from="${muc_jid}/juliet">
- <body>Wherefore art though?</body>
- <active xmlns="http://jabber.org/protocol/chatstates"/>
- <origin-id xmlns="urn:xmpp:sid:0" id="918172de-d5c5-4da4-b388-446ef4a05bec"/>
- <stanza-id xmlns="urn:xmpp:sid:0" id="88cc9c93-a8f4-4dd5-b02a-d19855eb6303" by="${muc_jid}"/>
- <delay xmlns="urn:xmpp:delay" stamp="2020-07-14T17:46:47Z" from="juliet@shakespeare.lit"/>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- message = stx`
- <message xmlns="jabber:client" type="groupchat" id="awQo6a-mi-Wa6NYh" to="${_converse.jid}" from="${muc_jid}/ews000" xml:lang="en">
- <composing xmlns="http://jabber.org/protocol/chatstates"/>
- <no-store xmlns="urn:xmpp:hints"/>
- <no-permanent-store xmlns="urn:xmpp:hints"/>
- <delay xmlns="urn:xmpp:delay" stamp="2020-07-14T17:46:54Z" from="juliet@shakespeare.lit"/>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- const affs = api.settings.get('muc_fetch_members');
- const all_affiliations = Array.isArray(affs) ? affs : (affs ? ['member', 'admin', 'owner'] : []);
- await mock.returnMemberLists(_converse, muc_jid, [], all_affiliations);
- iq_get = await u.waitUntil(() => sent_IQs.filter(iq => sizzle(`query[xmlns="${Strophe.NS.MAM}"]`, iq).length).pop());
- expect(iq_get).toEqualStanza(stx`
- <iq id="${iq_get.getAttribute('id')}" to="${muc_jid}" type="set" xmlns="jabber:client">
- <query queryid="${iq_get.querySelector('query').getAttribute('queryid')}" xmlns="${Strophe.NS.MAM}">
- <x xmlns="jabber:x:data" type="submit">
- <field type="hidden" var="FORM_TYPE"><value>urn:xmpp:mam:2</value></field>
- <field var="start"><value>2020-07-14T17:46:47.000Z</value></field>
- </x>
- <set xmlns="http://jabber.org/protocol/rsm"><before></before><max>50</max></set>
- </query>
- </iq>`);
- }));
- it("shows a new messages indicator when you're scrolled up",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid, 'romeo');
- const view = _converse.chatboxviews.get(muc_jid);
- const message = stx`
- <message xmlns="jabber:client" type="groupchat" id="918172de-d5c5-4da4-b388-446ef4a05bec" to="${_converse.jid}" xml:lang="en" from="${muc_jid}/juliet">
- <body>Wherefore art though?</body>
- <active xmlns="http://jabber.org/protocol/chatstates"/>
- <origin-id xmlns="urn:xmpp:sid:0" id="918172de-d5c5-4da4-b388-446ef4a05bec"/>
- <stanza-id xmlns="urn:xmpp:sid:0" id="88cc9c93-a8f4-4dd5-b02a-d19855eb6303" by="${muc_jid}"/>
- <delay xmlns="urn:xmpp:delay" stamp="2020-07-14T17:46:47Z" from="juliet@shakespeare.lit"/>
- </message>`;
- view.model.ui.set('scrolled', true); // hack
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- await u.waitUntil(() => view.model.messages.length);
- const chat_new_msgs_indicator = await u.waitUntil(() => view.querySelector('.new-msgs-indicator'));
- chat_new_msgs_indicator.click();
- expect(view.model.ui.get('scrolled')).toBeFalsy();
- await u.waitUntil(() => !u.isVisible(chat_new_msgs_indicator));
- }));
- describe("topic", function () {
- it("is shown the header", mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'jdev@conference.jabber.org', 'jc');
- const text = 'Jabber/XMPP Development | RFCs and Extensions: https://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
- let stanza = stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>${text}</subject>
- <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>
- <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- const view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- await new Promise(resolve => view.model.once('change:subject', resolve));
- const head_desc = await u.waitUntil(() => view.querySelector('.chat-head__desc'), 1000);
- expect(head_desc?.textContent.trim()).toBe(text);
- stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>This is a message subject</subject>
- <body>This is a message</body>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
- expect(sizzle('.chat-msg__subject', view).length).toBe(1);
- expect(sizzle('.chat-msg__subject', view).pop().textContent.trim()).toBe('This is a message subject');
- expect(sizzle('.chat-msg__text').length).toBe(1);
- expect(sizzle('.chat-msg__text').pop().textContent.trim()).toBe('This is a message');
- expect(view.querySelector('.chat-head__desc').textContent.trim()).toBe(text);
- }));
- it("can be toggled by the user", mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'jdev@conference.jabber.org', 'jc');
- const text = 'Jabber/XMPP Development | RFCs and Extensions: https://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
- let stanza = stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>${text}</subject>
- <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>
- <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- const view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- await new Promise(resolve => view.model.once('change:subject', resolve));
- const head_desc = await u.waitUntil(() => view.querySelector('.chat-head__desc'));
- expect(head_desc?.textContent.trim()).toBe(text);
- stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>This is a message subject</subject>
- <body>This is a message</body>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
- expect(sizzle('.chat-msg__subject', view).length).toBe(1);
- expect(sizzle('.chat-msg__subject', view).pop().textContent.trim()).toBe('This is a message subject');
- expect(sizzle('.chat-msg__text').length).toBe(1);
- expect(sizzle('.chat-msg__text').pop().textContent.trim()).toBe('This is a message');
- const topic_el = view.querySelector('.chat-head__desc');
- expect(topic_el.textContent.trim()).toBe(text);
- expect(u.isVisible(topic_el)).toBe(true);
- await u.waitUntil(() => view.querySelector('.hide-topic').textContent.trim() === 'Hide topic');
- const toggle = view.querySelector('.hide-topic');
- expect(toggle.textContent.trim()).toBe('Hide topic');
- toggle.click();
- await u.waitUntil(() => view.querySelector('.hide-topic').textContent.trim() === 'Show topic');
- }));
- it("will always be shown when it's new", mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'jdev@conference.jabber.org', 'jc');
- const text = 'Jabber/XMPP Development | RFCs and Extensions: https://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
- let stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>${text}</subject>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- const view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- await new Promise(resolve => view.model.once('change:subject', resolve));
- const head_desc = await u.waitUntil(() => view.querySelector('.chat-head__desc'));
- expect(head_desc?.textContent.trim()).toBe(text);
- let topic_el = view.querySelector('.chat-head__desc');
- expect(topic_el.textContent.trim()).toBe(text);
- expect(u.isVisible(topic_el)).toBe(true);
- const toggle = view.querySelector('.hide-topic');
- expect(toggle.textContent.trim()).toBe('Hide topic');
- toggle.click();
- await u.waitUntil(() => !u.isVisible(topic_el));
- stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>Another topic</subject>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => u.isVisible(view.querySelector('.chat-head__desc')));
- topic_el = view.querySelector('.chat-head__desc');
- expect(topic_el.textContent.trim()).toBe('Another topic');
- }));
- it("causes an info message to be shown when received in real-time", mock.initConverse([], {}, async function (_converse) {
- spyOn(_converse.ChatRoom.prototype, 'handleSubjectChange').and.callThrough();
- await mock.openAndEnterMUC(_converse, 'jdev@conference.jabber.org', 'romeo');
- const view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- _converse.api.connection.get()._dataRecv(mock.createRequest(stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>This is an older topic</subject>
- <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>
- <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>
- </message>`));
- await u.waitUntil(() => view.model.handleSubjectChange.calls.count());
- expect(sizzle('.chat-info__message', view).length).toBe(0);
- const desc = await u.waitUntil(() => view.querySelector('.chat-head__desc'));
- expect(desc.textContent.trim()).toBe('This is an older topic');
- _converse.api.connection.get()._dataRecv(mock.createRequest(stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>This is a new topic</subject>
- </message>`));
- await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 2);
- await u.waitUntil(() => sizzle('.chat-info__message', view).pop()?.textContent.trim() === 'Topic set by ralphm');
- await u.waitUntil(() => desc.textContent.trim() === 'This is a new topic');
- // Doesn't show multiple subsequent topic change notifications
- _converse.api.connection.get()._dataRecv(mock.createRequest(stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
- <subject>Yet another topic</subject>
- </message>`));
- await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 3);
- await u.waitUntil(() => desc.textContent.trim() === 'Yet another topic');
- expect(sizzle('.chat-info__message', view).length).toBe(1);
- // Sow multiple subsequent topic change notification from someone else
- _converse.api.connection.get()._dataRecv(mock.createRequest(stx`
- <message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/some1">
- <subject>Some1's topic</subject>
- </message>`));
- await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 4);
- await u.waitUntil(() => desc.textContent.trim() === "Some1's topic");
- expect(sizzle('.chat-info__message', view).length).toBe(2);
- const el = sizzle('.chat-info__message', view).pop();
- expect(el.textContent.trim()).toBe('Topic set by some1');
- // Removes current topic
- const stanza = stx`<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/some1">
- <subject/>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 5);
- await u.waitUntil(() => view.querySelector('.chat-head__desc') === null);
- await u.waitUntil(() => view.querySelector('converse-chat-message:last-child .chat-info').textContent.trim() === "Topic cleared by some1");
- }));
- });
- it("restores cached messages when it reconnects and clear_messages_on_reconnection and muc_clear_messages_on_leave are false",
- mock.initConverse([], {
- 'clear_messages_on_reconnection': false,
- 'muc_clear_messages_on_leave': false
- },
- async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid , 'romeo');
- const model = _converse.chatboxes.get(muc_jid);
- const message = 'Hello world';
- const nick = mock.chatroom_names[0];
- const msg =
- stx`<message from="lounge@montague.lit/${nick}"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit"
- type="groupchat"
- xmlns="jabber:client">
- <body>${message}</body>
- </message>`;
- await model.handleMessageStanza(msg);
- await u.waitUntil(() => document.querySelector('converse-chat-message'));
- await model.close();
- await u.waitUntil(() => !document.querySelector('converse-chat-message'));
- _converse.api.connection.get().IQ_stanzas = [];
- await mock.openAndEnterMUC(_converse, muc_jid , 'romeo');
- await u.waitUntil(() => document.querySelector('converse-chat-message'));
- expect(model.messages.length).toBe(1);
- expect(document.querySelectorAll('converse-chat-message').length).toBe(1);
- }));
- it("clears cached messages when it reconnects and clear_messages_on_reconnection is true",
- mock.initConverse([], {'clear_messages_on_reconnection': true}, async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid , 'romeo');
- const view = _converse.chatboxviews.get(muc_jid);
- const message = 'Hello world';
- const nick = mock.chatroom_names[0];
- const msg =
- stx`<message from="lounge@montague.lit/${nick}"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit"
- type="groupchat"
- xmlns="jabber:client">
- <body>${message}</body>
- </message>`;
- await view.model.handleMessageStanza(msg);
- await view.model.close();
- _converse.api.connection.get().IQ_stanzas = [];
- await mock.openAndEnterMUC(_converse, muc_jid , 'romeo');
- expect(view.model.messages.length).toBe(0);
- expect(view.querySelector('converse-chat-history')).toBe(null);
- }));
- it("is opened when an xmpp: URI is clicked inside another groupchat",
- mock.initConverse([], {}, async function (_converse) {
- await mock.waitForRoster(_converse, 'current');
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- if (!view.querySelectorAll('.chat-area').length) {
- view.renderChatArea();
- }
- expect(_converse.chatboxes.length).toEqual(2);
- const message = 'Please go to xmpp:coven@chat.shakespeare.lit?join';
- const nick = mock.chatroom_names[0];
- const msg =
- stx`<message from="lounge@montague.lit/${nick}"
- id="${u.getUniqueId()}"
- type="groupchat"
- to="romeo@montague.lit"
- xmlns="jabber:client">
- <body>${message}</body>
- </message>`;
- await view.model.handleMessageStanza(msg);
- await u.waitUntil(() => view.querySelector('.chat-msg__text a'));
- view.querySelector('.chat-msg__text a').click();
- await mock.waitForMUCDiscoInfo(_converse, 'coven@chat.shakespeare.lit');
- await mock.waitForReservedNick(_converse, 'coven@chat.shakespeare.lit', 'romeo');
- await u.waitUntil(() => _converse.chatboxes.length === 3)
- expect(_converse.chatboxes.pluck('id').includes('coven@chat.shakespeare.lit')).toBe(true);
- }));
- it("shows a notification if it's not anonymous",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const muc_jid = 'coven@chat.shakespeare.lit';
- const nick = 'romeo';
- _converse.api.rooms.open(muc_jid);
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await mock.waitForReservedNick(_converse, muc_jid, nick);
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- const presence =
- stx`<presence to="romeo@montague.lit/orchard"
- from="coven@chat.shakespeare.lit/some1"
- xmlns="jabber:client">
- <x xmlns="${Strophe.NS.MUC_USER}">
- <item affiliation="owner" jid="romeo@montague.lit/_converse.js-29092160" role="moderator"/>
- <status code="110"/>
- <status code="100"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
- await mock.returnMemberLists(_converse, muc_jid, [], ['member', 'admin', 'owner']);
- const num_info_msgs = await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-info').length);
- expect(num_info_msgs).toBe(1);
- expect(sizzle('div.chat-info', view).pop().textContent.trim()).toBe("This groupchat is not anonymous");
- const csntext = await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent);
- expect(csntext.trim()).toEqual("some1 has entered the groupchat");
- }));
- it("shows join/leave messages when users enter or exit a groupchat",
- mock.initConverse(['chatBoxesFetched'], {'muc_fetch_members': false}, async function (_converse) {
- const muc_jid = 'coven@chat.shakespeare.lit';
- const nick = 'some1';
- const room_creation_promise = _converse.api.rooms.open(muc_jid, {nick});
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- const sent_stanzas = _converse.api.connection.get().sent_stanzas;
- await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length));
- await _converse.api.waitUntil('chatRoomViewInitialized');
- /* We don't show join/leave messages for existing occupants. We
- * know about them because we receive their presences before we
- * receive our own.
- */
- let presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/oldguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'oldguy@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- /* <presence to="romeo@montague.lit/_converse.js-29092160"
- * from="coven@chat.shakespeare.lit/some1">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="romeo@montague.lit/_converse.js-29092160" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence></body>
- */
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/some1'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'romeo@montague.lit/_converse.js-29092160',
- 'role': 'moderator'
- }).up()
- .c('status', {code: '110'});
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const view = await u.waitUntil(() => _converse.chatboxviews.get('coven@chat.shakespeare.lit'));
- const csntext = await u.waitUntil(() => view.querySelector('.chat-content__notifications')?.textContent);
- expect(csntext.trim()).toEqual("some1 has entered the groupchat");
- await room_creation_promise;
- await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
- await view.model.messages.fetched;
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1 and newguy have entered the groupchat");
- const msg =
- stx`<message from="coven@chat.shakespeare.lit/some1"
- to="romeo@montague.lit"
- id="${u.getUniqueId()}"
- type="groupchat"
- xmlns="jabber:client">
- <body>hello world</body>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(msg));
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
- // Add another entrant, otherwise the above message will be
- // collapsed if "newguy" leaves immediately again
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newgirl'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newgirl@montague.lit/_converse.js-213098781',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1, newguy and newgirl have entered the groupchat");
- // Don't show duplicate join messages
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-290918392',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'
- * type='unavailable'>
- * <status>Disconnected: Replaced by new connection</status>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='none'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('status', 'Disconnected: Replaced by new connection').up()
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1 and newgirl have entered the groupchat\nnewguy has left the groupchat");
- // When the user immediately joins again, we collapse the
- // multiple join/leave messages.
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1, newgirl and newguy have entered the groupchat");
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1 and newgirl have entered the groupchat\nnewguy has left the groupchat");
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1, newgirl and nomorenicks have entered the groupchat\nnewguy has left the groupchat");
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-290918392',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@montague.lit/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1 and newgirl have entered the groupchat\nnewguy and nomorenicks have left the groupchat");
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1, newgirl and nomorenicks have entered the groupchat\nnewguy has left the groupchat");
- // Test a member joining and leaving
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-290918392',
- from: 'coven@chat.shakespeare.lit/insider'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'member',
- 'jid': 'insider@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'
- * type='unavailable'>
- * <status>Disconnected: Replaced by new connection</status>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='none'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- to: 'romeo@montague.lit/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/insider'
- })
- .c('status', 'Disconnected: Replaced by new connection').up()
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'member',
- 'jid': 'insider@montague.lit/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1, newgirl and nomorenicks have entered the groupchat\nnewguy and insider have left the groupchat");
- expect(view.model.occupants.length).toBe(5);
- expect(view.model.occupants.findWhere({'jid': 'insider@montague.lit'}).get('show')).toBe('offline');
- // New girl leaves
- presence = $pres({
- 'to': 'romeo@montague.lit/_converse.js-29092160',
- 'type': 'unavailable',
- 'from': 'coven@chat.shakespeare.lit/newgirl'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newgirl@montague.lit/_converse.js-213098781',
- 'role': 'none'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "some1 and nomorenicks have entered the groupchat\nnewguy, insider and newgirl have left the groupchat");
- expect(view.model.occupants.length).toBe(4);
- }));
- it("combines subsequent join/leave messages when users enter or exit a groupchat",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'coven@chat.shakespeare.lit', 'romeo')
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() === "romeo has entered the groupchat");
- let presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/fabio">
- <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() === "romeo and fabio have entered the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/Dele Olajide">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-39320524" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() === "romeo, fabio and Dele Olajide have entered the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/jcbrand">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="owner" jid="jc@opkode.com/converse.js-30645022" role="moderator"/>
- <status code="110"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() === "romeo, fabio and others have entered the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/Dele Olajide">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-39320524" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, fabio and jcbrand have entered the groupchat\nDele Olajide has left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/Dele Olajide">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-74567907" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, fabio and others have entered the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/fuvuv" xml:lang="en">
- <c xmlns="http://jabber.org/protocol/caps" node="http://jabber.pix-art.de" ver="5tOurnuFnp2h50hKafeUyeN4Yl8=" hash="sha-1"/>
- <x xmlns="vcard-temp:x:update"/>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fuvuv@blabber.im/Pix-Art Messenger.8zoB" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, fabio and others have entered the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/fuvuv">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fuvuv@blabber.im/Pix-Art Messenger.8zoB" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, fabio and others have entered the groupchat\nfuvuv has left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/fabio">
- <status>Disconnected: Replaced by new connection</status>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, jcbrand and Dele Olajide have entered the groupchat\nfuvuv and fabio have left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/fabio">
- <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
- <status>Ready for a new day</status>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, jcbrand and others have entered the groupchat\nfuvuv has left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/fabio">
- <status>Disconnected: closed</status>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, jcbrand and Dele Olajide have entered the groupchat\nfuvuv and fabio have left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/Dele Olajide">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-74567907" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo and jcbrand have entered the groupchat\nfuvuv, fabio and Dele Olajide have left the groupchat");
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" from="coven@chat.shakespeare.lit/fabio">
- <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo, jcbrand and fabio have entered the groupchat\nfuvuv and Dele Olajide have left the groupchat");
- expect(1).toBe(1);
- }));
- it("doesn't show the disconnection messages when join_leave_events is not in muc_show_info_messages setting",
- mock.initConverse(['chatBoxesFetched'], {'muc_show_info_messages': []}, async function (_converse) {
- spyOn(_converse.ChatRoom.prototype, 'onOccupantAdded').and.callThrough();
- spyOn(_converse.ChatRoom.prototype, 'onOccupantRemoved').and.callThrough();
- await mock.openAndEnterMUC(_converse, 'coven@chat.shakespeare.lit', 'some1');
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- let presence = $pres({
- to: 'romeo@montague.lit/orchard',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@montague.lit/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.model.onOccupantAdded.calls.count() === 2);
- expect(view.model.notifications.get('entered')).toBeFalsy();
- expect(view.querySelector('.chat-content__notifications').textContent.trim()).toBe('');
- await mock.sendMessage(view, 'hello world');
- presence = stx`<presence xmlns="jabber:client" to="romeo@montague.lit/orchard" type="unavailable" from="coven@chat.shakespeare.lit/newguy">
- <status>Gotta go!</status>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" jid="newguy@montague.lit/_converse.js-290929789" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.model.onOccupantRemoved.calls.count());
- expect(view.model.onOccupantRemoved.calls.count()).toBe(1);
- expect(view.model.notifications.get('entered')).toBeFalsy();
- await mock.sendMessage(view, 'hello world');
- expect(view.querySelector('.chat-content__notifications').textContent.trim()).toBe('');
- }));
- it("role-change messages that follow a MUC leave are left out",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- // See https://github.com/conversejs/converse.js/issues/1259
- await mock.openAndEnterMUC(_converse, 'conversations@conference.siacs.eu', 'romeo');
- const presence =
- stx`<presence to='romeo@montague.lit/orchard'
- from='conversations@conference.siacs.eu/Guus'
- xmlns="jabber:client">
- <x xmlns='${Strophe.NS.MUC_USER}'>
- <item affiliation='none' jid='Guus@montague.lit/xxx' role='visitor'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const view = _converse.chatboxviews.get('conversations@conference.siacs.eu');
- const msg =
- stx`<message from='conversations@conference.siacs.eu/romeo'
- to='romeo@montague.lit'
- id='${u.getUniqueId()}'
- type='groupchat'
- xmlns="jabber:client">
- <body>Some message</body>
- </message>`;
- await view.model.handleMessageStanza(msg);
- await u.waitUntil(() => sizzle('.chat-msg:last .chat-msg__text', view).pop());
- let stanza =
- stx`<presence
- to="romeo@montague.lit/orchard"
- type="unavailable"
- from="conversations@conference.siacs.eu/Guus"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" role="none"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- stanza =
- stx`<presence
- to="romeo@montague.lit/orchard"
- from="conversations@conference.siacs.eu/Guus"
- xmlns="jabber:client">
- <c xmlns="http://jabber.org/protocol/caps"
- node="http://conversations.im"
- ver="ISg6+9AoK1/cwhbNEDviSvjdPzI="
- hash="sha-1"/>
- <x xmlns="vcard-temp:x:update">
- <photo>bf987c486c51fbc05a6a4a9f20dd19b5efba3758</photo>
- </x>
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item affiliation="none" role="visitor"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim()
- === "romeo and Guus have entered the groupchat");
- expect(1).toBe(1);
- }));
- it("must first be configured if it's a new",
- mock.initConverse(['chatBoxesFetched'],
- { muc_instant_rooms: false },
- async function (_converse) {
- let sent_IQ, IQ_id;
- const sendIQ = _converse.api.connection.get().sendIQ;
- spyOn(_converse.api.connection.get(), 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.call(this, iq, callback, errback);
- });
- const { api } = _converse;
- const own_jid = api.connection.get().jid;
- const muc_jid = 'coven@chat.shakespeare.lit';
- _converse.api.rooms.open(muc_jid, {'nick': 'some1'});
- await mock.waitForNewMUCDiscoInfo(_converse, muc_jid);
- const presence =
- stx`<presence to='${own_jid}'
- from='coven@chat.shakespeare.lit/some1'
- xmlns="jabber:client">
- <x xmlns='${Strophe.NS.MUC_USER}'>
- <item affiliation='owner' jid='romeo@montague.lit/_converse.js-29092160' role='moderator'/>
- <status code='110'/>
- <status code='201'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const sent_IQs = _converse.api.connection.get().IQ_stanzas;
- while (sent_IQs.length) sent_IQs.pop();
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => u.isVisible(view));
- await u.waitUntil(() => view.model.getOwnOccupant()?.get('affiliation') === 'owner');
- const sel = 'iq query[xmlns="http://jabber.org/protocol/muc#owner"]';
- const iq = await u.waitUntil(() => sent_IQs.filter(iq => sizzle(sel, iq).length).pop());
- /* Check that an IQ is sent out, asking for the
- * configuration form.
- * See: // https://xmpp.org/extensions/xep-0045.html#example-163
- */
- expect(Strophe.serialize(iq)).toBe(
- `<iq id="${iq.getAttribute('id')}" to="${muc_jid}" type="get" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/muc#owner"/>`+
- `</iq>`);
- /* Server responds with the configuration form.
- * See: // https://xmpp.org/extensions/xep-0045.html#example-165
- */
- const config_stanza =
- stx`<iq from="${muc_jid}" id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/muc#owner">
- <x xmlns="jabber:x:data" type="form">
- <title>Configuration for "coven" Room</title>
- <instructions>Complete this form to modify the configuration of your room.</instructions>
- <field type="hidden" var="FORM_TYPE">
- <value>http://jabber.org/protocol/muc#roomconfig</value>
- </field>
- <field label="Natural-Language Room Name" type="text-single" var="muc#roomconfig_roomname">
- <value>A Dark Cave</value>
- </field>
- <field label="Short Description of Room" type="text-single" var="muc#roomconfig_roomdesc">
- <value>The place for all good witches!</value>
- </field>
- <field label="Enable Public Logging?" type="boolean" var="muc#roomconfig_enablelogging">
- <value>0</value>
- </field>
- <field label="Allow Occupants to Change Subject?" type="boolean" var="muc#roomconfig_changesubject">
- <value>0</value>
- </field>
- <field label="Allow Occupants to Invite Others?" type="boolean" var="muc#roomconfig_allowinvites">
- <value>0</value>
- </field>
- <field label="Who Can Send Private Messages?" type="list-single" var="muc#roomconfig_allowpm">
- <value>anyone</value>
- <option label="Anyone">
- <value>anyone</value>
- </option>
- <option label="Anyone with Voice">
- <value>participants</value>
- </option>
- <option label="Moderators Only">
- <value>moderators</value>
- </option>
- <option label="Nobody">
- <value>none</value>
- </option>
- </field>
- <field label="Roles for which Presence is Broadcasted" type="list-multi" var="muc#roomconfig_presencebroadcast">
- <value>moderator</value>
- <value>participant</value>
- <value>visitor</value>
- <option label="Moderator">
- <value>moderator</value>
- </option>
- <option label="Participant">
- <value>participant</value>
- </option>
- <option label="Visitor">
- <value>visitor</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>
- <option label="Moderator">
- <value>moderator</value>
- </option>
- <option label="Participant">
- <value>participant</value>
- </option>
- <option label="Visitor">
- <value>visitor</value>
- </option>
- </field>
- <field label="Make Room Publicly Searchable?" type="boolean" var="muc#roomconfig_publicroom">
- <value>0</value>
- </field>
- <field label="Make Room Persistent?" type="boolean" var="muc#roomconfig_persistentroom">
- <value>0</value>
- </field>
- <field label="Make Room Moderated?" type="boolean" var="muc#roomconfig_moderatedroom">
- <value>0</value>
- </field>
- <field label="Make Room Members Only?" type="boolean" var="muc#roomconfig_membersonly">
- <value>0</value>
- </field>
- <field label="Password Required for Entry?" type="boolean" var="muc#roomconfig_passwordprotectedroom">
- <value>1</value>
- </field>
- <field type="fixed">
- <value>If a password is required to enter this groupchat, you must specify the password below.</value>
- </field>
- <field label="Password" type="text-private" var="muc#roomconfig_roomsecret">
- <value>cauldronburn</value>
- </field>
- </x>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(config_stanza));
- const modal = _converse.api.modal.get('converse-muc-config-modal');
- const membersonly = await u.waitUntil(() => modal.querySelector('input[name="muc#roomconfig_membersonly"]'));
- expect(membersonly.getAttribute('type')).toBe('checkbox');
- membersonly.checked = true;
- const moderated = modal.querySelectorAll('input[name="muc#roomconfig_moderatedroom"]');
- expect(moderated.length).toBe(1);
- expect(moderated[0].getAttribute('type')).toBe('checkbox');
- moderated[0].checked = true;
- const password = modal.querySelectorAll('input[name="muc#roomconfig_roomsecret"]');
- expect(password.length).toBe(1);
- expect(password[0].getAttribute('type')).toBe('password');
- const allowpm = modal.querySelectorAll('select[name="muc#roomconfig_allowpm"]');
- expect(allowpm.length).toBe(1);
- allowpm[0].value = 'moderators';
- const presencebroadcast = modal.querySelectorAll('select[name="muc#roomconfig_presencebroadcast"]');
- expect(presencebroadcast.length).toBe(1);
- presencebroadcast[0].value = ['moderator'];
- modal.querySelector('.chatroom-form input[type="submit"]').click();
- console.log(Strophe.serialize(sent_IQ));
- expect(Strophe.serialize(sent_IQ)).toBe(
- `<iq id="${IQ_id}" to="${muc_jid}" type="set" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/muc#owner">`+
- `<x type="submit" xmlns="jabber:x:data">`+
- `<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#roomconfig</value></field>`+
- `<field var="muc#roomconfig_roomname"><value>A Dark Cave</value></field>`+
- `<field var="muc#roomconfig_roomdesc"><value>The place for all good witches!</value></field>`+
- `<field var="muc#roomconfig_enablelogging"><value>0</value></field>`+
- `<field var="muc#roomconfig_changesubject"><value>0</value></field>`+
- `<field var="muc#roomconfig_allowinvites"><value>0</value></field>`+
- `<field var="muc#roomconfig_allowpm"><value>moderators</value></field>`+
- `<field var="muc#roomconfig_presencebroadcast"><value>moderator</value></field>`+
- `<field var="muc#roomconfig_getmemberlist"><value>moderator</value>,<value>participant</value>,<value>visitor</value></field>`+
- `<field var="muc#roomconfig_publicroom"><value>0</value></field>`+
- `<field var="muc#roomconfig_persistentroom"><value>0</value></field>`+
- `<field var="muc#roomconfig_moderatedroom"><value>1</value></field>`+
- `<field var="muc#roomconfig_membersonly"><value>1</value></field>`+
- `<field var="muc#roomconfig_passwordprotectedroom"><value>1</value></field>`+
- `<field var="muc#roomconfig_roomsecret"><value>cauldronburn</value></field>`+
- `</x>`+
- `</query>`+
- `</iq>`);
- }));
- it("can be configured if your its owner",
- mock.initConverse(['chatBoxesFetched'],
- { muc_instant_rooms: false },
- async function (_converse) {
- let sent_IQ, IQ_id;
- const sendIQ = _converse.api.connection.get().sendIQ;
- spyOn(_converse.api.connection.get(), 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.call(this, iq, callback, errback);
- });
- const muc_jid = 'coven@chat.shakespeare.lit';
- const features = [
- 'http://jabber.org/protocol/muc',
- 'jabber:iq:register',
- 'muc_passwordprotected',
- 'muc_hidden',
- 'muc_temporary',
- 'muc_membersonly',
- 'muc_unmoderated',
- 'muc_anonymous',
- 'vcard-temp',
- ]
- await mock.openAndEnterMUC(_converse, muc_jid, 'some1', features);
- await mock.waitForNewMUCDiscoInfo(_converse, muc_jid);
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => u.isVisible(view));
- const presence =
- stx`<presence to="romeo@montague.lit/_converse.js-29092160"
- from="coven@chat.shakespeare.lit/some1"
- xmlns="jabber:client">
- <x xmlns="${Strophe.NS.MUC_USER}">
- <item affiliation="owner" jid="romeo@montague.lit/_converse.js-29092160" role="moderator"/>
- <status code="110"/>
- <status code="201"/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.model.getOwnOccupant()?.get('affiliation') === 'owner');
- const sent_IQs = _converse.api.connection.get().IQ_stanzas;
- const sel = 'iq query[xmlns="http://jabber.org/protocol/muc#owner"]';
- const iq = await u.waitUntil(() => sent_IQs.filter(iq => sizzle(sel, iq).length).pop());
- /* Check that an IQ is sent out, asking for the
- * configuration form.
- */
- expect(Strophe.serialize(iq)).toBe(
- `<iq id="${iq.getAttribute('id')}" to="${muc_jid}" type="get" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/muc#owner"/>`+
- `</iq>`);
- /* Server responds with the configuration form.
- * See: // https://xmpp.org/extensions/xep-0045.html#example-165
- */
- const config_stanza =
- stx`<iq from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/muc#owner">
- <x xmlns="jabber:x:data" type="form">
- <title>Configuration for "coven" Room</title>
- <instructions>Complete this form to modify the configuration of your room.</instructions>
- <field type="hidden" var="FORM_TYPE">
- <value>http://jabber.org/protocol/muc#roomconfig</value>
- </field>
- <field label="Natural-Language Room Name" type="text-single" var="muc#roomconfig_roomname">
- <value>A Dark Cave</value>
- </field>
- <field label="Short Description of Room" type="text-single" var="muc#roomconfig_roomdesc">
- <value>The place for all good witches!</value>
- </field>
- <field label="Enable Public Logging?" type="boolean" var="muc#roomconfig_enablelogging">
- <value>0</value>
- </field>
- <field label="Allow Occupants to Change Subject?" type="boolean" var="muc#roomconfig_changesubject">
- <value>0</value>
- </field>
- <field label="Allow Occupants to Invite Others?" type="boolean" var="muc#roomconfig_allowinvites">
- <value>0</value>
- </field>
- <field label="Who Can Send Private Messages?" type="list-single" var="muc#roomconfig_allowpm">
- <value>anyone</value>
- <option label="Anyone">
- <value>anyone</value>
- </option>
- <option label="Anyone with Voice">
- <value>participants</value>
- </option>
- <option label="Moderators Only">
- <value>moderators</value>
- </option>
- <option label="Nobody">
- <value>none</value>
- </option>
- </field>
- <field label="Roles for which Presence is Broadcasted"
- type="list-multi"
- var="muc#roomconfig_presencebroadcast">
- <value>moderator</value>
- <value>participant</value>
- <value>visitor</value>
- <option label="Moderator">
- <value>moderator</value>
- </option>
- <option label="Participant">
- <value>participant</value>
- </option>
- <option label="Visitor">
- <value>visitor</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>
- <option label="Moderator">
- <value>moderator</value>
- </option>
- <option label="Participant">
- <value>participant</value>
- </option>
- <option label="Visitor">
- <value>visitor</value>
- </option>
- </field>
- <field label="Make Room Publicly Searchable?" type="boolean" var="muc#roomconfig_publicroom">
- <value>0</value>
- </field>
- <field label="Make Room Persistent?" type="boolean" var="muc#roomconfig_persistentroom">
- <value>0</value>
- </field>
- <field label="Make Room Moderated?" type="boolean" var="muc#roomconfig_moderatedroom">
- <value>0</value>
- </field>
- <field label="Make Room Members Only?" type="boolean" var="muc#roomconfig_membersonly">
- <value>0</value>
- </field>
- <field label="Password Required for Entry?" type="boolean" var="muc#roomconfig_passwordprotectedroom">
- <value>1</value>
- </field>
- <field type="fixed">
- <value>If a password is required to enter this groupchat, you must specify the password below.</value>
- </field>
- <field label="Password" type="text-private" var="muc#roomconfig_roomsecret">
- <value>cauldronburn</value>
- </field>
- </x>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(config_stanza));
- const modal = _converse.api.modal.get('converse-muc-config-modal');
- const membersonly = await u.waitUntil(() => modal.querySelector('input[name="muc#roomconfig_membersonly"]'));
- expect(membersonly.getAttribute('type')).toBe('checkbox');
- membersonly.checked = true;
- const moderated = modal.querySelectorAll('input[name="muc#roomconfig_moderatedroom"]');
- expect(moderated.length).toBe(1);
- expect(moderated[0].getAttribute('type')).toBe('checkbox');
- moderated[0].checked = true;
- const password = modal.querySelectorAll('input[name="muc#roomconfig_roomsecret"]');
- expect(password.length).toBe(1);
- expect(password[0].getAttribute('type')).toBe('password');
- const allowpm = modal.querySelectorAll('select[name="muc#roomconfig_allowpm"]');
- expect(allowpm.length).toBe(1);
- allowpm[0].value = 'moderators';
- const presencebroadcast = modal.querySelectorAll('select[name="muc#roomconfig_presencebroadcast"]');
- expect(presencebroadcast.length).toBe(1);
- presencebroadcast[0].value = ['moderator'];
- // Set image file for avatar upload
- const avatar_picker = modal.querySelector('converse-image-picker input[type="file"]');
- const image_file = new File([_converse.default_avatar_image], 'avatar.svg', {
- type: _converse.default_avatar_image_type,
- lastModified: new Date(),
- });
- const dataTransfer = new DataTransfer();
- dataTransfer.items.add(image_file);
- avatar_picker.files = dataTransfer.files;
- modal.querySelector('.chatroom-form input[type="submit"]').click();
- expect(Strophe.serialize(sent_IQ)).toBe(
- `<iq id="${IQ_id}" to="${muc_jid}" type="set" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/muc#owner">`+
- `<x type="submit" xmlns="jabber:x:data">`+
- `<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#roomconfig</value></field>`+
- `<field var="muc#roomconfig_roomname"><value>A Dark Cave</value></field>`+
- `<field var="muc#roomconfig_roomdesc"><value>The place for all good witches!</value></field>`+
- `<field var="muc#roomconfig_enablelogging"><value>0</value></field>`+
- `<field var="muc#roomconfig_changesubject"><value>0</value></field>`+
- `<field var="muc#roomconfig_allowinvites"><value>0</value></field>`+
- `<field var="muc#roomconfig_allowpm"><value>moderators</value></field>`+
- `<field var="muc#roomconfig_presencebroadcast"><value>moderator</value></field>`+
- `<field var="muc#roomconfig_getmemberlist"><value>moderator</value>,<value>participant</value>,<value>visitor</value></field>`+
- `<field var="muc#roomconfig_publicroom"><value>0</value></field>`+
- `<field var="muc#roomconfig_persistentroom"><value>0</value></field>`+
- `<field var="muc#roomconfig_moderatedroom"><value>1</value></field>`+
- `<field var="muc#roomconfig_membersonly"><value>1</value></field>`+
- `<field var="muc#roomconfig_passwordprotectedroom"><value>1</value></field>`+
- `<field var="muc#roomconfig_roomsecret"><value>cauldronburn</value></field>`+
- `</x>`+
- `</query>`+
- `</iq>`);
- }));
- it("properly handles notification that a room has been destroyed",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'problematic@muc.montague.lit';
- api.rooms.open(muc_jid, { nick: 'romeo' });
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- const presence =
- stx`<presence from="problematic@muc.montague.lit"
- id="n13mt3l"
- type="error"
- to="romeo@montague.lit/pda"
- xmlns="jabber:client">
- <error type="cancel">
- <gone xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">xmpp:other-room@chat.jabberfr.org?join</gone>
- <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">We didn't like the name</text>
- </error>
- </presence>`;
- const view = await u.waitUntil(() => _converse.chatboxviews.get('problematic@muc.montague.lit'));
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const msg = await u.waitUntil(() => view.querySelector('.chatroom-body .disconnect-msg'));
- expect(msg.textContent.trim()).toBe('This groupchat no longer exists');
- expect(view.querySelector('.chatroom-body .destroyed-reason').textContent.trim())
- .toBe(`The following reason was given: "We didn't like the name"`);
- expect(view.querySelector('.chatroom-body .moved-label').textContent.trim())
- .toBe('The conversation has moved to a new address. Click the link below to enter.');
- expect(view.querySelector('.chatroom-body .moved-link').textContent.trim())
- .toBe(`other-room@chat.jabberfr.org`);
- }));
- it("allows the user to invite their roster contacts to enter the groupchat",
- mock.initConverse(['chatBoxesFetched'], {'view_mode': 'overlayed'}, async function (_converse) {
- // We need roster contacts, so that we have someone to invite
- await mock.waitForRoster(_converse, 'current');
- const features = [
- 'http://jabber.org/protocol/muc',
- 'jabber:iq:register',
- 'muc_passwordprotected',
- 'muc_hidden',
- 'muc_temporary',
- 'muc_membersonly',
- 'muc_unmoderated',
- 'muc_anonymous'
- ]
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo', features);
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- expect(view.model.getOwnAffiliation()).toBe('owner');
- expect(view.model.features.get('open')).toBe(false);
- await u.waitUntil(() => view.querySelector('.open-invite-modal'));
- // Members can't invite if the room isn't open
- view.model.getOwnOccupant().set('affiliation', 'member');
- await u.waitUntil(() => view.querySelector('.open-invite-modal') === null);
- view.model.features.set('open', 'true');
- await u.waitUntil(() => view.querySelector('.open-invite-modal'));
- view.querySelector('.open-invite-modal').click();
- const modal = _converse.api.modal.get('converse-muc-invite-modal');
- await u.waitUntil(() => u.isVisible(modal), 1000)
- expect(modal.querySelectorAll('#invitee_jids').length).toBe(1);
- expect(modal.querySelectorAll('textarea').length).toBe(1);
- spyOn(view.model, 'directInvite').and.callThrough();
- const input = modal.querySelector('#invitee_jids input');
- input.value = "Balt";
- modal.querySelector('input[type="submit"]').click();
- await u.waitUntil(() => modal.querySelector('.error'));
- const error = modal.querySelector('.error');
- expect(error.textContent).toBe('Please enter a valid XMPP address');
- let evt = new Event('input');
- input.dispatchEvent(evt);
- let sent_stanza;
- spyOn(_converse.api.connection.get(), 'send').and.callFake(stanza => (sent_stanza = stanza));
- const hint = await u.waitUntil(() => modal.querySelector('.suggestion-box__results li'));
- expect(input.value).toBe('Balt');
- expect(hint.textContent.trim()).toBe('Balthasar');
- evt = new Event('mousedown', {'bubbles': true});
- evt.button = 0;
- hint.dispatchEvent(evt);
- const textarea = modal.querySelector('textarea');
- textarea.value = "Please join!";
- modal.querySelector('input[type="submit"]').click();
- expect(view.model.directInvite).toHaveBeenCalled();
- expect(Strophe.serialize(sent_stanza)).toBe(
- `<message from="romeo@montague.lit/orchard" `+
- `id="${sent_stanza.getAttribute("id")}" `+
- `to="balthasar@montague.lit" `+
- `xmlns="jabber:client">`+
- `<x jid="lounge@montague.lit" reason="Please join!" xmlns="jabber:x:conference"/>`+
- `</message>`
- );
- }));
- it("can be joined automatically, based on a received invite",
- mock.initConverse([], { lazy_load_vcards: false }, async function (_converse) {
- await mock.waitForRoster(_converse, 'current'); // We need roster contacts, who can invite us
- const muc_jid = 'lounge@montague.lit';
- const name = mock.cur_names[0];
- const from_jid = name.replace(/ /g,'.').toLowerCase() + '@montague.lit';
- await u.waitUntil(() => _converse.roster.get(from_jid).vcard.get('fullname'));
- spyOn(_converse.api, 'confirm').and.callFake(() => Promise.resolve(true));
- expect(_converse.chatboxes.models.length).toBe(1);
- expect(_converse.chatboxes.models[0].id).toBe("controlbox");
- const reason = "Please join this groupchat";
- const stanza = stx`
- <message xmlns="jabber:client"
- to="${_converse.bare_jid}"
- from="${from_jid}"
- id="9bceb415-f34b-4fa4-80d5-c0d076a24231">
- <x xmlns="jabber:x:conference" jid="${muc_jid}" reason="${reason}"/>
- </message>`.tree();
- const promise = _converse.onDirectMUCInvitation(stanza);
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- await mock.waitForReservedNick(_converse, muc_jid, 'romeo');
- await mock.receiveOwnMUCPresence(_converse, muc_jid, 'romeo');
- await promise;
- expect(_converse.api.confirm).toHaveBeenCalledWith(
- name + ' has invited you to join a groupchat: '+ muc_jid +
- ', and left the following reason: "'+reason+'"');
- expect(_converse.chatboxes.models.length).toBe(2);
- expect(_converse.chatboxes.models[0].id).toBe('controlbox');
- expect(_converse.chatboxes.models[1].id).toBe(muc_jid);
- }));
- it("shows received groupchat messages",
- mock.initConverse([], {}, async function (_converse) {
- const text = 'This is a received message';
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- spyOn(_converse.api, "trigger").and.callThrough();
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- const nick = mock.chatroom_names[0];
- view.model.occupants.create({
- 'nick': nick,
- 'muc_jid': `${view.model.get('jid')}/${nick}`
- });
- const message =
- stx`<message
- from="lounge@montague.lit/${nick}"
- id="1"
- to="romeo@montague.lit"
- type="groupchat"
- xmlns="jabber:client">
- <body>${text}</body>
- </message>`;
- await view.model.handleMessageStanza(message.tree());
- await u.waitUntil(() => view.querySelectorAll('.chat-msg').length);
- expect(view.querySelectorAll('.chat-msg').length).toBe(1);
- expect(view.querySelector('.chat-msg__text').textContent.trim()).toBe(text);
- expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
- }));
- it("shows sent groupchat messages", mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- spyOn(_converse.api, "trigger").and.callThrough();
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- const text = 'This is a sent message';
- const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
- textarea.value = text;
- const message_form = view.querySelector('converse-muc-message-form');
- message_form.onKeyDown({
- target: textarea,
- preventDefault: function preventDefault () {},
- keyCode: 13
- });
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
- expect(_converse.api.trigger).toHaveBeenCalledWith('sendMessage', jasmine.any(Object));
- expect(view.querySelectorAll('.chat-msg').length).toBe(1);
- // Let's check that if we receive the same message again, it's
- // not shown.
- const stanza = stx`
- <message xmlns="jabber:client"
- from="lounge@montague.lit/romeo"
- to="${_converse.api.connection.get().jid}"
- type="groupchat">
- <body>${text}</body>
- <stanza-id xmlns="urn:xmpp:sid:0"
- id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
- by="lounge@montague.lit"/>
- <origin-id xmlns="urn:xmpp:sid:0" id="${view.model.messages.at(0).get('origin_id')}"/>
- </message>`;
- await view.model.handleMessageStanza(stanza);
- expect(view.querySelectorAll('.chat-msg').length).toBe(1);
- expect(sizzle('.chat-msg__text:last').pop().textContent.trim()).toBe(text);
- expect(view.model.messages.length).toBe(1);
- // We don't emit an event if it's our own message
- expect(_converse.api.trigger.calls.count(), 1);
- }));
- it("will cause the chat area to be scrolled down only if it was at the bottom already",
- mock.initConverse([], {}, async function (_converse) {
- const message = 'This message is received while the chat area is scrolled up';
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- // Create enough messages so that there's a scrollbar.
- const promises = [];
- for (let i=0; i<20; i++) {
- promises.push(
- view.model.handleMessageStanza(
- stx`<message from="lounge@montague.lit/someone"
- to="romeo@montague.lit.com"
- type="groupchat"
- id="${u.getUniqueId()}"
- xmlns="jabber:client">
- <body>Message: ${i}</body>
- </message>`
- ));
- }
- await Promise.all(promises);
- const promise = u.getOpenPromise();
- // Give enough time for `markScrolled` to have been called
- setTimeout(async () => {
- const content = view.querySelector('.chat-content');
- content.scrollTop = 0;
- await view.model.handleMessageStanza(
- stx`<message from="lounge@montague.lit/someone"
- to="romeo@montague.lit.com"
- type="groupchat"
- id="${u.getUniqueId()}"
- xmlns="jabber:client">
- <body>${message}</body>
- </message>`
- );
- await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 21);
- // Now check that the message appears inside the chatbox in the DOM
- const msg_txt = sizzle('.chat-msg:last .chat-msg__text', content).pop().textContent;
- expect(msg_txt).toEqual(message);
- expect(content.scrollTop).toBe(0);
- promise.resolve();
- }, 500);
- return promise;
- }));
- it("informs users if the room configuration has changed",
- mock.initConverse([], {}, async function (_converse) {
- const muc_jid = 'coven@chat.shakespeare.lit';
- await mock.openAndEnterMUC(_converse, 'coven@chat.shakespeare.lit', 'romeo');
- const view = _converse.chatboxviews.get(muc_jid);
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
- const stanza = stx`
- <message from="${muc_jid}"
- id="80349046-F26A-44F3-A7A6-54825064DD9E"
- to="${_converse.jid}"
- type="groupchat"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <status code="170"/>
- </x>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(stanza));
- await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-info').length);
- const info_messages = view.querySelectorAll('.chat-content .chat-info');
- expect(info_messages[0].textContent.trim()).toBe('Groupchat logging is now enabled');
- }));
- it("queries for the groupchat information before attempting to join the user",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const nick = "some1";
- const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
- const muc_jid = 'coven@chat.shakespeare.lit';
- _converse.api.rooms.open(muc_jid, { nick });
- const stanza = await u.waitUntil(() => IQ_stanzas.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- // Check that the groupchat queried for the feautures.
- expect(Strophe.serialize(stanza)).toBe(
- `<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute("id")}" to="${muc_jid}" type="get" xmlns="jabber:client">`+
- `<query xmlns="http://jabber.org/protocol/disco#info"/>`+
- `</iq>`);
- const features_stanza =
- stx`<iq from="${muc_jid}"
- id="${stanza.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="A Dark Cave" type="text"/>
- <feature var="http://jabber.org/protocol/muc"/>
- <feature var="muc_passwordprotected"/>
- <feature var="muc_hidden"/>
- <feature var="muc_temporary"/>
- <feature var="muc_open"/>
- <feature var="muc_unmoderated"/>
- <feature var="muc_nonanonymous"/>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- let view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- const sent_stanzas = _converse.api.connection.get().sent_stanzas;
- await u.waitUntil(() => sent_stanzas.filter(s => s.matches(`presence[to="${muc_jid}/${nick}"]`)).pop());
- view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- expect(view.model.features.get('fetched')).toBeTruthy();
- expect(view.model.features.get('passwordprotected')).toBe(true);
- expect(view.model.features.get('hidden')).toBe(true);
- expect(view.model.features.get('temporary')).toBe(true);
- expect(view.model.features.get('open')).toBe(true);
- expect(view.model.features.get('unmoderated')).toBe(true);
- expect(view.model.features.get('nonanonymous')).toBe(true);
- }));
- it("updates the shown features when the groupchat configuration has changed",
- mock.initConverse([], {'view_mode': 'fullscreen'}, async function (_converse) {
- let features = [
- 'http://jabber.org/protocol/muc',
- 'jabber:iq:register',
- 'muc_passwordprotected',
- 'muc_publicroom',
- 'muc_temporary',
- 'muc_open',
- 'muc_unmoderated',
- 'muc_nonanonymous'
- ];
- const muc_jid = 'room@conference.example.org';
- await mock.openAndEnterMUC(_converse, muc_jid, 'romeo', features);
- const view = _converse.chatboxviews.get(muc_jid);
- const info_el = view.querySelector(".show-muc-details-modal");
- info_el.click();
- let modal = _converse.api.modal.get('converse-muc-details-modal');
- await u.waitUntil(() => u.isVisible(modal), 1000);
- let features_list = modal.querySelector('.features-list');
- let features_shown = Array.from(features_list.children).map((e) => e.textContent);
- expect(features_shown.length).toBe(5);
- expect(features_shown.join(' ')).toBe(
- 'Password protected - This groupchat requires a password before entry '+
- 'Open - Anyone can join this groupchat '+
- 'Temporary - This groupchat will disappear once the last person leaves '+
- 'Not anonymous - All other groupchat participants can see your XMPP address '+
- 'Not moderated - Participants entering this groupchat can write right away');
- expect(view.model.features.get('hidden')).toBe(false);
- expect(view.model.features.get('mam_enabled')).toBe(false);
- expect(view.model.features.get('membersonly')).toBe(false);
- expect(view.model.features.get('moderated')).toBe(false);
- expect(view.model.features.get('nonanonymous')).toBe(true);
- expect(view.model.features.get('open')).toBe(true);
- expect(view.model.features.get('passwordprotected')).toBe(true);
- expect(view.model.features.get('persistent')).toBe(false);
- expect(view.model.features.get('publicroom')).toBe(true);
- expect(view.model.features.get('semianonymous')).toBe(false);
- expect(view.model.features.get('temporary')).toBe(true);
- expect(view.model.features.get('unmoderated')).toBe(true);
- expect(view.model.features.get('unsecured')).toBe(false);
- await u.waitUntil(() => view.querySelector('.chatbox-title__text').textContent.trim() === 'Room');
- modal.querySelector('.btn-close').click();
- view.querySelector('.configure-chatroom-button').click();
- const IQs = _converse.api.connection.get().IQ_stanzas;
- const s = `iq[to="${muc_jid}"] query[xmlns="${Strophe.NS.MUC_OWNER}"]`;
- let iq = await u.waitUntil(() => IQs.filter(iq => iq.querySelector(s)).pop());
- const response_el = stx`<iq xmlns="jabber:client"
- type="result"
- to="romeo@montague.lit/pda"
- from="room@conference.example.org" id="${iq.getAttribute('id')}">
- <query xmlns="http://jabber.org/protocol/muc#owner">
- <x xmlns="jabber:x:data" type="form">
- <title>Configuration for room@conference.example.org</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="fixed">
- <value>Room information</value>
- </field>
- <field var="muc#roomconfig_roomname" type="text-single" label="Title">
- <value>Room</value>
- </field>
- <field var="muc#roomconfig_roomdesc" type="text-single" label="Description">
- <desc>A brief description of the room</desc>
- <value>This room is used in tests</value>
- </field>
- <field var="muc#roomconfig_lang" type="text-single" label="Language tag for room (e.g. 'en', 'de', 'fr' etc.)">
- <desc>Indicate the primary language spoken in this room</desc>
- <value>en</value>
- </field>
- <field var="muc#roomconfig_persistentroom" type="boolean" label="Persistent (room should remain even when it is empty)">
- <desc>Rooms are automatically deleted when they are empty, unless this option is enabled</desc>
- <value>1</value>
- </field>
- <field var="muc#roomconfig_publicroom" type="boolean" label="Include room information in public lists">
- <desc>Enable this to allow people to find the room</desc>
- <value>1</value>
- </field>
- <field type="fixed"><value>Access to the room</value></field>
- <field var="muc#roomconfig_roomsecret" type="text-private" label="Password"><value/></field>
- <field var="muc#roomconfig_membersonly" type="boolean" label="Only allow members to join">
- <desc>Enable this to only allow access for room owners, admins and members</desc>
- </field>
- <field var="{http://prosody.im/protocol/muc}roomconfig_allowmemberinvites" type="boolean" label="Allow members to invite new members"/>
- <field type="fixed"><value>Permissions in the room</value>
- </field>
- <field var="muc#roomconfig_changesubject" type="boolean" label="Allow anyone to set the room's subject">
- <desc>Choose whether anyone, or only moderators, may set the room's subject</desc>
- </field>
- <field var="muc#roomconfig_moderatedroom" type="boolean" label="Moderated (require permission to speak)">
- <desc>In moderated rooms occupants must be given permission to speak by a room moderator</desc>
- </field>
- <field var="muc#roomconfig_whois" type="list-single" label="Addresses (JIDs) of room occupants may be viewed by:">
- <option label="Moderators only"><value>moderators</value></option>
- <option label="Anyone"><value>anyone</value></option>
- <value>anyone</value>
- </field>
- <field type="fixed"><value>Other options</value></field>
- <field var="muc#roomconfig_historylength" type="text-single" label="Maximum number of history messages returned by room">
- <desc>Specify the maximum number of previous messages that should be sent to users when they join the room</desc>
- <value>50</value>
- </field>
- <field var="muc#roomconfig_defaulthistorymessages" type="text-single" label="Default number of history messages returned by room">
- <desc>Specify the number of previous messages sent to new users when they join the room</desc>
- <value>20</value>
- </field>
- </x>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(response_el));
- modal = _converse.api.modal.get('converse-muc-config-modal');
- await u.waitUntil(() => modal.querySelector('.chatroom-form input'));
- expect(modal.querySelector('.chatroom-form legend').textContent.trim()).toBe("Configuration for room@conference.example.org");
- sizzle('[name="muc#roomconfig_membersonly"]', modal).pop().click();
- sizzle('[name="muc#roomconfig_roomname"]', modal).pop().value = "New room name"
- modal.querySelector('.chatroom-form input[type="submit"]').click();
- iq = await u.waitUntil(() => IQs.filter(iq => iq.matches(`iq[to="${muc_jid}"][type="set"]`)).pop());
- const result =
- stx`<iq xmlns="jabber:client"
- type="result"
- to="romeo@montague.lit/orchard"
- from="lounge@muc.montague.lit"
- id="${iq.getAttribute('id')}"/>`;
- IQs.length = 0; // Empty the array
- _converse.api.connection.get()._dataRecv(mock.createRequest(result));
- iq = await u.waitUntil(() => IQs.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- features = [
- 'http://jabber.org/protocol/muc',
- 'jabber:iq:register',
- 'muc_passwordprotected',
- 'muc_hidden',
- 'muc_temporary',
- 'muc_membersonly',
- 'muc_unmoderated',
- 'muc_nonanonymous'
- ];
- const features_stanza =
- stx`<iq from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="New room name" type="text"/>
- ${features.map(f => stx`<feature var="${f}"/>`)}
- <x xmlns="jabber:x:data" type="result">
- <field var="FORM_TYPE" type="hidden">
- <value>http://jabber.org/protocol/muc#roominfo</value>
- </field>
- <field type="text-single" var="muc#roominfo_description" label="Description">
- <value>This is the description</value>
- </field>
- <field type="text-single" var="muc#roominfo_occupants" label="Number of occupants">
- <value>0</value>
- </field>
- </x>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- await u.waitUntil(() => new Promise(success => view.model.features.on('change', success)));
- info_el.click();
- modal = _converse.api.modal.get('converse-muc-details-modal');
- await u.waitUntil(() => u.isVisible(modal), 1000);
- features_list = modal.querySelector('.features-list');
- features_shown = Array.from(features_list.children).map((e) => e.textContent);
- expect(features_shown.length).toBe(6);
- expect(features_shown.join(' ')).toBe(
- 'Password protected - This groupchat requires a password before entry '+
- 'Hidden - This groupchat is not publicly searchable '+
- 'Members only - This groupchat is restricted to members only '+
- 'Temporary - This groupchat will disappear once the last person leaves '+
- 'Not anonymous - All other groupchat participants can see your XMPP address '+
- 'Not moderated - Participants entering this groupchat can write right away');
- expect(view.model.features.get('hidden')).toBe(true);
- expect(view.model.features.get('mam_enabled')).toBe(false);
- expect(view.model.features.get('membersonly')).toBe(true);
- expect(view.model.features.get('moderated')).toBe(false);
- expect(view.model.features.get('nonanonymous')).toBe(true);
- expect(view.model.features.get('open')).toBe(false);
- expect(view.model.features.get('passwordprotected')).toBe(true);
- expect(view.model.features.get('persistent')).toBe(false);
- expect(view.model.features.get('publicroom')).toBe(false);
- expect(view.model.features.get('semianonymous')).toBe(false);
- expect(view.model.features.get('temporary')).toBe(true);
- expect(view.model.features.get('unmoderated')).toBe(true);
- expect(view.model.features.get('unsecured')).toBe(false);
- await u.waitUntil(() => view.querySelector('.chatbox-title__text')?.textContent.trim() === 'New room name');
- }));
- it("indicates when a room is no longer anonymous",
- mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'coven@chat.shakespeare.lit', 'some1');
- const message =
- stx`<message xmlns="jabber:client"
- type="groupchat"
- to="romeo@montague.lit/_converse.js-27854181"
- from="coven@chat.shakespeare.lit">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <status code="104"/>
- <status code="172"/>
- </x>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-info').length);
- const chat_body = view.querySelector('.chatroom-body');
- expect(sizzle('.message:last', chat_body).pop().textContent.trim())
- .toBe('This groupchat is now no longer anonymous');
- }));
- it("informs users if they have been kicked out of the groupchat",
- mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
- const presence =
- stx`<presence from='lounge@montague.lit/romeo'
- to='romeo@montague.lit/pda'
- type='unavailable'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item affiliation='none' jid='romeo@montague.lit/pda' role='none'>
- <actor nick='Fluellen'/>
- <reason>Avaunt, you cullion!</reason>
- </item>
- <status code='110'/>
- <status code='307'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => !u.isVisible(view.querySelector('.chat-area')));
- expect(u.isVisible(view.querySelector('.occupants'))).toBeFalsy();
- const chat_body = view.querySelector('.chatroom-body');
- expect(chat_body.querySelectorAll('.disconnect-msg').length).toBe(3);
- expect(chat_body.querySelector('.disconnect-msg:first-child').textContent.trim()).toBe(
- 'You have been kicked from this groupchat');
- expect(chat_body.querySelector('.disconnect-msg:nth-child(2)').textContent.trim()).toBe(
- 'This action was done by Fluellen.');
- expect(chat_body.querySelector('.disconnect-msg:nth-child(3)').textContent.trim()).toBe(
- 'The reason given is: "Avaunt, you cullion!".');
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.DISCONNECTED);
- }));
- it("informs users if they have exited the groupchat due to a technical reason",
- mock.initConverse([], {}, async function (_converse) {
- await mock.openAndEnterMUC(_converse, 'lounge@montague.lit', 'romeo');
- const presence =
- stx`<presence from='lounge@montague.lit/romeo'
- to='romeo@montague.lit/pda'
- type='unavailable'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item affiliation='none' jid='romeo@montague.lit/pda' role='none'>
- <reason>Flux capacitor overload!</reason>
- </item>
- <status code='110'/>
- <status code='333'/>
- <status code='307'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const view = _converse.chatboxviews.get('lounge@montague.lit');
- await u.waitUntil(() => !u.isVisible(view.querySelector('.chat-area')));
- expect(u.isVisible(view.querySelector('.occupants'))).toBeFalsy();
- const chat_body = view.querySelector('.chatroom-body');
- expect(chat_body.querySelectorAll('.disconnect-msg').length).toBe(2);
- expect(chat_body.querySelector('.disconnect-msg:first-child').textContent.trim()).toBe(
- 'You have exited this groupchat due to a technical problem');
- expect(chat_body.querySelector('.disconnect-msg:nth-child(2)').textContent.trim()).toBe(
- 'The reason given is: "Flux capacitor overload!".');
- }));
- it("can be saved to, and retrieved from, browserStorage",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid, 'romeo');
- // We instantiate a new ChatBoxes collection, which by default
- // will be empty.
- await mock.openControlBox(_converse);
- const newchatboxes = new _converse.ChatBoxes();
- expect(newchatboxes.length).toEqual(0);
- // The chatboxes will then be fetched from browserStorage inside the
- // onConnected method
- newchatboxes.onConnected();
- await new Promise(resolve => _converse.api.listen.once('chatBoxesFetched', resolve));
- expect(newchatboxes.length).toEqual(2);
- // Check that the chatrooms retrieved from browserStorage
- // have the same attributes values as the original ones.
- const attrs = ['id', 'box_id', 'visible'];
- let new_attrs, old_attrs;
- for (let i=0; i<attrs.length; i++) {
- new_attrs = newchatboxes.models.map(m => m.attributes[attrs[i]]);
- old_attrs = _converse.chatboxes.models.map(m => m.attributes[attrs[i]]);
- expect(new_attrs.sort()).toEqual(old_attrs.sort());
- }
- }));
- it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- const model = await mock.openAndEnterMUC(_converse, muc_jid, 'romeo');
- spyOn(model, 'close').and.callThrough();
- spyOn(_converse.api, "trigger").and.callThrough();
- spyOn(model, 'leave');
- spyOn(_converse.api, 'confirm').and.callFake(() => Promise.resolve(true));
- const view = await u.waitUntil(() => _converse.chatboxviews.get('lounge@montague.lit'));
- const button = await u.waitUntil(() => view.querySelector('.close-chatbox-button'));
- button.click();
- await u.waitUntil(() => model.close.calls.count());
- expect(model.leave).toHaveBeenCalled();
- await u.waitUntil(() => _converse.api.trigger.calls.count());
- expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
- }));
- it("informs users of role and affiliation changes",
- mock.initConverse([], {}, async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid, 'romeo');
- const view = _converse.chatboxviews.get(muc_jid);
- let presence =
- stx`<presence from='lounge@montague.lit/annoyingGuy'
- id='27C55F89-1C6A-459A-9EB5-77690145D624'
- to='romeo@montague.lit/desktop'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item jid='annoyingguy@montague.lit' affiliation='member' role='participant'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo and annoyingGuy have entered the groupchat");
- presence =
- stx`<presence from='lounge@montague.lit/annoyingGuy'
- to='romeo@montague.lit/desktop'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item jid='annoyingguy@montague.lit' affiliation='member' role='visitor'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo has entered the groupchat\nannoyingGuy has been muted");
- presence =
- stx`<presence from='lounge@montague.lit/annoyingGuy'
- to='romeo@montague.lit/desktop'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item jid='annoyingguy@montague.lit' affiliation='member' role='participant'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chat-content__notifications').textContent.trim() ===
- "romeo has entered the groupchat\nannoyingGuy has been given a voice");
- // Check that we don't see an info message concerning the role,
- // if the affiliation has changed.
- presence =
- stx`<presence from='lounge@montague.lit/annoyingGuy'
- to='romeo@montague.lit/desktop'
- xmlns="jabber:client">
- <x xmlns='http://jabber.org/protocol/muc#user'>
- <item jid='annoyingguy@montague.lit' affiliation='none' role='visitor'/>
- </x>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() =>
- Array.from(view.querySelectorAll('.chat-info__message')).pop()?.textContent.trim() ===
- "annoyingGuy is no longer a member of this groupchat"
- );
- expect(1).toBe(1);
- }));
- it("notifies users of role and affiliation changes for members not currently in the groupchat",
- mock.initConverse([], {}, async function (_converse) {
- const muc_jid = 'lounge@montague.lit';
- await mock.openAndEnterMUC(_converse, muc_jid, 'romeo');
- const view = _converse.chatboxviews.get(muc_jid);
- let message =
- stx`<message from="lounge@montague.lit"
- id="2CF9013B-E8A8-42A1-9633-85AD7CA12F40"
- to="romeo@montague.lit"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item jid="absentguy@montague.lit" affiliation="member" role="none"/>
- </x>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- await u.waitUntil(() => view.model.occupants.length > 1);
- expect(view.model.occupants.length).toBe(2);
- expect(view.model.occupants.findWhere({'jid': 'absentguy@montague.lit'}).get('affiliation')).toBe('member');
- message =
- stx`<message from="lounge@montague.lit"
- id="2CF9013B-E8A8-42A1-9633-85AD7CA12F41"
- to="romeo@montague.lit"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc#user">
- <item jid="absentguy@montague.lit" affiliation="none" role="none"/>
- </x>
- </message>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(message));
- expect(view.model.occupants.length).toBe(2);
- expect(view.model.occupants.findWhere({'jid': 'absentguy@montague.lit'}).get('affiliation')).toBe('none');
- }));
- });
- describe("When attempting to enter a groupchat", function () {
- it("will show an error message if the groupchat requires a password",
- mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'protected@montague.lit';
- api.rooms.open(muc_jid, { nick: 'romeo' });
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- const presence =
- stx`<presence from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="auth">
- <not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- const chat_body = view.querySelector('.chatroom-body');
- await u.waitUntil(() => chat_body.querySelectorAll('form.chatroom-form').length === 1);
- expect(chat_body.querySelector('.chatroom-form label').textContent.trim())
- .toBe('This groupchat requires a password');
- // Let's submit the form
- spyOn(view.model, 'join');
- const input_el = view.querySelector('[name="password"]');
- input_el.value = 'secret';
- view.querySelector('input[type=submit]').click();
- expect(view.model.join).toHaveBeenCalledWith('romeo', 'secret');
- }));
- it("will show an error message if the groupchat is members-only and the user not included",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'members-only@muc.montague.lit'
- api.rooms.open(muc_jid, { nick: 'romeo' });
- const iq = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- expect(iq).toEqualStanza(stx`
- <iq from="romeo@montague.lit/orchard" to="${muc_jid}" type="get" xmlns="jabber:client" id="${iq.getAttribute('id')}">
- <query xmlns="http://jabber.org/protocol/disco#info"/>
- </iq>`);
- // State that the chat is members-only via the features IQ
- const features_stanza =
- stx`<iq from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="A Dark Cave" type="text"/>
- <feature var="http://jabber.org/protocol/muc"/>
- <feature var="muc_hidden"/>
- <feature var="muc_temporary"/>
- <feature var="muc_membersonly"/>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
- const presence =
- stx`<presence from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="auth">
- <registration-required xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- await u.waitUntil(() => view.querySelector('.chatroom-body converse-muc-disconnected .disconnect-msg:last-child')?.textContent?.trim() ===
- 'You are not on the member list of this groupchat.');
- }));
- it("will show an error message if the user has been banned",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'off-limits@muc.montague.lit'
- api.rooms.open(muc_jid, { nick: 'romeo' });
- const iq = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- const features_stanza =
- stx`<iq from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="A Dark Cave" type="text"/>
- <feature var="http://jabber.org/protocol/muc"/>
- <feature var="muc_hidden"/>
- <feature var="muc_temporary"/>
- </query>
- </iq>`
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
- const presence =
- stx`<presence
- from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error"
- xmlns="jabber:client">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="auth">
- <forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const el = await u.waitUntil(() => view.querySelector('.chatroom-body converse-muc-disconnected .disconnect-msg:last-child'));
- expect(el.textContent.trim()).toBe('You have been banned from this groupchat');
- expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.BANNED);
- }));
- it("will show an error message if the user is not allowed to have created the groupchat",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'impermissable@muc.montague.lit'
- api.rooms.open(muc_jid, { nick: 'romeo' });
- await mock.waitForNewMUCDiscoInfo(_converse, muc_jid);
- const presence =
- stx`<presence xmlns="jabber:client"
- from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="cancel">
- <not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const sent_IQs = _converse.api.connection.get().IQ_stanzas;
- while (sent_IQs.length) sent_IQs.pop();
- await mock.waitForMUCDiscoInfo(_converse, muc_jid);
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- const el = await u.waitUntil(() => view.querySelector('.chatroom-body converse-muc-disconnected .disconnect-msg:last-child'));
- expect(el.textContent.trim()).toBe('You are not allowed to create new groupchats.');
- }));
- it("will show an error message if the groupchat doesn't yet exist",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'nonexistent@muc.montague.lit'
- api.rooms.open(muc_jid, { nick: 'romeo' });
- const iq = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- const features_stanza =
- stx`<iq xmlns="jabber:client"
- from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="A Dark Cave" type="text"/>
- <feature var="http://jabber.org/protocol/muc"/>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
- const presence =
- stx`<presence xmlns="jabber:client"
- from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="cancel">
- <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const el = await u.waitUntil(() => view.querySelector('.chatroom-body converse-muc-disconnected .disconnect-msg:last-child'));
- expect(el.textContent.trim()).toBe("This groupchat does not (yet) exist.");
- }));
- it("will show an error message if the groupchat has reached its maximum number of participants",
- mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'maxed-out@muc.montague.lit'
- api.rooms.open(muc_jid, { nick: 'romeo' });
- const iq = await u.waitUntil(() => _converse.api.connection.get().IQ_stanzas.filter(
- iq => iq.querySelector(
- `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop());
- const features_stanza =
- stx`<iq from="${muc_jid}"
- id="${iq.getAttribute('id')}"
- to="romeo@montague.lit/desktop"
- type="result"
- xmlns="jabber:client">
- <query xmlns="http://jabber.org/protocol/disco#info">
- <identity category="conference" name="A Dark Cave" type="text"/>
- <feature var="http://jabber.org/protocol/muc"/>
- </query>
- </iq>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(features_stanza));
- const view = await u.waitUntil(() => _converse.chatboxviews.get(muc_jid));
- await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
- const presence =
- stx`<presence xmlns="jabber:client"
- from="${muc_jid}/romeo"
- id="${u.getUniqueId()}"
- to="romeo@montague.lit/pda"
- type="error">
- <x xmlns="http://jabber.org/protocol/muc"/>
- <error by="lounge@montague.lit" type="cancel">
- <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- </error>
- </presence>`;
- _converse.api.connection.get()._dataRecv(mock.createRequest(presence));
- const el = await u.waitUntil(() => view.querySelector('.chatroom-body converse-muc-disconnected .disconnect-msg:last-child'));
- expect(el.textContent.trim()).toBe("This groupchat has reached its maximum number of participants.");
- }));
- });
- describe("The affiliations delta", function () {
- it("can be computed in various ways", mock.initConverse([], {}, async function (_converse) {
- const { api } = _converse;
- const muc_jid = 'coven@chat.shakespeare.lit';
- api.rooms.open(muc_jid, { nick: 'romeo' });
- let exclude_existing = false;
- let remove_absentees = false;
- let new_list = [];
- let old_list = [];
- const muc_utils = converse.env.muc_utils;
- let delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- new_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- // When remove_absentees is false, then affiliations in the old
- // list which are not in the new one won't be removed.
- old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
- {'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- // With exclude_existing set to false, any changed affiliations
- // will be included in the delta (i.e. existing affiliations are included in the comparison).
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(1);
- expect(delta[0].jid).toBe('wiccarocks@shakespeare.lit');
- expect(delta[0].affiliation).toBe('member');
- // To also remove affiliations from the old list which are not
- // in the new list, we set remove_absentees to true
- remove_absentees = true;
- old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
- {'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(1);
- expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
- expect(delta[0].affiliation).toBe('none');
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, [], old_list);
- expect(delta.length).toBe(2);
- expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
- expect(delta[0].affiliation).toBe('none');
- expect(delta[1].jid).toBe('wiccarocks@shakespeare.lit');
- expect(delta[1].affiliation).toBe('none');
- // To only add a user if they don't already have an
- // affiliation, we set 'exclude_existing' to true
- exclude_existing = true;
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'admin'}];
- delta = muc_utils.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- }));
- });
- });
|