Jelajahi Sumber

[bugfix][Fix #48] keep reactions when updating a message

B Thibault 8 tahun lalu
induk
melakukan
bb0f2c5e7b
1 mengubah file dengan 10 tambahan dan 8 penghapusan
  1. 10 8
      srv/src/message.js

+ 10 - 8
srv/src/message.js

@@ -72,14 +72,16 @@ Message.prototype.update = function(e, ts) {
         this.edited = !!e["edited"];
         this.removed = !!e["removed"];
 
-        var _this = this;
-        this.reactions = {};
-        (e["reactions"] || []).forEach(function(r) {
-            _this.reactions[r["name"]] = [];
-            r["users"].forEach(function(userId) {
-                _this.reactions[r["name"]].push(userId);
+        if (e["reactions"]) {
+            var reactions = {};
+            e["reactions"].forEach(function(r) {
+                reactions[r["name"]] = [];
+                r["users"].forEach(function(userId) {
+                    reactions[r["name"]].push(userId);
+                });
             });
-        });
+            this.reactions = reactions;
+        }
     } else {
         this.removed = true;
     }
@@ -105,7 +107,7 @@ Message.prototype.toStatic = function() {
         ,"is_starred": this.is_starred || undefined
         ,"edited": this.edited || undefined
         ,"removed": this.removed || undefined
-        ,"reactions": reactions.length ? reactions : undefined
+        ,"reactions": reactions
         ,"isMeMessage": this instanceof MeMessage || undefined
         ,"isNotice": this instanceof NoticeMessage || undefined
     };