Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 26 additions & 2 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;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The item here comes directly from a callback on Candy.Core.getConnection().roster, so I'm making an assumption that if it's coming all the way to _addRosterItem() that it's for someone who can be safely said to be in our roster. It can get here either through it's sibling _addRosterItems() or through a direct callback created in Candy.Core.Action.Jabber.Roster().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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,19 +481,34 @@ Candy.Core.Event = (function(self, Strophe, $) {
reason = reasonNode.text();
}

fromUser.jid = mediatedInvite.attr('from');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we modify a contact's JID?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, because it's empty. It's being set above as a blank new Candy.Core.Contact and that data isn't set. Because there are two paths here, --oh. Hi. I meant to remove this line when I gave up on trying to consolidate it into one place before the if's and just put them in separately. Thanks. :)


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

if(directInvite.length > 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between a mediated invite and a direct invite? Can we make any assumptions about whether the sender is in our global roster with one or the other?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can assume that either will come from someone in our roster. A mediated invite will actually come from the MUC service itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Thanks.

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 -
* (Candy.Core.Contact) from -
* (String) reason -
* (String) password -
* (String) continuedThread -
*/
invite = {
roomJid: directInvite.attr('jid'),
from: msg.attr('from'),
from: fromUser,
reason: directInvite.attr('reason'),
password: directInvite.attr('password'),
continuedThread: directInvite.attr('thread')
Expand Down