Browse Source

fix bug: when sending message notifications, all unnotified were updated to notified, not only those which were really notified

mrkvon 3 years ago
parent
commit
07505cfb5c
2 changed files with 8 additions and 2 deletions
  1. 7
    1
      jobs/notifications.js
  2. 1
    1
      models/message/index.js

+ 7
- 1
jobs/notifications.js View File

@@ -19,8 +19,14 @@ async function messages() {
19 19
     await mailer.notifyMessages({ messages, from, to });
20 20
   }
21 21
 
22
+  // collect ids of the messages
23
+  // first as array of arrays (an array for each direction of each thread);
24
+  const threadIds = unnotified.map(({ messages }) => messages.map(msg => msg._key));
25
+  // and concatenate them to a single array
26
+  const ids = [].concat(...threadIds);
27
+
22 28
   // mark the messages as notified
23
-  await models.message.updateNotified(unnotified.map(msg => msg.id));
29
+  await models.message.updateNotified(ids);
24 30
 }
25 31
 
26 32
 async function contactRequests() {

+ 1
- 1
models/message/index.js View File

@@ -180,7 +180,7 @@ class Message extends Model {
180 180
    */
181 181
   static async updateNotified(ids) {
182 182
     const query = `
183
-      FOR msg IN messages FILTER msg.id IN @ids
183
+      FOR msg IN messages FILTER msg._key IN @ids
184 184
         UPDATE msg WITH { notified: true } IN messages
185 185
         RETURN MERGE(NEW, {id: NEW._key})
186 186
     `;