From e52a7754301085fd421c8d47064b08a8df86030f Mon Sep 17 00:00:00 2001 From: JC Brand Date: Tue, 14 Feb 2017 16:55:32 +0000 Subject: [PATCH] Bugfix. See below. "TypeError: this.sendConfiguration(...).then is not a function" when a room is created --- docs/CHANGES.md | 3 ++ spec/chatroom.js | 108 ++++++++++++++++++++++++++++++++++++++++++++ src/converse-muc.js | 10 +++- 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 5cfb5cd19..819ce8a01 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -20,6 +20,9 @@ - Allow JIDs not on the roster to be invited to a chatroom. [jcbrand] - #770 Allow setting contact attrs on chats.open [Ape] +## 2.0.7 (2017-02-14) +- Bugfix. 'TypeError: this.sendConfiguration(...).then is not a function' when an instant room is created. [jcbrand] + ## 2.0.6 (2017-02-13) - Escape user-generated input to prevent JS-injection attacks. (Thanks to SamWhited) [jcbrand] - #486 Honor existing mam user configuration [throwaway42] diff --git a/spec/chatroom.js b/spec/chatroom.js index 9381cc3d1..3e99ce570 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -235,6 +235,114 @@ })); }); + describe("An instant chat room", function () { + it("will be created when muc_instant_rooms is set to true", mock.initConverse(function (_converse) { + var sent_IQ, IQ_id; + var sendIQ = _converse.connection.sendIQ; + spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { + sent_IQ = iq; + IQ_id = sendIQ.bind(this)(iq, callback, errback); + }); + /* + * + * + * + * + * + * + * + */ + test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); + // We pretend this is a new room, so no disco info is returned. + var features_stanza = $iq({ + from: 'lounge@localhost', + 'id': IQ_id, + 'to': 'dummy@localhost/desktop', + 'type': 'error' + }).c('error', {'type': 'cancel'}) + .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"}); + _converse.connection._dataRecv(test_utils.createRequest(features_stanza)); + + + var view = _converse.chatboxviews.get('lounge@localhost'); + spyOn(view, 'join').andCallThrough(); + + /* + * + * + */ + expect(sent_IQ.toLocaleString()).toBe( + ""+ + "" + ); + /* * + * + * + * + * + */ + var stanza = $iq({ + 'type': 'error', + 'id': IQ_id, + 'from': view.model.get('jid'), + 'to': _converse.connection.jid + }).c('error', {'type': 'cancel'}) + .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"}); + _converse.connection._dataRecv(test_utils.createRequest(stanza)); + + // TODO: enter nickname + var $input = view.$el.find('input.new-chatroom-nick'); + $input.val('nicky').parents('form').submit(); + + expect(view.join).toHaveBeenCalled(); + + // The user has just entered the room (because join was called) + // and receives their own presence from the server. + // See example 24: + // http://xmpp.org/extensions/xep-0045.html#enter-pres + // + /* + * + * + * + * + * + * + */ + var presence = $pres({ + to:'dummy@localhost/resource', + from:'lounge@localhost/thirdwitch', + id:'5025e055-036c-4bc5-a227-706e7e352053' + }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'}) + .c('item').attrs({ + affiliation: 'owner', + jid: 'dummy@localhost/resource', + role: 'moderator' + }).up() + .c('status').attrs({code:'110'}).up() + .c('status').attrs({code:'201'}).nodeTree; + + _converse.connection._dataRecv(test_utils.createRequest(presence)); + var info_text = view.$el.find('.chat-content .chat-info').text(); + expect(info_text).toBe('A new room has been created'); + + // An instant room is created by saving the default configuratoin. + // + /* + * + * + */ + expect(sent_IQ.toLocaleString()).toBe( + ""+ + ""+ + ""); + })); + }); + describe("A Chat Room", function () { it("can have spaces and special characters in its name", mock.initConverse(function (_converse) { diff --git a/src/converse-muc.js b/src/converse-muc.js index e29e866e6..56841b7bc 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -1203,19 +1203,25 @@ * Parameters: * (HTMLElement) form: The configuration form DOM element. */ + var deferred = new $.Deferred(); var that = this; var $inputs = $(form).find(':input:not([type=button]):not([type=submit])'), configArray = []; $inputs.each(function () { configArray.push(utils.webForm2xForm(this)); }); - this.sendConfiguration(configArray); + this.sendConfiguration( + configArray, + deferred.resolve, + deferred.reject + ); this.$el.find('div.chatroom-form-container').hide( function () { $(this).remove(); that.$el.find('.chat-area').removeClass('hidden'); that.$el.find('.occupants').removeClass('hidden'); }); + return deferred.promise(); }, autoConfigureChatRoom: function (stanza) { @@ -1727,7 +1733,7 @@ * * See http://xmpp.org/extensions/xep-0045.html#createroom-instant */ - this.sendConfiguration().then(this.getRoomFeatures.bind(this)); + this.saveConfiguration().then(this.getRoomFeatures.bind(this)); }, onChatRoomPresence: function (pres) {