浏览代码

'ask' attribute of 'subscribe' is only for 'pending out' requests.

Did more investigation with regards to subscription requests.

As far as I can tell, roster updates will only show ask='request' for 'pending
out' requests.

For 'pending in' requests (what converse.js calls requesting contacts), roster
updates are not used and instead a presence stanza with type 'subscribe' is
used.

This makes sense. When sending a presence with type 'subscribe', we need a way
to keep track of our outgoing subscriptions. The XMPP server helps us do this by
adding a user to our roster with ask='request' and subscription='none'.

When our contact receives our presence with type 'subscribe', they have the
information they need. If they go offline and online again, the XMPP server
will resend the presence with type 'subscribe'. So a roster item is not needed.

In convere.js's internal representation of the roster (via the RosterItems backbone
object) we need to add roster items for 'pending in' contacts so that we can
render them and we need to know whether they are 'pending in' or 'pending out'.

We already know they're 'pending out' when ask='subscribe' and
subscription='none'. For 'pending in', since these roster items are only stored
locally and not on the XMPP server (because 'pending in' requests are handled
via <presence> stanzas and not the roster) we add a special attribute
'requesting'.
JC Brand 11 年之前
父节点
当前提交
7a5bc7fe65
共有 2 个文件被更改,包括 13 次插入8 次删除
  1. 10 6
      converse.js
  2. 3 2
      spec/ControlBoxSpec.js

+ 10 - 6
converse.js

@@ -2468,6 +2468,7 @@
             render: function () {
                 var item = this.model,
                     ask = item.get('ask'),
+                    requesting  = item.get('requesting'),
                     subscription = item.get('subscription');
 
                 var classes_to_remove = [
@@ -2488,7 +2489,7 @@
                 if ((ask === 'subscribe') && (subscription == 'none')) {
                     this.$el.addClass('pending-xmpp-contact');
                     this.$el.html(this.pending_template(item.toJSON()));
-                } else if ((ask === 'subscribe') && (subscription == 'from')) {
+                } else if (requesting === true) {
                     this.$el.addClass('requesting-xmpp-contact');
                     this.$el.html(this.request_template(item.toJSON()));
                     converse.controlboxtoggle.showControlBox();
@@ -2709,8 +2710,9 @@
                                 $.proxy(function (jid, fullname, img, img_type, url) {
                                     this.add({
                                         jid: bare_jid,
-                                        subscription: 'from',
-                                        ask: 'subscribe',
+                                        subscription: 'none',
+                                        ask: null,
+                                        requesting: true,
                                         fullname: fullname,
                                         image: img,
                                         image_type: img_type,
@@ -2725,8 +2727,9 @@
                                     // well?
                                     this.add({
                                         jid: bare_jid,
-                                        subscription: 'from',
-                                        ask: 'subscribe',
+                                        subscription: 'none',
+                                        ask: null,
+                                        requesting: true,
                                         fullname: jid,
                                         is_last: true
                                     });
@@ -2891,12 +2894,13 @@
                         view = this.rosteritemviews[item.id],
                         ask = item.get('ask'),
                         subscription = item.get('subscription'),
+                        requesting  = item.get('requesting'),
                         crit = {order:'asc'};
 
                     if ((ask === 'subscribe') && (subscription == 'none')) {
                         $pending_contacts.after(view.render().el);
                         $pending_contacts.after($pending_contacts.siblings('dd.pending-xmpp-contact').tsort(crit));
-                    } else if ((ask === 'subscribe') && (subscription == 'from')) {
+                    } else if (requesting === true) {
                         $contact_requests.after(view.render().el);
                         $contact_requests.after($contact_requests.siblings('dd.requesting-xmpp-contact').tsort(crit));
                     } else if (subscription === 'both' || subscription === 'to') {

+ 3 - 2
spec/ControlBoxSpec.js

@@ -321,8 +321,9 @@
                 for (i=0; i<mock.req_names.length; i++) {
                     this.roster.create({
                         jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
-                        subscription: 'from',
-                        ask: 'subscribe',
+                        subscription: 'none',
+                        ask: null,
+                        requesting: true,
                         fullname: mock.req_names[i],
                         is_last: i===(mock.req_names.length-1)
                     });