Files
wekan/server/lib/syncActivityScope.js
Lauri Ojansivu 54c3130ce9 Capture activity notification intents before ordinary activity writes
Await private intent persistence before the activity insert, preserve scoped Sync deferral, and retain pending evidence until all recipient subscribers acknowledge local writes. Compact successful intents while preserving dispatch identity; keep webhook delivery independent.

Validated with six MongoDB cases, three Node suites, three full-app Meteor cases and ten Chromium email delivery and private-storage scenarios. Automatic pending-intent recovery remains unfinished.

Thanks to xet7.
2026-09-28 14:15:55 +03:00

18 lines
804 B
JavaScript

'use strict';
const { AsyncLocalStorage } = require('node:async_hooks');
const { canonical } = require('../../models/lib/changeHistoryIntegrity');
const storage = new AsyncLocalStorage();
async function withSyncActivityDeferred(activity, work) {
const scope = { expected: canonical(activity), slots: new Set(['timestamps', 'notificationIntent', 'rules', 'notifications']), active: true };
return storage.run(scope, async () => {
try { return await work(); } finally { scope.active = false; }
});
}
function deferSyncActivity(kind, activity) {
const scope = storage.getStore();
if (!scope?.active || !scope.slots.has(kind) || canonical(activity) !== scope.expected) return false;
scope.slots.delete(kind);
return true;
}
module.exports = { withSyncActivityDeferred, deferSyncActivity };