Ver código fonte

Add API method to retrieve buddy attributes. fixes #223

JC Brand 10 anos atrás
pai
commit
8843910d52
2 arquivos alterados com 16 adições e 0 exclusões
  1. 6 0
      converse.js
  2. 10 0
      spec/converse.js

+ 6 - 0
converse.js

@@ -4621,6 +4621,12 @@
         'initialize': function (settings, callback) {
         'initialize': function (settings, callback) {
             converse.initialize(settings, callback);
             converse.initialize(settings, callback);
         },
         },
+        'getBuddy': function (jid) {
+            var contact = converse.roster.get(Strophe.getBareJidFromJid(jid));
+            if (contact) {
+                return contact.attributes;
+            }
+        },
         'getRID': function () {
         'getRID': function () {
             if (converse.expose_rid_and_sid && typeof converse.connection !== "undefined") {
             if (converse.expose_rid_and_sid && typeof converse.connection !== "undefined") {
                 return converse.connection.rid || converse.connection._proto.rid;
                 return converse.connection.rid || converse.connection._proto.rid;

+ 10 - 0
spec/converse.js

@@ -43,5 +43,15 @@
             // Restore the connection
             // Restore the connection
             converse.connection = old_connection;
             converse.connection = old_connection;
         }, converse));
         }, converse));
+
+        it("has an API method for retrieving a buddy's attributes", $.proxy(function () {
+            var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
+            expect(converse_api.getBuddy(jid)).toBeFalsy();
+            test_utils.createContacts('current');
+            var attrs = converse_api.getBuddy(jid);
+            expect(typeof attrs).toBe('object');
+            expect(attrs.fullname).toBe(mock.cur_names[0]);
+            expect(attrs.jid).toBe(jid);
+        }, converse));
     }, converse, mock, test_utils));
     }, converse, mock, test_utils));
 }));
 }));