Переглянути джерело

fix(onPresence): extract anonymous function

master
Hristo Terezov 2 роки тому
джерело
коміт
69eee5b5b5
1 змінених файлів з 35 додано та 33 видалено
  1. 35
    33
      modules/xmpp/ChatRoom.js

+ 35
- 33
modules/xmpp/ChatRoom.js Переглянути файл

@@ -91,6 +91,40 @@ export function filterNodeFromPresenceJSON(pres, nodeName) {
91 91
  */
92 92
 const MEMBERS_AFFILIATIONS = [ 'owner', 'admin', 'member' ];
93 93
 
94
+/**
95
+ * Process nodes to extract data needed for MUC_JOINED and MUC_MEMBER_JOINED events.
96
+ *
97
+ */
98
+function extractIdentityInformation(node, hiddenFromRecorderFeatureEnabled) {
99
+    const identity = {};
100
+    const userInfo = node.children.find(c => c.tagName === 'user');
101
+
102
+    if (userInfo) {
103
+        identity.user = {};
104
+        const tags = [ 'id', 'name', 'avatar' ];
105
+
106
+        if (hiddenFromRecorderFeatureEnabled) {
107
+            tags.push('hidden-from-recorder');
108
+        }
109
+
110
+        for (const tag of tags) {
111
+            const child
112
+                = userInfo.children.find(c => c.tagName === tag);
113
+
114
+            if (child) {
115
+                identity.user[tag] = child.value;
116
+            }
117
+        }
118
+    }
119
+    const groupInfo = node.children.find(c => c.tagName === 'group');
120
+
121
+    if (groupInfo) {
122
+        identity.group = groupInfo.value;
123
+    }
124
+
125
+    return identity;
126
+}
127
+
94 128
 /**
95 129
  *
96 130
  */
@@ -496,38 +530,6 @@ export default class ChatRoom extends Listenable {
496 530
         parser.packet2JSON(pres, nodes);
497 531
         this.lastPresences[from] = nodes;
498 532
 
499
-        // process nodes to extract data needed for MUC_JOINED and
500
-        // MUC_MEMBER_JOINED events
501
-        const extractIdentityInformation = node => {
502
-            const identity = {};
503
-            const userInfo = node.children.find(c => c.tagName === 'user');
504
-
505
-            if (userInfo) {
506
-                identity.user = {};
507
-                const tags = [ 'id', 'name', 'avatar' ];
508
-
509
-                if (this.options.hiddenFromRecorderFeatureEnabled) {
510
-                    tags.push('hidden-from-recorder');
511
-                }
512
-
513
-                for (const tag of tags) {
514
-                    const child
515
-                        = userInfo.children.find(c => c.tagName === tag);
516
-
517
-                    if (child) {
518
-                        identity.user[tag] = child.value;
519
-                    }
520
-                }
521
-            }
522
-            const groupInfo = node.children.find(c => c.tagName === 'group');
523
-
524
-            if (groupInfo) {
525
-                identity.group = groupInfo.value;
526
-            }
527
-
528
-            return identity;
529
-        };
530
-
531 533
         for (let i = 0; i < nodes.length; i++) {
532 534
             const node = nodes[i];
533 535
 
@@ -553,7 +555,7 @@ export default class ChatRoom extends Listenable {
553 555
                 member.statsID = node.value;
554 556
                 break;
555 557
             case 'identity':
556
-                member.identity = extractIdentityInformation(node);
558
+                member.identity = extractIdentityInformation(node, this.options.hiddenFromRecorderFeatureEnabled);
557 559
                 break;
558 560
             case 'features': {
559 561
                 member.features = this._extractFeatures(node);

Завантаження…
Відмінити
Зберегти