diff --git a/converse.js b/converse.js index 27f64a9bb..0ca4bed06 100644 --- a/converse.js +++ b/converse.js @@ -3693,7 +3693,7 @@ .c('item', {jid: this.model.get('jid'), subscription: "remove"}); converse.connection.sendIQ(iq, function (iq) { - this.model.unauthorize().destroy(); + this.model.destroy(); this.remove(); }.bind(this), function (err) { diff --git a/spec/controlbox.js b/spec/controlbox.js index 772fcf807..e19aa6d13 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -471,7 +471,6 @@ expect(window.confirm).toHaveBeenCalled(); expect(converse.connection.sendIQ).toHaveBeenCalled(); - expect(contact.unauthorize).toHaveBeenCalled(); expect(contact.removeFromRoster).toHaveBeenCalled(); expect(this.connection.sendIQ).toHaveBeenCalled(); expect(converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length).toEqual(0); @@ -492,7 +491,6 @@ fullname: name }); spyOn(window, 'confirm').andReturn(true); - spyOn(contact, 'unauthorize').andCallFake(function () { return contact; }); spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) { if (typeof callback === "function") { return callback(); } }); @@ -500,7 +498,6 @@ converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')") .siblings('.remove-xmpp-contact').click(); expect(window.confirm).toHaveBeenCalled(); - expect(contact.unauthorize).toHaveBeenCalled(); expect(this.connection.sendIQ).toHaveBeenCalled(); expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(false); }, this)); @@ -610,7 +607,6 @@ var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; var contact = this.roster.get(jid); spyOn(window, 'confirm').andReturn(true); - spyOn(contact, 'unauthorize').andCallFake(function () { return contact; }); spyOn(contact, 'removeFromRoster'); spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) { if (typeof callback === "function") { return callback(); } @@ -621,7 +617,6 @@ expect(window.confirm).toHaveBeenCalled(); expect(converse.connection.sendIQ).toHaveBeenCalled(); - expect(contact.unauthorize).toHaveBeenCalled(); expect(contact.removeFromRoster).toHaveBeenCalled(); expect(converse.rosterview.$el.find(".open-chat:contains('"+name+"')").length).toEqual(0); }, this)); @@ -642,7 +637,6 @@ fullname: name }); spyOn(window, 'confirm').andReturn(true); - spyOn(contact, 'unauthorize').andCallFake(function () { return contact; }); spyOn(contact, 'removeFromRoster'); spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) { if (typeof callback === "function") { return callback(); } @@ -653,7 +647,6 @@ .siblings('.remove-xmpp-contact').click(); expect(window.confirm).toHaveBeenCalled(); expect(this.connection.sendIQ).toHaveBeenCalled(); - expect(contact.unauthorize).toHaveBeenCalled(); expect(contact.removeFromRoster).toHaveBeenCalled(); expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none'); }, this)); diff --git a/spec/protocol.js b/spec/protocol.js index b467842b0..c3d710b02 100644 --- a/spec/protocol.js +++ b/spec/protocol.js @@ -54,7 +54,7 @@ test_utils.openContactsPanel(); }); - it("Mutual subscription between the users and a contact", $.proxy(function () { + it("Subscribe to contact, contact accepts and subscribes back", $.proxy(function () { /* The process by which a user subscribes to a contact, including * the interaction between roster items and subscription states. */ @@ -391,7 +391,7 @@ * have requested the roster, containing an updated roster * item for the contact with the 'subscription' attribute * set to a value of "none" and with no 'ask' attribute: - * + * * * */ + // FIXME: also add the stanza = $pres({ 'to': converse.bare_jid, 'from': 'contact@example.org', @@ -437,6 +438,89 @@ ); }, this)); }, converse)); + + it("Unsubscribe to a contact when subscription is mutual", function () { + var sent_IQ, IQ_id, jid = 'annegreet.gomez@localhost'; + runs(function () { + test_utils.createContacts('current'); + }); + waits(50); + runs(function () { + spyOn(window, 'confirm').andReturn(true); + // We now have a contact we want to remove + expect(this.roster.get(jid) instanceof this.RosterContact).toBeTruthy(); + + var sendIQ = this.connection.sendIQ; + spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { + sent_IQ = iq; + IQ_id = sendIQ.bind(this)(iq, callback, errback); + }); + + var $header = $('a:contains("My contacts")'); + // remove the first user + $($header.parent().nextUntil('dt', 'dd').find('.remove-xmpp-contact').get(0)).click(); + expect(window.confirm).toHaveBeenCalled(); + + /* Section 8.6 Removing a Roster Item and Cancelling All + * Subscriptions + * + * First the user is removed from the roster + * Because there may be many steps involved in completely + * removing a roster item and cancelling subscriptions in + * both directions, the roster management protocol includes + * a "shortcut" method for doing so. The process may be + * initiated no matter what the current subscription state + * is by sending a roster set containing an item for the + * contact with the 'subscription' attribute set to a value + * of "remove": + * + * + * + * + * + * + */ + expect(sent_IQ.toLocaleString()).toBe( + ""+ + ""+ + ""+ + ""+ + ""); + + // Receive confirmation from the contact's server + // + var stanza = $iq({'type': 'result', 'id':IQ_id}); + this.connection._dataRecv(test_utils.createRequest(stanza)); + // Our contact has now been removed + expect(typeof this.roster.get(jid) === "undefined").toBeTruthy(); + }.bind(converse)); + }.bind(converse)); + + it("Receiving a subscription request", function () { + runs(function () { + test_utils.createContacts('current'); // Create some contacts so that we can test positioning + }); + waits(50); + runs(function () { + /* + * + */ + var stanza = $pres({ + 'to': converse.bare_jid, + 'from': 'contact@example.org', + 'type': 'subscribe' + }); + this.connection._dataRecv(test_utils.createRequest(stanza)); + var $header = $('a:contains("Contact requests")'); + expect($header.length).toBe(1); + expect($header.is(":visible")).toBeTruthy(); + var $contacts = $header.parent().nextUntil('dt', 'dd'); + expect($contacts.length).toBe(1); + }.bind(converse)); + }.bind(converse)); }, converse, mock, test_utils)); }, converse, mock, test_utils)); }));