diff --git a/converse.js b/converse.js index 06e0fa6d5..95d394599 100644 --- a/converse.js +++ b/converse.js @@ -1092,9 +1092,32 @@ } } } else { - var error = $presence.find('error'); - if ($(error).attr('type') == 'auth') { - this.$el.find('.chat-content').append('Sorry, this chatroom is restricted'); + var $error = $presence.find('error'), + $chat_content = this.$el.find('.chat-content'); + if ($error.attr('type') == 'auth') { + if ($error.find('not-authorized').length) { + $chat_content.append('This chatroom requires a password'); + } else if ($error.find('registration-required').length) { + $chat_content.append('You are not on the member list of this room'); + } else if ($error.find('forbidden').length) { + $chat_content.append('You have been banned from this room'); + } + } else if ($error.attr('type') == 'modify') { + if ($error.find('jid-malformed').length) { + $chat_content.append('No nickname was specified'); + } + } else if ($error.attr('type') == 'cancel') { + if ($error.find('not-allowed').length) { + $chat_content.append('You are not allowed to create new rooms'); + } else if ($error.find('not-acceptable').length) { + $chat_content.append("Your nickname doesn't conform to the room's policies"); + } else if ($error.find('conflict').length) { + $chat_content.append("Your nickname is already taken"); + } else if ($error.find('item-not-found').length) { + $chat_content.append("This room does not (yet) exist"); + } else if ($error.find('service-unavailable').length) { + $chat_content.append("This room has reached it's maximum number of occupants"); + } } } return true; @@ -1419,7 +1442,6 @@ this.$el.addClass('current-xmpp-contact'); this.$el.html(this.template(item.toJSON())); } - return this; }, @@ -1877,7 +1899,6 @@ converse.connection.send($pres().c('show').t(this.get('status')).up().c('status').t(status_message)); this.save({'status_message': status_message}); } - }); converse.XMPPStatusView = Backbone.View.extend({ @@ -1909,7 +1930,6 @@ '' + ''), - renderStatusChangeForm: function (ev) { ev.preventDefault(); var status_message = this.model.get('status') || 'offline'; diff --git a/spec/MainSpec.js b/spec/MainSpec.js index b6f625208..b6ddd8f53 100644 --- a/spec/MainSpec.js +++ b/spec/MainSpec.js @@ -713,5 +713,156 @@ expect(converse.connection.muc.leave).toHaveBeenCalled(); }, converse)); }, converse)); + + describe("When attempting to enter a chatroom", $.proxy(function () { + beforeEach($.proxy(function () { + var roomspanel = this.chatboxesview.views.controlbox.roomspanel; + var $input = roomspanel.$el.find('input.new-chatroom-name'); + var $server = roomspanel.$el.find('input.new-chatroom-server'); + $input.val('problematic'); + $server.val('muc.localhost'); + roomspanel.$el.find('form').submit(); + }, converse)); + + afterEach($.proxy(function () { + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.closeChat(); + }, converse)); + + it("will show an error message if the room requires a password", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'}) + .c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe('This chatroom requires a password'); + }, converse)); + + it("will show an error message if the room is members-only and the user not included", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'}) + .c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe('You are not on the member list of this room'); + }, converse)); + + it("will show an error message if the user has been banned", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'}) + .c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe('You have been banned from this room'); + }, converse)); + + it("will show an error message if no nickname was specified for the user", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'modify'}) + .c('jid-malformed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe('No nickname was specified'); + }, converse)); + + it("will show an error message if the user is not allowed to have created the room", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'}) + .c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe('You are not allowed to create new rooms'); + }, converse)); + + it("will show an error message if the user's nickname doesn't conform to room policy", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'}) + .c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe("Your nickname doesn't conform to the room's policies"); + }, converse)); + + it("will show an error message if the user's nickname is already taken", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'}) + .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe("Your nickname is already taken"); + }, converse)); + + it("will show an error message if the room doesn't yet exist", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'}) + .c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe("This room does not (yet) exist"); + }, converse)); + + it("will show an error message if the room has reached it's maximum number of occupants", $.proxy(function () { + var presence = $pres().attrs({ +   from:'coven@chat.shakespeare.lit/thirdwitch', +     id:'n13mt3l', +     to:'hag66@shakespeare.lit/pda', +     type:'error'}) + .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up() + .c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'}) + .c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree; + var view = this.chatboxesview.views['problematic@muc.localhost']; + view.onChatRoomPresence(presence, {'nick': 'dummy'}); + var $chat_content = view.$el.find('.chat-content'); + expect($chat_content.text()).toBe("This room has reached it's maximum number of occupants"); + }, converse)); + }, converse)); }, converse)); })); diff --git a/tests_main.js b/tests_main.js index 7aaf75e5b..992b78785 100644 --- a/tests_main.js +++ b/tests_main.js @@ -2,7 +2,7 @@ require(["jquery", "spec/MainSpec"], function($) { $(function($) { var jasmineEnv = jasmine.getEnv(); - jasmineEnv.updateInterval = 500; + jasmineEnv.updateInterval = 250; var htmlReporter = new jasmine.HtmlReporter();