mirror of
https://github.com/wekan/wekan.git
synced 2026-02-20 23:14:07 +01:00
Part 3 of ReactiveCache async migration: - Add await before all ReactiveCache.getX() calls - Make functions containing ReactiveCache calls async - Convert forEach/map/filter loops with async callbacks to for...of - Update model helpers, Meteor methods, JsonRoutes handlers - Update collection hooks (.before/.after insert/update/remove) - Update .allow() callbacks to async Files updated across models/ and server/ directories: - Model files: cards, boards, lists, swimlanes, activities, users, checklists, checklistItems, customFields, attachments, integrations, cardComments, settings files, creators, exporters, and more - Server files: publications, methods, notifications, routes, migrations
152 lines
3.4 KiB
JavaScript
152 lines
3.4 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
// We use these when displaying notifications in the notificationsDrawer
|
|
|
|
// gets all activities associated with the current user
|
|
Meteor.publish('notificationActivities', async () => {
|
|
const ret = await activities();
|
|
return ret;
|
|
});
|
|
|
|
// gets all attachments associated with activities associated with the current user
|
|
Meteor.publish('notificationAttachments', async function() {
|
|
const ret = (await ReactiveCache.getAttachments(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.attachmentId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
)).cursor;
|
|
return ret;
|
|
});
|
|
|
|
// gets all cards associated with activities associated with the current user
|
|
Meteor.publish('notificationCards', async function() {
|
|
const ret = await ReactiveCache.getCards(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.cardId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all checklistItems associated with activities associated with the current user
|
|
Meteor.publish('notificationChecklistItems', async function() {
|
|
const ret = await ReactiveCache.getChecklistItems(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.checklistItemId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all checklists associated with activities associated with the current user
|
|
Meteor.publish('notificationChecklists', async function() {
|
|
const ret = await ReactiveCache.getChecklists(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.checklistId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all comments associated with activities associated with the current user
|
|
Meteor.publish('notificationComments', async function() {
|
|
const ret = await ReactiveCache.getCardComments(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.commentId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all lists associated with activities associated with the current user
|
|
Meteor.publish('notificationLists', async function() {
|
|
const ret = await ReactiveCache.getLists(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.listId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all swimlanes associated with activities associated with the current user
|
|
Meteor.publish('notificationSwimlanes', async function() {
|
|
const ret = await ReactiveCache.getSwimlanes(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.swimlaneId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
// gets all users associated with activities associated with the current user
|
|
Meteor.publish('notificationUsers', async function() {
|
|
const ret = await ReactiveCache.getUsers(
|
|
{
|
|
_id: {
|
|
$in: (await activities())
|
|
.map(v => v.userId)
|
|
.filter(v => !!v),
|
|
},
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
return ret;
|
|
});
|
|
|
|
async function activities() {
|
|
const activityIds = (await ReactiveCache.getCurrentUser())?.profile?.notifications?.map(v => v.activity) || [];
|
|
let ret = [];
|
|
if (activityIds.length > 0) {
|
|
ret = await ReactiveCache.getActivities(
|
|
{
|
|
_id: { $in: activityIds },
|
|
},
|
|
{},
|
|
true,
|
|
);
|
|
}
|
|
return ret;
|
|
}
|