Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/candy-chat/candy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Klang <bklang@mojolingo.com>2015-07-26 22:50:22 +0300
committerBen Langfeld <ben@langfeld.me>2015-08-01 19:09:29 +0300
commitcfc83b56420bb4935bd1b7980f7090962b0e62f5 (patch)
tree09745eee031d90df03693da0d17ea30663fef0dd
parent0d9fc661c796a630225cf5ffd0151c4f50ecd1d8 (diff)
Fix handling an empty priority
Per http://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.3 “If no priority is provided, a server SHOULD consider the priority to be zero.”
-rw-r--r--src/core/contact.js7
-rw-r--r--tests/candy/unit/core/contact.js16
2 files changed, 22 insertions, 1 deletions
diff --git a/src/core/contact.js b/src/core/contact.js
index 51985a3..0f56ca9 100644
--- a/src/core/contact.js
+++ b/src/core/contact.js
@@ -113,7 +113,12 @@ Candy.Core.Contact.prototype.getStatus = function() {
highestResourcePriority;
$.each(this.data.resources, function(resource, obj) {
- var resourcePriority = parseInt(obj.priority, 10);
+ var resourcePriority;
+ if (obj.priority === undefined || obj.priority === '') {
+ resourcePriority = 0;
+ } else {
+ resourcePriority = parseInt(obj.priority, 10);
+ }
if (obj.show === '' || obj.show === null || obj.show === undefined) {
// TODO: Submit this as a bugfix to strophejs-plugins' roster plugin
diff --git a/tests/candy/unit/core/contact.js b/tests/candy/unit/core/contact.js
index 2059630..2e926dc 100644
--- a/tests/candy/unit/core/contact.js
+++ b/tests/candy/unit/core/contact.js
@@ -47,6 +47,22 @@ define([
expect(contact.getGroups()).to.eql(['Friends']);
});
+ bdd.it('defaults the priority to 0 when not defined', function() {
+ contact.data.resources = {
+ 'resource1': {
+ show: 'away',
+ status: 'Hanging out',
+ priority: 0
+ },
+ 'resource2': {
+ show: 'available',
+ status: 'Not Hanging out',
+ priority: ""
+ }
+ };
+ expect(contact.getStatus()).to.eql('available');
+ });
+
bdd.describe('aggregate status', function () {
bdd.describe('when there are no online resources', function () {
bdd.it('is unavailable when there are no online resources', function () {