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

More flexible invites #265

Closed
wants to merge 5 commits into from
Closed
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
57 changes: 43 additions & 14 deletions candy.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion candy.bundle.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions candy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion candy.min.map

Large diffs are not rendered by default.

69 changes: 54 additions & 15 deletions src/core/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,76 @@ Candy.Core.Event = (function(self, Strophe, $) {

// Inspect the message type.
if (type === 'normal' || type === 'undefined') {
// It is an invite
if($(msg).find('invite').length > 0) {
var mediated_invite = msg.find('invite'),
direct_invite = msg.find('x[xmlns="jabber:x:conference"]');

if(mediated_invite.length > 0) {
var password_node = msg.find('password'),
password = null,
continue_node = mediated_invite.find('continue'),
continued_thread = null;

if(password_node) {
password = password_node.text();
}

if(continue_node) {
continued_thread = continue_node.attr('thread');
}

/** Event: candy:core:chat:invite
* Incoming chat invite for a MUC.
*
* Parameters:
* (String) roomJid - The room the invite is to
* (String) from - User JID that invite is from text
* (String) reason - Reason for invite [default: '']
* (String) password - Password for the room [default: null]
* (String) continued_thread - The thread ID if this is a continuation of a 1-on-1 chat [default: null]
*/
$(Candy).triggerHandler('candy:core:chat:invite', {
roomJid: fromJid,
from: $(msg).find('invite').attr('from') || 'undefined',
reason: $(msg).find('invite').find('reason').html() || ''
from: mediated_invite.attr('from') || 'undefined',
reason: mediated_invite.find('reason').html() || '',
password: password,
continued_thread: continued_thread
});
// It is not an invite
} else {
/** Event: candy:core:chat:message:normal
* Messages with the type attribute of normal or those
* that do not have the optional type attribute.
}

if(direct_invite.length > 0) {
/** Event: candy:core:chat:invite
* Incoming chat invite for a MUC.
*
* Parameters:
* (String) type - Type of the message [default: message]
* (Object) message - Message object.
* (String) roomJid - The room the invite is to
* (String) from - User JID that invite is from text
* (String) reason - Reason for invite [default: '']
* (String) password - Password for the room [default: null]
* (String) continued_thread - The thread ID if this is a continuation of a 1-on-1 chat [default: null]
*/
// Detect message with type normal or with no type.
$(Candy).triggerHandler('candy:core:chat:message:normal', {
type: (type || 'normal'),
message: msg
$(Candy).triggerHandler('candy:core:chat:invite', {
roomJid: direct_invite.attr('jid'),
from: fromJid,
reason: direct_invite.attr('reason') || '',
password: direct_invite.attr('password'),
continued_thread: direct_invite.attr('thread')
});
}

/** Event: candy:core:chat:message:normal
* Messages with the type attribute of normal or those
* that do not have the optional type attribute.
*
* Parameters:
* (String) type - Type of the message [default: message]
* (Object) message - Message object.
*/
// Detect message with type normal or with no type.
$(Candy).triggerHandler('candy:core:chat:message:normal', {
type: (type || 'normal'),
message: msg
});

return true;
} else if (type !== 'groupchat' && type !== 'chat' && type !== 'error' && type !== 'headline') {
/** Event: candy:core:chat:message:other
Expand Down