Skip to content

Commit

Permalink
[FIX] Apps Engine notifyRoom sending notification to wrong users (#17093
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sampaiodiego committed Mar 31, 2020
1 parent 6cc5863 commit d47921a
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions app/apps/server/bridges/messages.js
Expand Up @@ -59,24 +59,27 @@ export class AppMessageBridge {
async notifyRoom(room, message, appId) {
this.orch.debugLog(`The App ${ appId } is notifying a room's users.`);

if (room) {
const msg = this.orch.getConverters().get('messages').convertAppMessage(message);
const rmsg = Object.assign(msg, {
_id: Random.id(),
rid: room.id,
ts: new Date(),
u: undefined,
editor: undefined,
});

const users = Subscriptions.findByRoomIdWhenUserIdExists(room._id, { fields: { 'u._id': 1 } })
.fetch()
.map((s) => s.u._id);
Users.findByIds(users, { fields: { _id: 1 } })
.fetch()
.forEach(({ _id }) =>
Notifications.notifyUser(_id, 'message', rmsg),
);
if (!room || !room.id) {
return;
}

const msg = this.orch.getConverters().get('messages').convertAppMessage(message);
const rmsg = Object.assign(msg, {
_id: Random.id(),
rid: room.id,
ts: new Date(),
u: undefined,
editor: undefined,
});

const users = Subscriptions.findByRoomIdWhenUserIdExists(room.id, { fields: { 'u._id': 1 } })
.fetch()
.map((s) => s.u._id);

Users.findByIds(users, { fields: { _id: 1 } })
.fetch()
.forEach(({ _id }) =>
Notifications.notifyUser(_id, 'message', rmsg),
);
}
}

0 comments on commit d47921a

Please sign in to comment.