2
0
Эх сурвалжийг харах

Expand tests and found a bug in the process.

updates #785
JC Brand 8 жил өмнө
parent
commit
7ae2e46925

+ 1 - 1
docs/CHANGES.md

@@ -52,7 +52,7 @@
 - #366 Show the chat room occupant's JID in the tooltip (if you're allowed to see it). [jcbrand]
 - #694 The `notification_option` wasn't being used consistently. [jcbrand]
 - #770 Allow setting contact attrs on chats.open [Ape]
-- #785 Add presence priority handling [w3host, jcbrand]
+- #610, #785 Add presence priority handling [w3host, jcbrand]
 
 
 ## 2.0.6 (2017-02-13)

+ 50 - 0
spec/presence.js

@@ -57,6 +57,56 @@
             expect(contact.get('resources')['androidkhydmcKW']['priority']).toBe(0);
             expect(contact.get('resources')['androidkhydmcKW']['status']).toBe('xa');
 
+            stanza = $(
+            '<presence xmlns="jabber:client"'+
+            '          id="tYRdj-35"'+
+            '          to="dummy@localhost/converse.js-21770972"'+
+            '          from="'+contact_jid+'/other-resource">'+
+            '    <priority>2</priority>'+
+            '    <show>dnd</show>'+
+            '</presence>');
+            _converse.connection._dataRecv(test_utils.createRequest(stanza[0]));
+            expect(_converse.roster.get(contact_jid).get('chat_status')).toBe('dnd');
+            expect(_.keys(contact.get('resources')).length).toBe(3);
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['priority']).toBe(1);
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['status']).toBe('online');
+            expect(contact.get('resources')['androidkhydmcKW']['priority']).toBe(0);
+            expect(contact.get('resources')['androidkhydmcKW']['status']).toBe('xa');
+            expect(contact.get('resources')['other-resource']['priority']).toBe(2);
+            expect(contact.get('resources')['other-resource']['status']).toBe('dnd');
+
+            stanza = $(
+            '<presence xmlns="jabber:client"'+
+            '          id="tYRdj-35"'+
+            '          to="dummy@localhost/converse.js-21770972"'+
+            '          from="'+contact_jid+'/other-resource">'+
+            '    <priority>3</priority>'+
+            '    <show>away</show>'+
+            '</presence>');
+            _converse.connection._dataRecv(test_utils.createRequest(stanza[0]));
+            expect(_converse.roster.get(contact_jid).get('chat_status')).toBe('away');
+            expect(_.keys(contact.get('resources')).length).toBe(3);
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['priority']).toBe(1);
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['status']).toBe('online');
+            expect(contact.get('resources')['androidkhydmcKW']['priority']).toBe(0);
+            expect(contact.get('resources')['androidkhydmcKW']['status']).toBe('xa');
+            expect(contact.get('resources')['other-resource']['priority']).toBe(3);
+            expect(contact.get('resources')['other-resource']['status']).toBe('away');
+
+            stanza = $(
+            '<presence xmlns="jabber:client"'+
+            '          to="dummy@localhost/converse.js-21770972"'+
+            '          type="unavailable"'+
+            '          from="'+contact_jid+'/other-resource">'+
+            '</presence>');
+            _converse.connection._dataRecv(test_utils.createRequest(stanza[0]));
+            expect(_converse.roster.get(contact_jid).get('chat_status')).toBe('online');
+            expect(_.keys(contact.get('resources')).length).toBe(2);
+            expect(contact.get('resources')['androidkhydmcKW']['priority']).toBe(0);
+            expect(contact.get('resources')['androidkhydmcKW']['status']).toBe('xa');
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['priority']).toBe(1);
+            expect(contact.get('resources')['c71f218b-0797-4732-8a88-b42cb1d8557a']['status']).toBe('online');
+
             stanza = $(
             '<presence xmlns="jabber:client"'+
             '          to="dummy@localhost/converse.js-21770972"'+

+ 1 - 1
src/converse-core.js

@@ -887,7 +887,7 @@
                  */
                 var resources = this.get('resources');
                 if (_.isObject(resources) && _.size(resources)) {
-                    var val = _(resources).values().sortBy('priority').get(0);
+                    var val = _(resources).values().sortBy('priority').reverse().get(0);
                     if (!_.isUndefined(val)) {
                         return val.status;
                     }