qeled / discordie

Predictable JavaScript abstractions for Discord API.
https://qeled.github.io/discordie/
BSD 2-Clause "Simplified" License
190 stars 45 forks source link

Fix reaction count on new messages #64

Closed enebe-nb closed 7 years ago

enebe-nb commented 7 years ago

The message object returned by the discord api don't always have a reactions property. This must be created before to cache the message, or it will use the array object instanced on lib/models/Message.js. In the current behaviour all messages cached while not having a reaction, will have the reference for the same Array Object.

qeled commented 7 years ago

Would be better to fix it this way since sharing an empty array for messages with no reactions actually saves memory:

   if (e.type === Events.MESSAGE_REACTION_ADD) {
-    if (!message.reactions) {
+    if (!message.reactions || !message.reactions.length) {
       message = message.merge({reactions: []});

I can rebase the PR and edit it on my end, will this be fine?

enebe-nb commented 7 years ago

This way the whole Message object will be replicated every time it gets the first reaction (in case someone remove the reaction). It will work, so there's no problem.

qeled commented 7 years ago

Rebased.