瀏覽代碼

Bot message doesn't appear when it has the same id as its command

JC Brand 9 年之前
父節點
當前提交
29c2a96481
共有 3 個文件被更改,包括 20 次插入9 次删除
  1. 2 0
      docs/CHANGES.md
  2. 2 4
      src/converse-core.js
  3. 16 5
      src/converse-muc.js

+ 2 - 0
docs/CHANGES.md

@@ -5,6 +5,8 @@
 - Bugfix. Login form doesn't render after logging out, when `auto_reconnect = false` 
   [jcbrand]
 - Also indicate new day for the first day's messages. [jcbrand]
+- Chat bot messages don't appear when they have the same ids as their commands.
+  [jcbrand]
 
 ## 1.0.2 (2016-05-24)
 

+ 2 - 4
src/converse-core.js

@@ -1134,7 +1134,6 @@
 
 
         this.Message = Backbone.Model.extend({
-            idAttribute: 'msgid',
             defaults: function(){
                 return {
                     msgid: converse.connection.getUniqueId()
@@ -1173,7 +1172,6 @@
                     delayed = $delay.length > 0,
                     fullname = this.get('fullname'),
                     is_groupchat = $message.attr('type') === 'groupchat',
-                    msgid = $message.attr('id'),
                     chat_state = $message.find(converse.COMPOSING).length && converse.COMPOSING ||
                         $message.find(converse.PAUSED).length && converse.PAUSED ||
                         $message.find(converse.INACTIVE).length && converse.INACTIVE ||
@@ -1205,13 +1203,13 @@
                     delayed: delayed,
                     fullname: fullname,
                     message: body || undefined,
-                    msgid: msgid,
+                    msgid: $message.attr('id'),
                     sender: sender,
                     time: time
                 });
             }
         });
-        
+
         this.ChatBoxes = Backbone.Collection.extend({
             model: converse.ChatBox,
             comparator: 'time_opened',

+ 16 - 5
src/converse-muc.js

@@ -830,7 +830,6 @@
                     var $message = $(message),
                         $forwarded = $message.find('forwarded'),
                         $delay;
-
                     if ($forwarded.length) {
                         $message = $forwarded.children('message');
                         $delay = $forwarded.children('delay');
@@ -839,10 +838,22 @@
                         msgid = $message.attr('id'),
                         resource = Strophe.getResourceFromJid(jid),
                         sender = resource && Strophe.unescapeNode(resource) || '',
-                        subject = $message.children('subject').text();
-
-                    if (msgid && this.model.messages.findWhere({msgid: msgid})) {
-                        return true; // We already have this message stored.
+                        subject = $message.children('subject').text(),
+                        text = $message.find('body').text(),
+                        collision = msgid && this.model.messages.findWhere({'msgid': msgid});
+                    if (collision) {
+                        // We already have a message with this id stored.
+                        // It might therefore be a duplicate, but we cannot yet be
+                        // 100% sure. Some bots (like HAL in the prosody
+                        // chatroom) respond to commands with the same ID as
+                        // the original message. We therefore also check whether
+                        // the sender is the same and then lastly whether the
+                        // message text is the same.
+                        if (collision.get('fullname') === sender) {
+                            if (this.model.messages.findWhere({'message': text})) {
+                                return true;
+                            }
+                        }
                     }
                     if (subject) {
                         this.$el.find('.chatroom-topic').text(subject).attr('title', subject);