Skip to content

Commit

Permalink
[FIX] Sending notifications from senders without a name (#18479)
Browse files Browse the repository at this point in the history
* Save error and skip from queue
  • Loading branch information
sampaiodiego committed Aug 13, 2020
1 parent 2fb78cf commit 9ad3a40
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions app/lib/server/functions/notifications/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions app/models/server/models/NotificationQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down
15 changes: 15 additions & 0 deletions app/models/server/raw/NotificationQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down Expand Up @@ -55,6 +68,8 @@ export class NotificationQueueRaw extends BaseRaw {
{ schedule: { $exists: false } },
{ schedule: { $lte: now } },
],
}, {
error: { $exists: false },
}],
}, {
$set: {
Expand Down
2 changes: 1 addition & 1 deletion app/notification-queue/server/NotificationQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions definition/INotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ export interface INotification {
ts: Date;
schedule?: Date;
sending?: Date;
error?: string;
items: NotificationItem[];
}

0 comments on commit 9ad3a40

Please sign in to comment.