瀏覽代碼

Chat state notifications are now also sent out from chat rooms.

JC Brand 9 年之前
父節點
當前提交
fe46f2ee77
共有 4 個文件被更改,包括 24 次插入15 次删除
  1. 3 0
      docs/CHANGES.md
  2. 6 6
      spec/chatroom.js
  3. 2 8
      src/converse-chatview.js
  4. 13 1
      src/converse-muc.js

+ 3 - 0
docs/CHANGES.md

@@ -2,6 +2,9 @@
 
 ## 1.0.6 (Unreleased)
 - #674 Polish translation updated to the current master. [ser]
+- Typing (i.e. chat state) notifications are now also sent out from MUC rooms. [jcbrand]
+- `ChatRoomView.onChatRoomMessageSubmitted` has been renamed to
+  `onMessageSubmitted`, to make it the same as the method on `ChatBoxView`. [jcbrand]
 - New config option [muc_nickname_from_jid](https://conversejs.org/docs/html/configuration.html#muc_nickname_from_jid) [jcbrand]
 - New config option [muc_instant_rooms](https://conversejs.org/docs/html/configuration.html#muc_instant_rooms) [jcbrand]
 

+ 6 - 6
spec/chatroom.js

@@ -728,11 +728,11 @@
             it("to clear messages", function () {
                 test_utils.openChatRoom('lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
-                spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough();
+                spyOn(view, 'onMessageSubmitted').andCallThrough();
                 spyOn(view, 'clearChatRoomMessages');
                 view.$el.find('.chat-textarea').text('/clear');
                 view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
-                expect(view.onChatRoomMessageSubmitted).toHaveBeenCalled();
+                expect(view.onMessageSubmitted).toHaveBeenCalled();
                 expect(view.clearChatRoomMessages).toHaveBeenCalled();
 
             });
@@ -740,13 +740,13 @@
             it("to ban a user", function () {
                 test_utils.openChatRoom('lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
-                spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough();
+                spyOn(view, 'onMessageSubmitted').andCallThrough();
                 spyOn(view, 'setAffiliation').andCallThrough();
                 spyOn(view, 'showStatusNotification').andCallThrough();
                 spyOn(view, 'validateRoleChangeCommand').andCallThrough();
                 view.$el.find('.chat-textarea').text('/ban');
                 view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
-                expect(view.onChatRoomMessageSubmitted).toHaveBeenCalled();
+                expect(view.onMessageSubmitted).toHaveBeenCalled();
                 expect(view.validateRoleChangeCommand).toHaveBeenCalled();
                 expect(view.showStatusNotification).toHaveBeenCalledWith(
                     "Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.",
@@ -755,10 +755,10 @@
                 expect(view.setAffiliation).not.toHaveBeenCalled();
 
                 // Call now with the correct amount of arguments.
-                // XXX: Calling onChatRoomMessageSubmitted directly, trying
+                // XXX: Calling onMessageSubmitted directly, trying
                 // again via triggering Event doesn't work for some weird
                 // reason.
-                view.onChatRoomMessageSubmitted('/ban jid This is the reason');
+                view.onMessageSubmitted('/ban jid This is the reason');
                 expect(view.validateRoleChangeCommand.callCount).toBe(2);
                 expect(view.showStatusNotification.callCount).toBe(1);
                 expect(view.setAffiliation).toHaveBeenCalled();

+ 2 - 8
src/converse-chatview.js

@@ -523,17 +523,11 @@
                         message = $textarea.val();
                         $textarea.val('').focus();
                         if (message !== '') {
-                            // XXX: leaky abstraction from MUC
-                            if (this.model.get('type') === 'chatroom') {
-                                this.onChatRoomMessageSubmitted(message);
-                            } else {
-                                this.onMessageSubmitted(message);
-                            }
+                            this.onMessageSubmitted(message);
                             converse.emit('messageSend', message);
                         }
                         this.setChatState(converse.ACTIVE);
-                    // XXX: leaky abstraction from MUC
-                    } else if (this.model.get('type') !== 'chatroom') { // chat state data is currently only for single user chat
+                    } else {
                         // Set chat state to composing if keyCode is not a forward-slash
                         // (which would imply an internal command and not a message).
                         this.setChatState(converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH);

+ 13 - 1
src/converse-muc.js

@@ -321,6 +321,18 @@
                     this.showStatusNotification(__("Error: could not execute the command"), true);
                 },
 
+                handleChatStateMessage: function (message) {
+                    /* Override the method on the ChatBoxView base class to
+                     * ignore <gone/> notifications in groupchats.
+                     *
+                     * As laid out in the business rules in XEP-0085
+                     * http://xmpp.org/extensions/xep-0085.html#bizrules-groupchat
+                     */
+                    if (message.get('chat_state') !== converse.GONE) {
+                        converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
+                    }
+                },
+
                 sendChatRoomMessage: function (text) {
                     var msgid = converse.connection.getUniqueId();
                     var msg = $msg({
@@ -391,7 +403,7 @@
                     return this;
                 },
 
-                onChatRoomMessageSubmitted: function (text) {
+                onMessageSubmitted: function (text) {
                     /* Gets called when the user presses enter to send off a
                      * message in a chat room.
                      *