Commit 1ce32878 authored by JC Brand's avatar JC Brand

Also add tests for case where contact declines request.

Did a bit of renaming and fixed a bug in updateContact where a user wasn't
created when it should have been.
parent 838ad136
...@@ -3484,7 +3484,7 @@ ...@@ -3484,7 +3484,7 @@
'status': '' 'status': ''
}, attributes)); }, attributes));
this.on('destroy', function () { this.removeFromRoster(); }.bind(this)); this.on('destroy', this.removeFromRoster, this);
}, },
subscribe: function (message) { subscribe: function (message) {
...@@ -3506,7 +3506,7 @@ ...@@ -3506,7 +3506,7 @@
return this; return this;
}, },
acknowledgeSubscription: function () { ackSubscribe: function () {
/* Upon receiving the presence stanza of type "subscribed", /* Upon receiving the presence stanza of type "subscribed",
* the user SHOULD acknowledge receipt of that subscription * the user SHOULD acknowledge receipt of that subscription
* state notification by sending a presence stanza of type * state notification by sending a presence stanza of type
...@@ -3518,6 +3518,19 @@ ...@@ -3518,6 +3518,19 @@
})); }));
}, },
ackUnsubscribe: function (jid) {
/* Upon receiving the presence stanza of type "unsubscribed",
* the user SHOULD acknowledge receipt of that subscription state
* notification by sending a presence stanza of type "unsubscribe"
* this step lets the user's server know that it MUST no longer
* send notification of the subscription state change to the user.
* Parameters:
* (String) jid - The Jabber ID of the user who is unsubscribing
*/
converse.connection.send($pres({'type': 'unsubscribe', 'to': this.get('jid')}));
this.destroy(); // Will cause removeFromRoster to be called.
},
unauthorize: function (message) { unauthorize: function (message) {
/* Unauthorize this contact's presence subscription /* Unauthorize this contact's presence subscription
* Parameters: * Parameters:
...@@ -3841,19 +3854,6 @@ ...@@ -3841,19 +3854,6 @@
} }
}, },
unsubscribe: function (jid) {
/* Upon receiving the presence stanza of type "unsubscribed",
* the user SHOULD acknowledge receipt of that subscription state
* notification by sending a presence stanza of type "unsubscribe"
* this step lets the user's server know that it MUST no longer
* send notification of the subscription state change to the user.
* Parameters:
* (String) jid - The Jabber ID of the user who is unsubscribing
*/
converse.connection.send($pres({'type': 'unsubscribe', 'to': jid}));
this.get(jid).destroy(); // Will cause removeFromRoster to be called.
},
getNumOnlineContacts: function () { getNumOnlineContacts: function () {
var count = 0, var count = 0,
ignored = ['offline', 'unavailable'], ignored = ['offline', 'unavailable'],
...@@ -3936,7 +3936,7 @@ ...@@ -3936,7 +3936,7 @@
groups.push(Strophe.getText(group)); groups.push(Strophe.getText(group));
}); });
if (!contact) { if (!contact) {
if (subscription === "none" || subscription === "remove") { if ((subscription === "none" && ask === null) || (subscription === "remove")) {
return; // We're lazy when adding contacts. return; // We're lazy when adding contacts.
} }
this.create({ this.create({
...@@ -4032,13 +4032,13 @@ ...@@ -4032,13 +4032,13 @@
contact.save({'status': status_message.text()}); contact.save({'status': status_message.text()});
} }
if (presence_type === 'subscribed' && contact) { if (presence_type === 'subscribed' && contact) {
contact.acknowledgeSubscription(); contact.ackSubscribe();
} else if (presence_type === 'unsubscribed' && contact) {
contact.ackUnsubscribe();
} else if (presence_type === 'unsubscribe') { } else if (presence_type === 'unsubscribe') {
return; return;
} else if (presence_type === 'subscribe') { } else if (presence_type === 'subscribe') {
this.handleIncomingSubscription(jid); this.handleIncomingSubscription(jid);
} else if (presence_type === 'unsubscribed') {
this.unsubscribe(bare_jid);
} else if (presence_type === 'unavailable' && contact) { } else if (presence_type === 'unavailable' && contact) {
contact.save({'chat_status': (contact.removeResource(resource) === 0) ? "offline" : chat_status}); contact.save({'chat_status': (contact.removeResource(resource) === 0) ? "offline" : chat_status});
} else if (contact) { // presence_type is undefined } else if (contact) { // presence_type is undefined
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment