From 55ae88455f4b1f4c525118fd260f09f2d73c1fc6 Mon Sep 17 00:00:00 2001 From: Melissa Noelle Date: Fri, 9 Jan 2015 14:12:52 -0500 Subject: [PATCH] Create new Candy.Core.Contact for invites, add inRoster boolean to object. --- src/core/contact.js | 9 +++++++-- src/core/event.js | 12 +++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/contact.js b/src/core/contact.js index 04c3cf50..fb684a5f 100644 --- a/src/core/contact.js +++ b/src/core/contact.js @@ -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; }; @@ -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': diff --git a/src/core/event.js b/src/core/event.js index fe66a017..47fe0c64 100644 --- a/src/core/event.js +++ b/src/core/event.js @@ -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; @@ -482,8 +483,13 @@ Candy.Core.Event = (function(self, Strophe, $) { } if(directInvite.length > 0) { - fromUser = Candy.Core.getRoster().get(msg.attr('from')); - room = Candy.Core.getRoom(directInvite.attr('jid')); + var fromUser; + + 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 - @@ -493,7 +499,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'),