浏览代码

Fixes surrounding chat state notifications in MUC.

- Send chat state notifications with type groupchat for MUC.
- Don't show own chat state notifications if received from the server.
JC Brand 9 年之前
父节点
当前提交
1f805fa1e2
共有 1 个文件被更改,包括 25 次插入0 次删除
  1. 25 0
      src/converse-muc.js

+ 25 - 0
src/converse-muc.js

@@ -198,6 +198,7 @@
                     this.model.messages.on('add', this.onMessageAdded, this);
                     this.model.messages.on('add', this.onMessageAdded, this);
                     this.model.on('show', this.show, this);
                     this.model.on('show', this.show, this);
                     this.model.on('destroy', this.hide, this);
                     this.model.on('destroy', this.hide, this);
+                    this.model.on('change:chat_state', this.sendChatState, this);
 
 
                     this.occupantsview = new converse.ChatRoomOccupantsView({
                     this.occupantsview = new converse.ChatRoomOccupantsView({
                         model: new converse.ChatRoomOccupants({nick: this.model.get('nick')})
                         model: new converse.ChatRoomOccupants({nick: this.model.get('nick')})
@@ -328,11 +329,35 @@
                      * As laid out in the business rules in XEP-0085
                      * As laid out in the business rules in XEP-0085
                      * http://xmpp.org/extensions/xep-0085.html#bizrules-groupchat
                      * http://xmpp.org/extensions/xep-0085.html#bizrules-groupchat
                      */
                      */
+                    if (message.get('fullname') === this.model.get('nick')) {
+                        // Don't know about other servers, but OpenFire sends
+                        // back to you your own chat state notifications.
+                        // We ignore them here...
+                        return;
+                    }
                     if (message.get('chat_state') !== converse.GONE) {
                     if (message.get('chat_state') !== converse.GONE) {
                         converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
                         converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
                     }
                     }
                 },
                 },
 
 
+                sendChatState: function () {
+                    /* Sends a message with the status of the user in this chat session
+                     * as taken from the 'chat_state' attribute of the chat box.
+                     * See XEP-0085 Chat State Notifications.
+                     */
+                    var chat_state = this.model.get('chat_state');
+                    if (chat_state === converse.GONE) {
+                        // <gone/> is not applicable within MUC context
+                        return;
+                    }
+                    converse.connection.send(
+                        $msg({'to':this.model.get('jid'), 'type': 'groupchat'})
+                            .c(chat_state, {'xmlns': Strophe.NS.CHATSTATES}).up()
+                            .c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
+                            .c('no-permanent-store', {'xmlns': Strophe.NS.HINTS})
+                    );
+                },
+
                 sendChatRoomMessage: function (text) {
                 sendChatRoomMessage: function (text) {
                     var msgid = converse.connection.getUniqueId();
                     var msgid = converse.connection.getUniqueId();
                     var msg = $msg({
                     var msg = $msg({