diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a88b2a63f813..da9570060ed4 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -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 diff --git a/app/lib/server/functions/notifications/mobile.js b/app/lib/server/functions/notifications/mobile.js index 02e5cb4d4f81..4d1b7482b126 100644 --- a/app/lib/server/functions/notifications/mobile.js +++ b/app/lib/server/functions/notifications/mobile.js @@ -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'; diff --git a/app/models/server/models/NotificationQueue.js b/app/models/server/models/NotificationQueue.js index 1210f5e73127..32eb7524c2c2 100644 --- a/app/models/server/models/NotificationQueue.js +++ b/app/models/server/models/NotificationQueue.js @@ -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 }); } } diff --git a/app/models/server/raw/NotificationQueue.ts b/app/models/server/raw/NotificationQueue.ts index 136671fba372..44a34a21be7f 100644 --- a/app/models/server/raw/NotificationQueue.ts +++ b/app/models/server/raw/NotificationQueue.ts @@ -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: { diff --git a/app/notification-queue/server/NotificationQueue.ts b/app/notification-queue/server/NotificationQueue.ts index 1927d888c228..7665a588c8ee 100644 --- a/app/notification-queue/server/NotificationQueue.ts +++ b/app/notification-queue/server/NotificationQueue.ts @@ -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) { diff --git a/definition/INotification.ts b/definition/INotification.ts index 6359f33dd612..d8153de9427f 100644 --- a/definition/INotification.ts +++ b/definition/INotification.ts @@ -40,5 +40,6 @@ export interface INotification { ts: Date; schedule?: Date; sending?: Date; + error?: string; items: NotificationItem[]; }