Преглед изворни кода

Merge pull request #2 from alecghica/master

Code clean up + updated error message
JC Brand пре 12 година
родитељ
комит
e6c5a6c5c4
10 измењених фајлова са 29 додато и 27 уклоњено
  1. 1 1
      LICENSE_MIT.txt
  2. 2 2
      README.rst
  3. 1 1
      converse.css
  4. 16 14
      converse.js
  5. BIN
      images/error_icon.png
  6. BIN
      images/spinner.gif
  7. 1 1
      index.html
  8. 2 2
      spec/RosterSpec.js
  9. 4 4
      spec/StorageSpec.js
  10. 2 2
      tests_main.js

+ 1 - 1
LICENSE_MIT.txt

@@ -8,7 +8,7 @@ Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the "Software"),
 a copy of this software and associated documentation files (the "Software"),
 to deal in the Software without restriction, including without limitation
 to deal in the Software without restriction, including without limitation
 the rights to use, copy, modify, merge, publish, distribute, sublicense,
 the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the 
+and/or sell copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following conditions:
 Software is furnished to do so, subject to the following conditions:
 
 
 The above copyright notice and this permission notice shall be included
 The above copyright notice and this permission notice shall be included

+ 2 - 2
README.rst

@@ -12,7 +12,7 @@ Features
 
 
 It has the following features:
 It has the following features:
 
 
-* Manually or automically subscribe to other users. 
+* Manually or automically subscribe to other users.
 * With manual roster subscriptions, you can accept or decline contact requests.
 * With manual roster subscriptions, you can accept or decline contact requests.
 * Chat statuses (online, busy, away, offline)
 * Chat statuses (online, busy, away, offline)
 * Custom status message
 * Custom status message
@@ -20,7 +20,7 @@ It has the following features:
 * Third person messages (/me )
 * Third person messages (/me )
 * Multi-user chat in chatrooms
 * Multi-user chat in chatrooms
 * Topics can be set for chatrooms
 * Topics can be set for chatrooms
-* Full name and profile picture support 
+* Full name and profile picture support
 
 
 Converse.js is used by collective.xmpp.chat_, which is a Plone_ instant
 Converse.js is used by collective.xmpp.chat_, which is a Plone_ instant
 messaging add-on.
 messaging add-on.

+ 1 - 1
converse.css

@@ -30,7 +30,7 @@
 }
 }
 
 
 #connecting-to-chat {
 #connecting-to-chat {
-    background: url('/spinner.gif') no-repeat;
+    background: url(images/spinner.gif) no-repeat left;
     padding-left: 1.4em;
     padding-left: 1.4em;
 }
 }
 
 

+ 16 - 14
converse.js

@@ -460,8 +460,8 @@
                 }
                 }
                 else if (match[1] === "help") {
                 else if (match[1] === "help") {
                     msgs =  [
                     msgs =  [
-                        '<strong>/help</strong>: Show this menu', 
-                        '<strong>/clear</strong>: Remove messages' 
+                        '<strong>/help</strong>: Show this menu',
+                        '<strong>/clear</strong>: Remove messages'
                         ];
                         ];
                     this.addHelpMessages(msgs);
                     this.addHelpMessages(msgs);
                     return;
                     return;
@@ -501,7 +501,7 @@
                 this.$el.data('composing', false);
                 this.$el.data('composing', false);
             } else {
             } else {
                 composing = this.$el.data('composing');
                 composing = this.$el.data('composing');
-                if (!composing) { 
+                if (!composing) {
                     if (ev.keyCode != 47) {
                     if (ev.keyCode != 47) {
                         // We don't send composing messages if the message
                         // We don't send composing messages if the message
                         // starts with forward-slash.
                         // starts with forward-slash.
@@ -931,10 +931,10 @@
 
 
         initialize: function () {
         initialize: function () {
             xmppchat.connection.muc.join(
             xmppchat.connection.muc.join(
-                            this.model.get('jid'), 
-                            this.model.get('nick'), 
-                            $.proxy(this.onChatRoomMessage, this), 
-                            $.proxy(this.onChatRoomPresence, this), 
+                            this.model.get('jid'),
+                            this.model.get('nick'),
+                            $.proxy(this.onChatRoomMessage, this),
+                            $.proxy(this.onChatRoomPresence, this),
                             $.proxy(this.onChatRoomRoster, this));
                             $.proxy(this.onChatRoomRoster, this));
         },
         },
 
 
@@ -978,7 +978,7 @@
                 }
                 }
             } else {
             } else {
                 if (sender === this.model.get('nick')) {
                 if (sender === this.model.get('nick')) {
-                    // Our own message which is already appended 
+                    // Our own message which is already appended
                     return true;
                     return true;
                 } else {
                 } else {
                     $chat_content.find('div.chat-event').remove();
                     $chat_content.find('div.chat-event').remove();
@@ -1292,7 +1292,7 @@
                 that = this,
                 that = this,
                 subscription = item.get('subscription');
                 subscription = item.get('subscription');
             this.$el.addClass(item.get('presence_type'));
             this.$el.addClass(item.get('presence_type'));
-            
+
             if (ask === 'subscribe') {
             if (ask === 'subscribe') {
                 this.$el.addClass('pending-xmpp-contact');
                 this.$el.addClass('pending-xmpp-contact');
                 this.$el.html(this.pending_template(item.toJSON()));
                 this.$el.html(this.pending_template(item.toJSON()));
@@ -1678,14 +1678,14 @@
             store.set(xmppchat.connection.bare_jid+'-xmpp-status', value);
             store.set(xmppchat.connection.bare_jid+'-xmpp-status', value);
         },
         },
 
 
+        getStatusMessage: function () {
+            return store.get(xmppchat.connection.bare_jid+'-xmpp-custom-status');
+        },
+
         setStatusMessage: function (status_message) {
         setStatusMessage: function (status_message) {
             xmppchat.connection.send($pres({'type':this.getStatus()}).c('status').t(status_message));
             xmppchat.connection.send($pres({'type':this.getStatus()}).c('status').t(status_message));
             this.set({'status_message': status_message});
             this.set({'status_message': status_message});
             store.set(xmppchat.connection.bare_jid+'-xmpp-custom-status', status_message);
             store.set(xmppchat.connection.bare_jid+'-xmpp-custom-status', status_message);
-        },
-
-        getStatusMessage: function () {
-            return store.get(xmppchat.connection.bare_jid+'-xmpp-custom-status');
         }
         }
 
 
     });
     });
@@ -1815,8 +1815,10 @@
         }).render();
         }).render();
 
 
         $(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
         $(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
-            $connecting.show();
             $toggle.hide();
             $toggle.hide();
+            $connecting.show();
+            $connecting.html('Unable to communicate with chat server');
+            $connecting.css('background-image', "url(images/error_icon.png)");
             console.log("Connection Failed :(");
             console.log("Connection Failed :(");
         }, this));
         }, this));
 
 

