[FIX] Sending notifications from senders without a name (#18479)

* Save error and skip from queue
pull/18420/head^2
Diego Sampaio 5 years ago committed by GitHub
parent c33c2ab63b
commit 87966634ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/codeql-analysis.yml
  2. 5
      app/lib/server/functions/notifications/mobile.js
  3. 1
      app/models/server/models/NotificationQueue.js
  4. 15
      app/models/server/raw/NotificationQueue.ts
  5. 2
      app/notification-queue/server/NotificationQueue.ts
  6. 1
      definition/INotification.ts

@ -24,7 +24,7 @@ jobs:
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1

@ -42,10 +42,7 @@ function enableNotificationReplyButton(room, username) {
}
export async function getPushData({ room, message, userId, senderUsername, senderName, notificationMessage, receiver, shouldOmitMessage = true }) {
let username = '';
if (settings.get('Push_show_username_room')) {
username = settings.get('UI_Use_Real_Name') === true ? senderName : senderUsername;
}
const username = (settings.get('Push_show_username_room') && settings.get('UI_Use_Real_Name') && senderName) || senderUsername;
const lng = receiver.language || settings.get('Language') || 'en';

@ -7,6 +7,7 @@ export class NotificationQueue extends Base {
this.tryEnsureIndex({ ts: 1 }, { expireAfterSeconds: 2 * 60 * 60 });
this.tryEnsureIndex({ schedule: 1 }, { sparse: true });
this.tryEnsureIndex({ sending: 1 }, { sparse: true });
this.tryEnsureIndex({ error: 1 }, { sparse: true });
}
}

@ -18,6 +18,19 @@ export class NotificationQueueRaw extends BaseRaw {
});
}
setErrorById(_id: string, error: any) {
return this.col.updateOne({
_id,
}, {
$set: {
error,
},
$unset: {
sending: 1,
},
});
}
removeById(_id: string) {
return this.col.deleteOne({ _id });
}
@ -55,6 +68,8 @@ export class NotificationQueueRaw extends BaseRaw {
{ schedule: { $exists: false } },
{ schedule: { $lte: now } },
],
}, {
error: { $exists: false },
}],
}, {
$set: {

@ -75,7 +75,7 @@ class NotificationClass {
NotificationQueue.removeById(notification._id);
} catch (e) {
console.error(e);
await NotificationQueue.unsetSendingById(notification._id);
await NotificationQueue.setErrorById(notification._id, e.message);
}
if (counter >= this.maxBatchSize) {

@ -40,5 +40,6 @@ export interface INotification {
ts: Date;
schedule?: Date;
sending?: Date;
error?: string;
items: NotificationItem[];
}

Loading…
Cancel
Save