refactor: centralize wechat notification dispatch

This commit is contained in:
john
2026-06-30 21:26:46 +08:00
parent 9c653e9b16
commit 6e4e0e2937
6 changed files with 186 additions and 12 deletions
+10 -4
View File
@@ -34,6 +34,7 @@ import { PUBLISH_ROOT_DIR, PUBLISH_KEY_UUID, PUBLIC_ZONE_DIR, resolvePublishDir,
import { ensureWorkspaceHtmlThumbnail, startWorkspaceThumbnailWatcher, workspaceThumbnailRelativePath } from './mindspace-workspace-thumbnails.mjs';
import { startWorkspaceAssetSyncWatcher } from './mindspace-workspace-sync.mjs';
import { attachRequestId, sendData, sendError } from './api-response.mjs';
import { createNotificationDispatcher } from './notification-dispatcher.mjs';
import { createMindSpaceAuditWriter } from './mindspace-audit.mjs';
import { assertMindSpaceRoute, mindspaceFlags } from './mindspace-flags.mjs';
import { createMindSpaceService, DEFAULT_MAX_FILE_BYTES } from './mindspace.mjs';
@@ -258,6 +259,7 @@ let subscriptionService = null;
let wechatPayClient = null;
let wechatOAuthService = null;
let wechatMpService = null;
let notificationDispatcher = null;
let scheduleService = null;
let feedbackService = null;
let scheduleReminderWorker = null;
@@ -592,9 +594,13 @@ async function bootstrapUserAuth() {
})
: null,
});
userAuth.setRechargeNotifier(async ({ userId, title, body }) => {
if (!wechatMpService?.enabled) return;
await wechatMpService.sendTextToUser(userId, `${title}\n${body}`.trim());
notificationDispatcher = createNotificationDispatcher({
sendWechatTextToUser: wechatMpService?.enabled
? (userId, text) => wechatMpService.sendTextToUser(userId, text)
: null,
});
userAuth.setRechargeNotifier(async ({ userId, title, body, dedupeKey }) => {
await notificationDispatcher.sendRechargeSuccess({ userId, title, body, dedupeKey });
});
if (
process.env.H5_REMINDER_WORKER_ENABLED === '1' &&
@@ -603,7 +609,7 @@ async function bootstrapUserAuth() {
) {
scheduleReminderWorker = startScheduleReminderWorker({
scheduleService,
sendWechatTextToUser: (userId, text) => wechatMpService.sendTextToUser(userId, text),
notificationDispatcher,
});
console.log('Schedule reminder worker enabled');
}