mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
The #3136 invite notification never ran: its params object was declared inside the email block, so Notifications.notify() threw a ReferenceError that its own catch logged. With it in scope, the tray would still have refused an entry with no activity, and the email service would have queued a second email beside the invitation. The invite now delivers the membership's addBoardMember activity, which the bell already renders, to an existing invitee's tray only, honouring their tray setting. A re-activated membership records that activity; re-inviting an active member adds nobody. Refs #3136. Thanks to CondensedTea and xet7 !
41 lines
1.9 KiB
JavaScript
41 lines
1.9 KiB
JavaScript
import Activities from '/models/activities';
|
|
import { prepareTrayNotification } from '/server/notifications/profile';
|
|
import { trayDelivery } from '/server/notifications/trayQueue';
|
|
|
|
// #3136: an existing user invited to a board is told in the in-app
|
|
// notification bell, not only by email.
|
|
//
|
|
// The bell lists activities, and tray delivery refuses an entry without one.
|
|
// The invite used to call Notifications.notify() with an invite-only params
|
|
// object: that object was declared inside the email block, so the call threw
|
|
// a ReferenceError the surrounding catch logged, and even with it in scope the
|
|
// tray service would have refused the missing activityId while the email
|
|
// service queued a second email beside the invitation itself.
|
|
//
|
|
// So the invite delivers the membership's own addBoardMember activity, which
|
|
// the bell already renders ("added member ... to board ..."), to the invitee's
|
|
// tray only, honouring the admin/board/member tray settings. A new membership
|
|
// gets that activity from Boards.after.update; a re-activated one records it
|
|
// here, since re-adding someone is still adding a member. Inviting somebody
|
|
// who is already an active member adds nobody, so there is no activity and
|
|
// nothing to deliver.
|
|
export async function deliverBoardInviteToTray({ user, boardId, inviterId, since, reactivated }) {
|
|
if (reactivated) {
|
|
await Activities.insertAsync({
|
|
userId: inviterId,
|
|
memberId: user._id,
|
|
type: 'member',
|
|
activityType: 'addBoardMember',
|
|
boardId,
|
|
});
|
|
}
|
|
if (!await prepareTrayNotification(user, { boardId })) return null;
|
|
const activity = await Activities.findOneAsync(
|
|
{ activityType: 'addBoardMember', boardId, memberId: user._id, createdAt: { $gte: since } },
|
|
{ sort: { createdAt: -1 }, fields: { _id: 1 } },
|
|
);
|
|
if (!activity) return null;
|
|
await trayDelivery.deliver(user._id, activity._id);
|
|
return activity._id;
|
|
}
|