Explorar o código

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

JC Brand %!s(int64=5) %!d(string=hai) anos
pai
achega
5fe23f477f
Modificáronse 2 ficheiros con 24 adicións e 6 borrados
  1. 15 1
      src/converse-muc-views.js
  2. 9 5
      src/headless/converse-muc.js

+ 15 - 1
src/converse-muc-views.js

@@ -237,7 +237,7 @@ converse.plugins.add('converse-muc-views', {
                     this.users_with_affiliation = null;
                     this.render();
                     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);
                     } else {
                         this.users_with_affiliation = this.getUsersWithAffiliation();
@@ -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) {
                 ev.stopPropagation();
                 ev.preventDefault();

+ 9 - 5
src/headless/converse-muc.js

@@ -2238,15 +2238,19 @@ converse.plugins.add('converse-muc', {
                 }
             },
 
-            async fetchMembers () {
+            getAutoFetchedAffiliationLists () {
                 const affs = _converse.muc_fetch_members;
-                const all_affiliations = Array.isArray(affs) ? affs :  (affs ? ['member', 'admin', 'owner'] : []);
-                if (affs.length === 0) {
+                return Array.isArray(affs) ? affs :  (affs ? ['member', 'admin', 'owner'] : []);
+            },
+
+            async fetchMembers () {
+                const affiliations = this.getAutoFetchedAffiliationLists();
+                if (affiliations.length === 0) {
                     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 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_nicks = new_members.map(m => !m.jid && m.nick || undefined).filter(m => m !== undefined);
                 const removed_members = this.filter(m => {