wekan/server/publications/activities.js
Harry Adel 71eb01e233 Update ReactiveCache call sites to use async/await for Meteor 3.0
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
2026-02-01 00:54:38 +02:00

69 lines
1.8 KiB
JavaScript

import { ReactiveCache } from '/imports/reactiveCache';
// We use activities fields at two different places:
// 1. The board sidebar
// 2. The card activity tab
// We use this publication to paginate for these two publications.
Meteor.publish('activities', async function(kind, id, limit, showActivities) {
check(
kind,
Match.Where(x => {
return ['board', 'card'].indexOf(x) !== -1;
}),
);
check(id, Match.Maybe(String));
check(limit, Number);
check(showActivities, Boolean);
// Return empty cursor if id is null or undefined
if (!id) {
return this.ready();
}
if (!this.userId) {
return this.ready();
}
let linkedElmtId = [id];
let board;
if (kind === 'board') {
board = await ReactiveCache.getBoard(id);
if (!board || !board.isVisibleBy(this.userId)) {
return this.ready();
}
// Get linked boards, but only those visible to the user
(await ReactiveCache.getCards({
"type": "cardType-linkedBoard",
"boardId": id
})).forEach(async card => {
const linkedBoard = await ReactiveCache.getBoard(card.linkedId);
if (linkedBoard && linkedBoard.isVisibleBy(this.userId)) {
linkedElmtId.push(card.linkedId);
}
});
} else if (kind === 'card') {
const card = await ReactiveCache.getCard(id);
if (!card) {
return this.ready();
}
board = await ReactiveCache.getBoard(card.boardId);
if (!board || !board.isVisibleBy(this.userId)) {
return this.ready();
}
}
const selector = showActivities
? { [`${kind}Id`]: { $in: linkedElmtId } }
: { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: { $in: linkedElmtId } }] };
const ret = await ReactiveCache.getActivities(selector,
{
limit,
sort: { createdAt: -1 },
},
true,
);
return ret;
});