Commit 5fe23f47 authored by JC Brand's avatar JC Brand

modtools: Fetch affiliation list when we haven't fetched it by default

parent 2c5cde05
...@@ -237,7 +237,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -237,7 +237,7 @@ converse.plugins.add('converse-muc-views', {
this.users_with_affiliation = null; this.users_with_affiliation = null;
this.render(); this.render();
const affiliation = this.model.get('affiliation'); const affiliation = this.model.get('affiliation');
if (!_converse.muc_fetch_members || affiliation === 'outcast') { if (this.shouldFetchAffiliationsList()) {
this.users_with_affiliation = await this.chatroomview.model.getAffiliationList(affiliation); this.users_with_affiliation = await this.chatroomview.model.getAffiliationList(affiliation);
} else { } else {
this.users_with_affiliation = this.getUsersWithAffiliation(); this.users_with_affiliation = this.getUsersWithAffiliation();
...@@ -275,6 +275,20 @@ converse.plugins.add('converse-muc-views', { ...@@ -275,6 +275,20 @@ converse.plugins.add('converse-muc-views', {
})); }));
}, },
shouldFetchAffiliationsList () {
const affiliation = this.model.get('affiliation');
if (affiliation === 'none') {
return false;
}
const chatroom = this.chatroomview.model;
const auto_fetched_affs = chatroom.occupants.getAutoFetchedAffiliationLists();
if (auto_fetched_affs.includes(affiliation)) {
return false;
} else {
return true;
}
},
toggleForm (ev) { toggleForm (ev) {
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
......
...@@ -2238,15 +2238,19 @@ converse.plugins.add('converse-muc', { ...@@ -2238,15 +2238,19 @@ converse.plugins.add('converse-muc', {
} }
}, },
async fetchMembers () { getAutoFetchedAffiliationLists () {
const affs = _converse.muc_fetch_members; const affs = _converse.muc_fetch_members;
const all_affiliations = Array.isArray(affs) ? affs : (affs ? ['member', 'admin', 'owner'] : []); return Array.isArray(affs) ? affs : (affs ? ['member', 'admin', 'owner'] : []);
if (affs.length === 0) { },
async fetchMembers () {
const affiliations = this.getAutoFetchedAffiliationLists();
if (affiliations.length === 0) {
return; return;
} }
const aff_lists = await Promise.all(all_affiliations.map(a => this.chatroom.getAffiliationList(a))); const aff_lists = await Promise.all(affiliations.map(a => this.chatroom.getAffiliationList(a)));
const new_members = aff_lists.reduce((acc, val) => (u.isErrorObject(val) ? acc : [...val, ...acc]), []); 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)])); const known_affiliations = affiliations.filter(a => !u.isErrorObject(aff_lists[affiliations.indexOf(a)]));
const new_jids = new_members.map(m => m.jid).filter(m => m !== undefined); const new_jids = new_members.map(m => m.jid).filter(m => m !== undefined);
const new_nicks = new_members.map(m => !m.jid && m.nick || undefined).filter(m => m !== undefined); const new_nicks = new_members.map(m => !m.jid && m.nick || undefined).filter(m => m !== undefined);
const removed_members = this.filter(m => { const removed_members = this.filter(m => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment