Skip to content

Commit

Permalink
Create new Candy.Core.Contact for invites, add inRoster boolean to ob…
Browse files Browse the repository at this point in the history
…ject.
  • Loading branch information
Melissa Noelle committed Jan 9, 2015
1 parent 5c7205e commit 3d9ee4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/core/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
Candy.Core.Contact = function(stropheRosterItem) {
/** Object: data
* Strophe Roster plugin item model containing:
* - jid
* - name
* - (String) jid
* - (String) name
* - subscription
* - groups
* - (Boolean) inRoster
*/
this.data = stropheRosterItem;
};
Expand Down Expand Up @@ -134,6 +135,10 @@ Candy.Core.Contact.prototype.getStatus = function() {
return status;
};

Candy.Core.Contact.prototype.isInRoster = function() {
return this.data.inRoster;
}

Candy.Core.Contact.prototype._weightForStatus = function(status) {
switch (status) {
case 'chat':
Expand Down
22 changes: 18 additions & 4 deletions src/core/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ Candy.Core.Event = (function(self, Strophe, $) {
},

_addRosterItem: function(item) {
item.inRoster = true;
var user = new Candy.Core.Contact(item);
Candy.Core.getRoster().add(user);
return user;
Expand Down Expand Up @@ -457,13 +458,21 @@ Candy.Core.Event = (function(self, Strophe, $) {
directInvite = msg.find('x[xmlns="jabber:x:conference"]'),
invite;

var fromUser;

if(mediatedInvite.length > 0) {
var passwordNode = msg.find('password'),
password,
reasonNode = mediatedInvite.find('reason'),
reason,
continueNode = mediatedInvite.find('continue');

if (!fromUser = Candy.Core.getRoster().get(mediatedInvite.attr('from'))) {
var fromUser = new Candy.Core.Contact;
fromUser.data.jid = mediatedInvite.attr('from');
fromUser.data.inRoster = false;
}

if(passwordNode.text() !== '') {
password = passwordNode.text();
}
Expand All @@ -472,18 +481,23 @@ Candy.Core.Event = (function(self, Strophe, $) {
reason = reasonNode.text();
}

fromUser.jid = mediatedInvite.attr('from');

invite = {
roomJid: msg.attr('from'),
from: mediatedInvite.attr('from'),
from: fromUser,
reason: reason,
password: password,
continuedThread: continueNode.attr('thread')
};
}

if(directInvite.length > 0) {
fromUser = Candy.Core.getRoster().get(msg.attr('from'));
room = Candy.Core.getRoom(directInvite.attr('jid'));
if (!fromUser = Candy.Core.getRoster().get(msg.attr('from'))) {
var fromUser = new Candy.Core.Contact;
fromUser.data.jid = msg.attr('from');
fromUser.data.inRoster = false;
}

/*
* (Candy.Core.Chatroom) room -
Expand All @@ -493,7 +507,7 @@ Candy.Core.Event = (function(self, Strophe, $) {
* (String) continuedThread -
*/
invite = {
room: room,
roomJid: directInvite.attr('jid'),
from: fromUser,
reason: directInvite.attr('reason'),
password: directInvite.attr('password'),
Expand Down

0 comments on commit 3d9ee4a

Please sign in to comment.