Skip to content

Commit

Permalink
Fix handling an empty priority
Browse files Browse the repository at this point in the history
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.”
  • Loading branch information
bklang authored and benlangfeld committed Aug 1, 2015
1 parent 0d9fc66 commit cfc83b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/contact.js
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/candy/unit/core/contact.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit cfc83b5

Please sign in to comment.