feat(notifications): P4 WebUI — channel manager, per-account opt-in, deliveries widget
- API client: notifications surface (getConfig/saveConfig/recent/test) + types. - Settings → 通知 tab: global channel CRUD (id/name/url/body-template/enabled) + global debounce window, per-channel test-send, dirty-tracked save; invalid channels (bad slug / non-http URL) are dropped server-side and surfaced. - Per-account 通用设置: opt-in toggles bound to notifications.channelIds, riding the ConfigPage's existing debounced autosave; stale opt-ins preserved. - Overview: opt-in 最近投递 widget (polls /api/notifications/recent, read-only). Hidden-by-default set is now DERIVED from the catalogue (defaultVisible) and shared by desktop + mobile reconcile — replaces the hardcoded STATIC_WIDGET_IDS so a new opt-in widget can't reappear unbidden on existing mobile dashboards. Typecheck + build green. Adversarial review: 1 should-fix (mobile hidden-set) + 2 nits found, fixed/triaged, and re-verified clean.
This commit is contained in:
12 files changed
+509
-7
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { AccountConnections, HookProcessInfo, LogEntry, LogLevel, QQInfo, SystemInfo, UiAppearance, UiConfig, UpdateInfo } from '@/types';
|
||||
import type { AccountConnections, HookProcessInfo, LogEntry, LogLevel, NotificationDeliveryRecord, NotificationsConfig, QQInfo, SystemInfo, UiAppearance, UiConfig, UpdateInfo } from '@/types';
|
||||
import type { PasswordRule } from '@/components/pages/change-password-page';
|
||||
import { normalizeOneBotConfig } from '@/lib/onebot-config';
|
||||
import {
|
||||
@@ -44,6 +44,7 @@ class HttpApiClient implements ApiClient {
|
||||
readonly logs: ApiClient['logs'];
|
||||
readonly update: ApiClient['update'];
|
||||
readonly ui: ApiClient['ui'];
|
||||
readonly notifications: ApiClient['notifications'];
|
||||
|
||||
constructor(opts: CreateApiClientOptions = {}) {
|
||||
this.tokenStore = opts.tokenStore ?? localStorageTokenStore(DEFAULT_TOKEN_KEY);
|
||||
@@ -136,6 +137,26 @@ class HttpApiClient implements ApiClient {
|
||||
return data.config;
|
||||
},
|
||||
};
|
||||
|
||||
this.notifications = {
|
||||
getConfig: () =>
|
||||
this.getJson<{ config: NotificationsConfig }>('/api/notifications/config').then((d) => d.config),
|
||||
saveConfig: async (config) => {
|
||||
const data = await this.postJson<{ success: boolean; config: NotificationsConfig }>(
|
||||
'/api/notifications/config',
|
||||
config,
|
||||
);
|
||||
return data.config;
|
||||
},
|
||||
recent: (limit) =>
|
||||
this.getJson<{ recent: NotificationDeliveryRecord[] }>(
|
||||
`/api/notifications/recent${limit ? `?limit=${limit}` : ''}`,
|
||||
).then((d) => d.recent ?? []),
|
||||
test: (channelId) =>
|
||||
this.postJson<{ success: boolean; message?: string; status?: number }>('/api/notifications/test', {
|
||||
channelId,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- HTTP helpers ----------
|
||||
|
||||
@@ -3,6 +3,8 @@ import type {
|
||||
HookProcessInfo,
|
||||
LogEntry,
|
||||
LogLevel,
|
||||
NotificationDeliveryRecord,
|
||||
NotificationsConfig,
|
||||
OneBotConfig,
|
||||
QQInfo,
|
||||
SystemInfo,
|
||||
@@ -72,6 +74,18 @@ export interface ApiClient {
|
||||
save(uin: string, config: OneBotConfig): Promise<OneBotConfig>;
|
||||
};
|
||||
|
||||
// ---- notifications (account up/down webhooks) ----
|
||||
notifications: {
|
||||
/** Global channel store (channels + debounce). Bearer-gated. */
|
||||
getConfig(): Promise<NotificationsConfig>;
|
||||
/** Persist the global store (whole-config; server normalizes). */
|
||||
saveConfig(config: Partial<NotificationsConfig>): Promise<NotificationsConfig>;
|
||||
/** Recent in-memory delivery history, most-recent-first (≤100). */
|
||||
recent(limit?: number): Promise<NotificationDeliveryRecord[]>;
|
||||
/** Fire a one-off test to a single channel by id. */
|
||||
test(channelId: string): Promise<{ success: boolean; message?: string; status?: number }>;
|
||||
};
|
||||
|
||||
// ---- update check ----
|
||||
update: {
|
||||
/** Advisory check for a newer stable release. Read-only — never downloads. */
|
||||
|
||||
@@ -45,10 +45,16 @@ export const GRID_WIDGETS: GridWidgetSpec[] = [
|
||||
{ id: 'note', label: '便签', minW: 2, minH: 2, def: { x: 0, y: 14, w: 4, h: 2 }, defaultVisible: false },
|
||||
{ id: 'link', label: '链接卡', minW: 2, minH: 1, def: { x: 4, y: 14, w: 4, h: 1 }, defaultVisible: false },
|
||||
{ id: 'account', label: '账号快捷卡', minW: 2, minH: 1, def: { x: 8, y: 14, w: 4, h: 1 }, defaultVisible: false },
|
||||
{ id: 'deliveries', label: '最近投递', minW: 3, minH: 3, def: { x: 0, y: 16, w: 6, h: 3 }, defaultVisible: false },
|
||||
];
|
||||
|
||||
/** The opt-in static widgets — appended hidden when reconciling forward. */
|
||||
export const STATIC_WIDGET_IDS: ReadonlySet<string> = new Set(['note', 'link', 'account']);
|
||||
/** Widgets hidden on first sight (opt-in) — derived from the catalogue's
|
||||
* `defaultVisible:false` so a new opt-in widget is hidden on BOTH desktop
|
||||
* (migrateOverviewBlocks) and mobile (reconcileLayoutItems) from a single
|
||||
* source of truth — no second registration to forget. */
|
||||
export const HIDDEN_BY_DEFAULT_IDS: ReadonlySet<string> = new Set(
|
||||
GRID_WIDGETS.filter((w) => w.defaultVisible === false).map((w) => w.id),
|
||||
);
|
||||
|
||||
const WIDGET_BY_ID = new Map(GRID_WIDGETS.map((w) => [w.id, w]));
|
||||
|
||||
|
||||
@@ -16,6 +16,15 @@ function normalizeStatusCommand(raw: unknown): StatusCommandConfig {
|
||||
};
|
||||
}
|
||||
|
||||
/** Keep only string channel ids (the server re-validates slugs on save). */
|
||||
function normalizeNotifications(raw: unknown): { channelIds: string[] } {
|
||||
const src = (raw ?? {}) as Record<string, unknown>;
|
||||
const channelIds = Array.isArray(src.channelIds)
|
||||
? src.channelIds.filter((x): x is string => typeof x === 'string')
|
||||
: [];
|
||||
return { channelIds };
|
||||
}
|
||||
|
||||
/**
|
||||
* Anti-corruption layer for the per-UIN config payload. Older backends emit
|
||||
* `messageFormat` / `reportSelfMessage` at the top level instead of per
|
||||
@@ -47,5 +56,6 @@ export function normalizeOneBotConfig(raw: unknown): OneBotConfig {
|
||||
},
|
||||
musicSignUrl: typeof cfg.musicSignUrl === 'string' ? cfg.musicSignUrl : undefined,
|
||||
statusCommand: normalizeStatusCommand(cfg.statusCommand),
|
||||
notifications: normalizeNotifications(cfg.notifications),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user