BIN
images/error_icon.png


BIN
images/spinner.gif


+ 1 - 1
index.html

@@ -9,7 +9,7 @@
     </head>
     </head>
     <body>
     <body>
         <h1>Converse.js Demo Page</h1>
         <h1>Converse.js Demo Page</h1>
-        Log in with your Jabber/XMPP ID and password. 
+        Log in with your Jabber/XMPP ID and password.
         <!-- login dialog -->
         <!-- login dialog -->
         <div id='login_dialog' class='hidden'>
         <div id='login_dialog' class='hidden'>
             <label>Login ID:</label>
             <label>Login ID:</label>

+ 2 - 2
spec/RosterSpec.js

@@ -192,11 +192,11 @@
                     for (i=10; i<15; i++) {
                     for (i=10; i<15; i++) {
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
                     }
                     }
-                    // The next five are unavailable 
+                    // The next five are unavailable
                     for (i=15; i<20; i++) {
                     for (i=15; i<20; i++) {
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
                     }
                     }
-                    // The next 20 are offline 
+                    // The next 20 are offline
                     for (i=20; i<40; i++) {
                     for (i=20; i<40; i++) {
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
                         expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
                     }
                     }

+ 4 - 4
spec/StorageSpec.js

@@ -35,7 +35,7 @@
                 expect(this.storage.getOpenChats()).toEqual(['chat1@localhost', 'chat2@localhost']);
                 expect(this.storage.getOpenChats()).toEqual(['chat1@localhost', 'chat2@localhost']);
 
 
                 this.storage.addOpenChat('chat3@localhost');
                 this.storage.addOpenChat('chat3@localhost');
-                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost', 
+                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost',
                                                              'chat2@localhost',
                                                              'chat2@localhost',
                                                              'chat3@localhost']);
                                                              'chat3@localhost']);
             });
             });
@@ -47,12 +47,12 @@
                 this.storage.addOpenChat('chat1@localhost');
                 this.storage.addOpenChat('chat1@localhost');
                 this.storage.addOpenChat('chat2@localhost');
                 this.storage.addOpenChat('chat2@localhost');
                 this.storage.addOpenChat('chat3@localhost');
                 this.storage.addOpenChat('chat3@localhost');
-                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost', 
+                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost',
                                                              'chat2@localhost',
                                                              'chat2@localhost',
                                                              'chat3@localhost']);
                                                              'chat3@localhost']);
 
 
                 this.storage.removeOpenChat('chat2@localhost');
                 this.storage.removeOpenChat('chat2@localhost');
-                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost', 
+                expect(this.storage.getOpenChats()).toEqual(['chat1@localhost',
                                                              'chat3@localhost']);
                                                              'chat3@localhost']);
 
 
                 this.storage.removeOpenChat('chat1@localhost');
                 this.storage.removeOpenChat('chat1@localhost');
@@ -84,7 +84,7 @@
                     expect(msgs.length).toEqual(i+1);
                     expect(msgs.length).toEqual(i+1);
                     expect(msgs[i]).toEqual(jasmine.any(String));
                     expect(msgs[i]).toEqual(jasmine.any(String));
 
 
-                    // First two space separated strings are ISO date and direction 
+                    // First two space separated strings are ISO date and direction
                     var msg_arr = msgs[i].split(' ', 2);
                     var msg_arr = msgs[i].split(' ', 2);
                     // Check that first string is ISO format
                     // Check that first string is ISO format
                     expect(msg_arr[0]).toMatch(iso_regex);
                     expect(msg_arr[0]).toMatch(iso_regex);

+ 2 - 2
tests_main.js

@@ -1,5 +1,5 @@
-require(["jquery", 
-         "spec/StorageSpec", 
+require(["jquery",
+         "spec/StorageSpec",
          "spec/RosterSpec"], function($) {
          "spec/RosterSpec"], function($) {
 
 
     $(function($) {
     $(function($) {