muc_fetch_members now accepts an array of affiliations
This commit is contained in:
parent
590a8862bc
commit
62ef18a027
@ -3,6 +3,7 @@
|
||||
|
||||
## 7.0.0 (Unreleased)
|
||||
|
||||
- [muc_fetch_members](https://conversejs.org/docs/html/configuration.html#muc-fetch-members) now also accepts an array of affiliations to fetch.
|
||||
- Replace Backbone with [Skeletor](https://github.com/skeletorjs/skeletor)
|
||||
- Start using [lit-html](https://lit-html.polymer-project.org/) instead of lodash for templating.
|
||||
- Bugfix. Handle stanza that clears the MUC subject
|
||||
|
@ -1079,6 +1079,8 @@ muc_fetch_members
|
||||
|
||||
* Default: ``true``
|
||||
|
||||
* Possible values: Array containing any of the following: ``['member', 'admin', 'owner']``
|
||||
|
||||
Determines whether Converse.js will fetch the member lists for a MUC
|
||||
(multi-user chat) when the user first enters it.
|
||||
|
||||
@ -1091,8 +1093,7 @@ The member lists consists of three lists of users who have the affiliations
|
||||
``member``, ``admin`` and ``owner`` respectively.
|
||||
|
||||
By fetching member lists, Converse.js will always show these users as
|
||||
participants of the MUC, which makes it behave a bit more like modern chat
|
||||
apps.
|
||||
participants of the MUC, giving them a permanent "presence" in the MUC.
|
||||
|
||||
|
||||
muc_history_max_stanzas
|
||||
|
29
spec/muc.js
29
spec/muc.js
@ -362,12 +362,11 @@
|
||||
['rosterGroupsFetched'], {'muc_fetch_members': true},
|
||||
async function (done, _converse) {
|
||||
|
||||
const sent_IQs = _converse.connection.IQ_stanzas;
|
||||
let sent_IQs = _converse.connection.IQ_stanzas;
|
||||
const muc_jid = 'lounge@montague.lit';
|
||||
spyOn(_converse.ChatRoomOccupants.prototype, 'fetchMembers').and.callThrough();
|
||||
await test_utils.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
||||
let view = _converse.chatboxviews.get(muc_jid);
|
||||
expect(view.model.occupants.fetchMembers).toHaveBeenCalled();
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation]')).length).toBe(3);
|
||||
|
||||
// Check in reverse order that we requested all three lists
|
||||
const owner_iq = sent_IQs.pop();
|
||||
@ -387,11 +386,33 @@
|
||||
`<iq id="${member_iq.getAttribute('id')}" to="${muc_jid}" type="get" xmlns="jabber:client">`+
|
||||
`<query xmlns="http://jabber.org/protocol/muc#admin"><item affiliation="member"/></query>`+
|
||||
`</iq>`);
|
||||
view.close();
|
||||
|
||||
_converse.connection.IQ_stanzas = [];
|
||||
sent_IQs = _converse.connection.IQ_stanzas;
|
||||
_converse.muc_fetch_members = false;
|
||||
await test_utils.openAndEnterChatRoom(_converse, 'orchard@montague.lit', 'romeo');
|
||||
view = _converse.chatboxviews.get('orchard@montague.lit');
|
||||
expect(view.model.occupants.fetchMembers.calls.count()).toBe(1);
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation]')).length).toBe(0);
|
||||
await view.close();
|
||||
|
||||
_converse.connection.IQ_stanzas = [];
|
||||
sent_IQs = _converse.connection.IQ_stanzas;
|
||||
_converse.muc_fetch_members = ['admin'];
|
||||
await test_utils.openAndEnterChatRoom(_converse, 'courtyard@montague.lit', 'romeo');
|
||||
view = _converse.chatboxviews.get('courtyard@montague.lit');
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation]')).length).toBe(1);
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation="admin"]')).length).toBe(1);
|
||||
view.close();
|
||||
|
||||
_converse.connection.IQ_stanzas = [];
|
||||
sent_IQs = _converse.connection.IQ_stanzas;
|
||||
_converse.muc_fetch_members = ['owner'];
|
||||
await test_utils.openAndEnterChatRoom(_converse, 'garden@montague.lit', 'romeo');
|
||||
view = _converse.chatboxviews.get('garden@montague.lit');
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation]')).length).toBe(1);
|
||||
expect(sent_IQs.filter(iq => iq.querySelector('query item[affiliation="owner"]')).length).toBe(1);
|
||||
view.close();
|
||||
done();
|
||||
}));
|
||||
|
||||
|
@ -460,9 +460,7 @@ converse.plugins.add('converse-muc', {
|
||||
|
||||
async onConnectionStatusChanged () {
|
||||
if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) {
|
||||
if (_converse.muc_fetch_members) {
|
||||
await this.occupants.fetchMembers();
|
||||
}
|
||||
await this.occupants.fetchMembers();
|
||||
await this.fetchMessages();
|
||||
await this.clearMessageQueue();
|
||||
/**
|
||||
@ -1339,9 +1337,7 @@ converse.plugins.add('converse-muc', {
|
||||
const aff_lists = await Promise.all(all_affiliations.map(a => this.getAffiliationList(a)));
|
||||
const old_members = aff_lists.reduce((acc, val) => (u.isErrorObject(val) ? acc: [...val, ...acc]), []);
|
||||
await this.setAffiliations(muc_utils.computeAffiliationsDelta(true, false, members, old_members));
|
||||
if (_converse.muc_fetch_members) {
|
||||
return this.occupants.fetchMembers();
|
||||
}
|
||||
await this.occupants.fetchMembers();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -2228,7 +2224,11 @@ converse.plugins.add('converse-muc', {
|
||||
},
|
||||
|
||||
async fetchMembers () {
|
||||
const all_affiliations = ['member', 'admin', 'owner'];
|
||||
const affs = _converse.muc_fetch_members;
|
||||
const all_affiliations = Array.isArray(affs) ? affs : (affs ? ['member', 'admin', 'owner'] : []);
|
||||
if (affs.length === 0) {
|
||||
return;
|
||||
}
|
||||
const aff_lists = await Promise.all(all_affiliations.map(a => this.chatroom.getAffiliationList(a)));
|
||||
const new_members = aff_lists.reduce((acc, val) => (u.isErrorObject(val) ? acc : [...val, ...acc]), []);
|
||||
const known_affiliations = all_affiliations.filter(a => !u.isErrorObject(aff_lists[all_affiliations.indexOf(a)]));
|
||||
|
@ -204,6 +204,9 @@
|
||||
|
||||
|
||||
utils.returnMemberLists = async function (_converse, muc_jid, members=[], affiliations=['member', 'owner', 'admin']) {
|
||||
if (affiliations.length === 0) {
|
||||
return;
|
||||
}
|
||||
const stanzas = _converse.connection.IQ_stanzas;
|
||||
|
||||
if (affiliations.includes('member')) {
|
||||
@ -302,9 +305,10 @@
|
||||
await room_creation_promise;
|
||||
const view = _converse.chatboxviews.get(muc_jid);
|
||||
await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
|
||||
if (_converse.muc_fetch_members) {
|
||||
await utils.returnMemberLists(_converse, muc_jid, members);
|
||||
}
|
||||
|
||||
const affs = _converse.muc_fetch_members;
|
||||
const all_affiliations = Array.isArray(affs) ? affs : (affs ? ['member', 'admin', 'owner'] : []);
|
||||
await utils.returnMemberLists(_converse, muc_jid, members, all_affiliations);
|
||||
await view.model.messages.fetched;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user