More fixes after live testing of roster subscriptions.
Also, added code to acknowledge a subscription being accepted. See https://xmpp.org/rfcs/rfc3921.html#substates-ack
This commit is contained in:
parent
96396fdc6e
commit
ef7605d363
62
converse.js
62
converse.js
@ -3506,6 +3506,18 @@
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
acknowledgeSubscription: function () {
|
||||||
|
/* Upon receiving the presence stanza of type "subscribed",
|
||||||
|
* the user SHOULD acknowledge receipt of that subscription
|
||||||
|
* state notification by sending a presence stanza of type
|
||||||
|
* "subscribe" to the contact
|
||||||
|
*/
|
||||||
|
converse.connection.send($pres({
|
||||||
|
'type': 'subscribe',
|
||||||
|
'to': this.get('jid')
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
unauthorize: function (message) {
|
unauthorize: function (message) {
|
||||||
/* Unauthorize this contact's presence subscription
|
/* Unauthorize this contact's presence subscription
|
||||||
* Parameters:
|
* Parameters:
|
||||||
@ -3556,7 +3568,9 @@
|
|||||||
var chatStatus = this.get('chat_status');
|
var chatStatus = this.get('chat_status');
|
||||||
if ((converse.show_only_online_users && chatStatus !== 'online') || (converse.hide_offline_users && chatStatus === 'offline')) {
|
if ((converse.show_only_online_users && chatStatus !== 'online') || (converse.hide_offline_users && chatStatus === 'offline')) {
|
||||||
// If pending or requesting, show
|
// If pending or requesting, show
|
||||||
if ((this.get('ask') === 'subscribe') || (this.get('subscription') === 'from') || (this.get('requesting') === true)) {
|
if ((this.get('ask') === 'subscribe') ||
|
||||||
|
(this.get('subscription') === 'from') ||
|
||||||
|
(this.get('requesting') === true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -3678,12 +3692,11 @@
|
|||||||
|
|
||||||
acceptRequest: function (ev) {
|
acceptRequest: function (ev) {
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
this.model.authorize();
|
|
||||||
converse.roster.sendContactAddIQ(
|
converse.roster.sendContactAddIQ(
|
||||||
this.model.get('jid'),
|
this.model.get('jid'),
|
||||||
this.model.get('fullname'),
|
this.model.get('fullname'),
|
||||||
[],
|
[],
|
||||||
function (iq) { this.model.subscribe(); }.bind(this)
|
function (iq) { this.model.authorize().subscribe(); }.bind(this)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -3714,12 +3727,10 @@
|
|||||||
|
|
||||||
subscribeToSuggestedItems: function (msg) {
|
subscribeToSuggestedItems: function (msg) {
|
||||||
$(msg).find('item').each(function (i, items) {
|
$(msg).find('item').each(function (i, items) {
|
||||||
var $this = $(this),
|
var $this = $(this);
|
||||||
jid = $this.attr('jid'),
|
if (this.getAttribute('action') === 'add') {
|
||||||
action = $this.attr('action'),
|
converse.roster.addAndSubscribe(
|
||||||
fullname = $this.attr('name');
|
this.getAttribute('jid'), null, converse.xmppstatus.get('fullname'));
|
||||||
if (action === 'add') {
|
|
||||||
converse.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@ -3838,8 +3849,8 @@
|
|||||||
* Parameters:
|
* Parameters:
|
||||||
* (String) jid - The Jabber ID of the user who is unsubscribing
|
* (String) jid - The Jabber ID of the user who is unsubscribing
|
||||||
*/
|
*/
|
||||||
converse.xmppstatus.sendPresence('unsubscribe');
|
converse.connection.send($pres({'type': 'unsubscribe', 'to': jid}));
|
||||||
this.get(bare_jid).destroy(); // Will cause removeFromRoster to be called.
|
this.get(jid).destroy(); // Will cause removeFromRoster to be called.
|
||||||
},
|
},
|
||||||
|
|
||||||
getNumOnlineContacts: function () {
|
getNumOnlineContacts: function () {
|
||||||
@ -3924,6 +3935,9 @@
|
|||||||
groups.push(Strophe.getText(group));
|
groups.push(Strophe.getText(group));
|
||||||
});
|
});
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
|
if (subscription === "none" || subscription === "remove") {
|
||||||
|
return; // We're lazy when adding contacts.
|
||||||
|
}
|
||||||
this.create({
|
this.create({
|
||||||
ask: ask,
|
ask: ask,
|
||||||
fullname: item.getAttribute("name") || jid,
|
fullname: item.getAttribute("name") || jid,
|
||||||
@ -3932,18 +3946,9 @@
|
|||||||
subscription: subscription
|
subscription: subscription
|
||||||
}, {sort: false});
|
}, {sort: false});
|
||||||
} else {
|
} else {
|
||||||
if ((subscription === 'none') && (ask === null)) {
|
if (subscription === "remove") {
|
||||||
// When making a contact request, a roster push is
|
return contact.destroy(); // will trigger removeFromRoster
|
||||||
// received with the user being requested with
|
}
|
||||||
/* <iq xmlns="jabber:client" type="set" id="lx799">
|
|
||||||
<query xmlns="jabber:iq:roster" ver="30">
|
|
||||||
<item jid="jc@opkode.com" name="jc@opkode.com" subscription="none"/>
|
|
||||||
</query>
|
|
||||||
</iq>
|
|
||||||
*/
|
|
||||||
return; // XXX: figure out what's going on here.
|
|
||||||
// contact.destroy(); // This user is no longer in our roster
|
|
||||||
} else {
|
|
||||||
// We only find out about requesting contacts via the
|
// We only find out about requesting contacts via the
|
||||||
// presence handler, so if we receive a contact
|
// presence handler, so if we receive a contact
|
||||||
// here, we know they aren't requesting anymore.
|
// here, we know they aren't requesting anymore.
|
||||||
@ -3955,7 +3960,6 @@
|
|||||||
groups: groups
|
groups: groups
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
createContactFromVCard: function (iq, jid, fullname, img, img_type, url) {
|
createContactFromVCard: function (iq, jid, fullname, img, img_type, url) {
|
||||||
@ -3986,8 +3990,12 @@
|
|||||||
contact.authorize();
|
contact.authorize();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((contact) && (contact.get('subscription') != 'none')) {
|
if (contact) {
|
||||||
|
if (contact.get('subscription') != 'none') {
|
||||||
contact.authorize();
|
contact.authorize();
|
||||||
|
} else if (contact.get('ask') == "subscribe") {
|
||||||
|
contact.authorize();
|
||||||
|
}
|
||||||
} else if (!contact) {
|
} else if (!contact) {
|
||||||
converse.getVCard(
|
converse.getVCard(
|
||||||
bare_jid, this.createContactFromVCard.bind(this),
|
bare_jid, this.createContactFromVCard.bind(this),
|
||||||
@ -4022,7 +4030,9 @@
|
|||||||
if (contact && (status_message.text() != contact.get('status'))) {
|
if (contact && (status_message.text() != contact.get('status'))) {
|
||||||
contact.save({'status': status_message.text()});
|
contact.save({'status': status_message.text()});
|
||||||
}
|
}
|
||||||
if ((presence_type === 'subscribed') || (presence_type === 'unsubscribe')) {
|
if (presence_type === 'subscribed' && contact) {
|
||||||
|
contact.acknowledgeSubscription();
|
||||||
|
} else if (presence_type === 'unsubscribe') {
|
||||||
return;
|
return;
|
||||||
} else if (presence_type === 'subscribe') {
|
} else if (presence_type === 'subscribe') {
|
||||||
this.handleIncomingSubscription(jid);
|
this.handleIncomingSubscription(jid);
|
||||||
|
Loading…
Reference in New Issue
Block a user