Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/models/server/raw/NotificationQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ export class NotificationQueueRaw extends BaseRaw {
return op.deletedCount;
}

/**
* Expedite scheduled notifications for given user, to be scheduled now.
* Used when the user that was "online" becomes "away" or "offline".
* @param uid User ID
*/
async expediteSheduleByUserId(uid: string) {
const now = new Date();
return this.col.updateMany({
uid,
schedule: { $gt: now },
}, {
$set: {
schedule: now,
},
});
}

async findNextInQueueOrExpired(expired: Date): Promise<INotification | undefined> {
const now = new Date();

Expand Down
13 changes: 13 additions & 0 deletions app/notification-queue/server/NotificationQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ class NotificationClass {
items,
});
}

/**
* Expedite scheduled notifications for given user, to be scheduled now.
* Used when the user that was "online" becomes "away" or "offline".
* @param uid User ID
*/
async expediteSheduleByUserId(uid: string) {
const updateResult = await NotificationQueue.expediteSheduleByUserId(uid);
if (updateResult.modifiedCount > 0) {
console.debug(`Expedited ${updateResult.modifiedCount} notifications for user ${uid}`);
}
return updateResult;
}
}

export const Notification = new NotificationClass();
Expand Down
6 changes: 6 additions & 0 deletions imports/users-presence/server/activeUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UserPresenceEvents } from 'meteor/konecty:user-presence';

import { Notifications } from '../../../app/notifications/server';
import { settings } from '../../../app/settings/server';
import { Notification } from '../../../app/notification-queue/server/NotificationQueue';

// mirror of object in /imports/startup/client/listenActiveUsers.js - keep updated
export const STATUS_MAP = {
Expand All @@ -26,6 +27,11 @@ export const setUserStatus = (user, status/* , statusConnection*/) => {
STATUS_MAP[status],
statusText,
]);

if (status == 'offline' || status == 'away') {
// Expedite notification schedule for this user
Notification.expediteSheduleByUserId(_id);
}
};

let TroubleshootDisablePresenceBroadcast;
Expand Down