Ver Fonte

Merge branch 'master' into roster_refactor

Conflicts:
	dev.html
JC Brand há 10 anos atrás
pai
commit
848c13eb62
5 ficheiros alterados com 128 adições e 16 exclusões
  1. 26 10
      converse.js
  2. 0 2
      dev.html
  3. 3 2
      docs/CHANGES.rst
  4. 2 2
      docs/source/development.rst
  5. 97 0
      spec/register.js

+ 26 - 10
converse.js

@@ -3084,7 +3084,13 @@
                 var contact_jid, $forwarded, $received, $sent,
                     msgid = $message.attr('id'),
                     chatbox, resource, roster_item,
-                    message_from = $message.attr('from');
+                    message_from = $message.attr('from'),
+                    message_to = $message.attr('to');
+
+                if(!_.contains([converse.connection.jid, converse.bare_jid], message_to)) {
+                    // Ignore messages sent to a different resource
+                    return true;
+                }
                 if (message_from === converse.connection.jid) {
                     // FIXME: Forwarded messages should be sent to specific resources,
                     // not broadcasted
@@ -4106,7 +4112,7 @@
                 if (contact.showInRoster()) {
                     if (this.model.get('state') === CLOSED) {
                         if (view.$el[0].style.display !== "none") { view.$el.hide(); }
-                        if (this.$el[0].style.display === "none") { this.$el.show(); }
+                        if (!this.$el.is(':visible')) { this.$el.show(); }
                     } else {
                         if (this.$el[0].style.display !== "block") { this.show(); }
                     }
@@ -4131,10 +4137,12 @@
             },
 
             show: function () {
-                // FIXME: There's a bug here, if show_only_online_users is true
-                // Possible solution, get the group, call _.each and check
-                // showInRoster
-                this.$el.nextUntil('dt').addBack().show();
+                this.$el.show();
+                _.each(this.getAll(), function (contactView) {
+                    if (contactView.model.showInRoster()) {
+                        contactView.$el.show();
+                    }
+                });
             },
 
             hide: function () {
@@ -5179,11 +5187,19 @@
                 var $inputs = $(ev.target).find(':input:not([type=button]):not([type=submit])'),
                     iq = $iq({type: "set"})
                         .c("query", {xmlns:Strophe.NS.REGISTER})
-                        .c("x", {xmlns: Strophe.NS.XFORM, type: 'submit'});
 
-                $inputs.each(function () {
-                    iq.cnode(utils.webForm2xForm(this)).up();
-                });
+                if (this.form_type == 'xform') {
+                    iq.c("x", {xmlns: Strophe.NS.XFORM, type: 'submit'});
+                    $inputs.each(function () {
+                        iq.cnode(utils.webForm2xForm(this)).up();
+                    });
+                } else {
+                    $inputs.each(function () {
+                        var $input = $(this);
+                        iq.c($input.attr('name'), {}, $input.val());
+                    });
+                }
+
                 converse.connection._addSysHandler(this._onRegisterIQ.bind(this), null, "iq", null, null);
                 converse.connection.send(iq);
                 this.setFields(iq.tree());

+ 0 - 2
dev.html

@@ -52,8 +52,6 @@
 <script>
     require(['converse'], function (converse) {
         converse.initialize({
-            allow_registration: false,
-            allow_logout: true,
             bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
             i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
             keepalive: true,

+ 3 - 2
docs/CHANGES.rst

@@ -6,6 +6,7 @@ Changelog
 
 * Add the ability to log in anonymously. [jcbrand]
 * Add the ability to log in automatically. [jcbrand]
+* #374 Fix collapsed group visibility on page load. [floriancargoet]
 
 0.9.2 (2015-04-09)
 ------------------
@@ -27,7 +28,7 @@ Changelog
 * Set the JID input field in the login form to ``type=email``. [chatme]
 * New configuration setting `allow_contact_removal <https://conversejs.org/docs/html/configuration.html#allow-contact-removal>`_ [jcbrand]
 * Document that event handlers receive 'event' obj as first arg. [jcbrand]
-* Add a test to check that notifications are played in chat rooms. [jcbrand] 
+* Add a test to check that notifications are played in chat rooms. [jcbrand]
 * #333 Enable automatic reconnection when ``prebind`` and ``prebind_url`` are specified. [jcbrand]
 * #339 Require the JID to be specified when using ``keepalive`` with ``prebind``. Also add a logout API method. [jcbrand]
 * #349 Indicate visitors in chat rooms. [c143]
@@ -214,7 +215,7 @@ Changelog
     to fetch the newest strophe.muc.plugin (for bugfix of #85).
 
     This release contains 3 different builds:
-    - converse.min.js 
+    - converse.min.js
     - converse-no-otr.min.js (Without OTR encryption)
     - converse-no-locales-no-otr.min.js (Without OTR encryption or any translations)
 

+ 2 - 2
docs/source/development.rst

@@ -369,7 +369,7 @@ Similar to chats.get API
 
 To open a single multi user chat box, provide the JID of the room::
 
-    converse.room.open('group@muc.example.com')
+    converse.rooms.open('group@muc.example.com')
 
 To return an array of chat boxes, provide an array of JIDs::
 
@@ -377,7 +377,7 @@ To return an array of chat boxes, provide an array of JIDs::
 
 To setup a custom nickname when joining the room, provide the optionnal nick argument::
 
-    converse.room.open('group@muc.example.com', 'mycustomnick')
+    converse.rooms.open('group@muc.example.com', 'mycustomnick')
 
 
 "settings" grouping

+ 97 - 0
spec/register.js

@@ -160,5 +160,102 @@
             expect(registerview.$('input[type=button]').length).toBe(1);
         }, converse));
 
+        it("will set form_type to legacy and submit it as legacy", $.proxy(function () {
+            var cbview = this.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = this.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(this.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            this.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Please choose a username, password and provide your email address').up()
+                    .c('username').up()
+                    .c('password').up()
+                    .c('email');
+            this.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('legacy');
+
+            registerview.$('input[name=username]').val('testusername');
+            registerview.$('input[name=password]').val('testpassword');
+            registerview.$('input[name=email]').val('test@email.local');
+
+            spyOn(converse.connection, 'send');
+
+            registerview.$('input[type=submit]').click();
+
+            expect(converse.connection.send).toHaveBeenCalled();
+            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+            expect($stanza.children('query').children().length).toBe(3);
+            expect($stanza.children('query').children()[0].tagName).toBe('username');
+        }, converse));
+
+        it("will set form_type to xform and submit it as xform", $.proxy(function () {
+            var cbview = this.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = this.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(this.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            this.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Using xform data').up()
+                    .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
+                        .c('instructions').t('xform instructions').up()
+                        .c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
+                        .c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
+                        .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up()
+            this.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('xform');
+
+            registerview.$('input[name=username]').val('testusername');
+            registerview.$('input[name=password]').val('testpassword');
+            registerview.$('input[name=email]').val('test@email.local');
+
+            spyOn(converse.connection, 'send');
+
+            registerview.$('input[type=submit]').click();
+
+            expect(converse.connection.send).toHaveBeenCalled();
+            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+            expect($stanza.children('query').children().length).toBe(1);
+            expect($stanza.children('query').children().children().length).toBe(3);
+            expect($stanza.children('query').children().children()[0].tagName).toBe('field');
+        }, converse));
+
     }, converse, mock, test_utils));
 }));