Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] candy:core:chat:invite triggerHandler #4

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
25 changes: 23 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
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
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 @@ -474,23 +483,35 @@ Candy.Core.Event = (function(self, Strophe, $) {

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
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
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
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;
}
invite = {
roomJid: directInvite.attr('jid'),
from: msg.attr('from'),
from: fromUser,
reason: directInvite.attr('reason'),
password: directInvite.attr('password'),
continuedThread: directInvite.attr('thread')
};
}

/*
* (Candy.Core.Chatroom) room -
* (Candy.Core.Contact) from -
* (String) reason -
* (String) password -
* (String) continuedThread -
*/
return invite;
},

Expand Down