Files
wekan/server/methods/sinceLastVisit.js
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02:00

70 lines
3.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import Activities from '/models/activities';
import Cards from '/models/cards';
import Users from '/models/users';
import { ReactiveCache } from '/imports/reactiveCache';
import { canReadBoard } from '/models/lib/boardVisibility';
import { featureOnFor } from '/server/lib/assistGate';
// Board menu -> Since your last visit
// (docs/Features/Since-Last-Visit/README.md). markVisited
// is called when a board opens and answers with the visit BEFORE this one,
// which is what the view lists from; it is kept while the feature is hidden,
// so turning it on again shows the right changes. The list reads a board the
// caller may read, and for an assigned-only member only their cards.
const { sinceOf, sinceLastVisit, boardVisitsModifier, TYPES } = require('/models/lib/sinceLastVisit');
const { assignedOnlyCardScope, mergeCardScope } = require('/models/lib/boardCardScope');
const ID = /^[A-Za-z0-9_-]{1,64}$/;
const MAX_ROWS = 5000;
async function readableBoard(userId, boardId) {
if (!userId || !ID.test(boardId)) return null;
const board = await ReactiveCache.getBoard(boardId);
return board && canReadBoard(userId, board) ? board : null;
}
Meteor.methods({
async 'boards.markVisited'(boardId) {
check(boardId, String);
const board = await readableBoard(this.userId, boardId);
if (!board) return null;
const user = await ReactiveCache.getUser(this.userId);
const visits = (user && user.profile && user.profile.boardVisits) || {};
const previous = visits[boardId] || null;
await Users.updateAsync(this.userId, boardVisitsModifier(visits, boardId, new Date()));
return previous;
},
async 'boards.sinceLastVisit'(boardId, previousVisit) {
check(boardId, String);
check(previousVisit, Match.Maybe(Date));
if (!(await featureOnFor(this.userId, 'since-last-visit'))) return [];
const board = await readableBoard(this.userId, boardId);
if (!board) return [];
const since = sinceOf(previousVisit);
const activities = await Activities.find(
{ boardId, activityType: { $in: TYPES }, createdAt: { $gte: since }, userId: { $ne: this.userId } },
{ fields: { activityType: 1, userId: 1, cardId: 1, listName: 1, createdAt: 1 }, sort: { createdAt: -1 }, limit: MAX_ROWS },
).fetchAsync();
const cardIds = [...new Set(activities.map(a => a.cardId).filter(Boolean))];
const visible = await Cards.find(
mergeCardScope({ _id: { $in: cardIds }, boardId }, assignedOnlyCardScope(board, this.userId)),
{ fields: { title: 1 } },
).fetchAsync();
const cards = {};
for (const card of visible) cards[card._id] = card;
const userIds = [...new Set(activities.map(a => a.userId))];
const usernames = {};
for (const user of await Users.find({ _id: { $in: userIds } }, { fields: { username: 1 } }).fetchAsync()) {
usernames[user._id] = user.username;
}
return sinceLastVisit({ activities, cards, usernames, userId: this.userId, since });
},
});
DDPRateLimiter.addRule({ type: 'method', name: 'boards.markVisited', connectionId: () => true }, 20, 10000);
DDPRateLimiter.addRule({ type: 'method', name: 'boards.sinceLastVisit', connectionId: () => true }, 20, 10000);