feat(onebot): backfill cloud history after login
Add an opt-in per-account login history backfill that waits for roster warmup and a 30-second grace period before silently filling local message history. The setting defaults to disabled and applies on the next account lifecycle. Run one account at a time, prioritize known local gaps, and process at most three groups plus three friends with one 20-message page per session. Failures are logged and never retried during the same login. Persist reconstructed history without dispatching OneBot events or changing QQ read state. Keep private metadata and event bodies atomic, honor recall tombstones, suppress live-only history side effects, avoid extra media requests, and stop queued, in-flight, or converting work when the account closes. Share the persistence path with manual history actions and add lifecycle, cancellation, corruption, partial-failure, peer-identity, and storage-atomicity regression coverage. Refs #280.
This commit is contained in:
15 files changed
+1810
-68
No files matched your search
@@ -194,9 +194,28 @@ export class OneBotManager {
|
||||
if (result.applied) log.info('network startup applied: UIN=%s adapters=%d', uin, result.statuses.length);
|
||||
else log.warn('network startup degraded: UIN=%s failures=%d', uin, result.errors.length);
|
||||
}));
|
||||
warmUpBridgeState(uin, bridge).catch((err) => {
|
||||
log.warn('warmup error for UIN %s: %s', uin, err instanceof Error ? (err.stack ?? err.message) : String(err));
|
||||
});
|
||||
void warmUpBridgeState(uin, bridge).then(
|
||||
(warmup) => {
|
||||
if (warmup.friendsLoaded && warmup.groupsLoaded) {
|
||||
instance.startLoginHistorySync();
|
||||
return;
|
||||
}
|
||||
log.warn(
|
||||
'login history sync skipped because roster warmup was incomplete: '
|
||||
+ 'UIN=%s friendsLoaded=%s groupsLoaded=%s',
|
||||
uin,
|
||||
String(warmup.friendsLoaded),
|
||||
String(warmup.groupsLoaded),
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
log.warn(
|
||||
'warmup error for UIN %s: %s',
|
||||
uin,
|
||||
err instanceof Error ? (err.stack ?? err.message) : String(err),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private onSessionClosed(uin: string): void {
|
||||
@@ -279,9 +298,18 @@ export class OneBotManager {
|
||||
|
||||
}
|
||||
|
||||
async function warmUpBridgeState(uin: string, bridge: BridgeInterface): Promise<void> {
|
||||
interface BridgeWarmupResult {
|
||||
friendsLoaded: boolean;
|
||||
groupsLoaded: boolean;
|
||||
}
|
||||
|
||||
async function warmUpBridgeState(
|
||||
uin: string,
|
||||
bridge: BridgeInterface,
|
||||
): Promise<BridgeWarmupResult> {
|
||||
const selfUin = parseInt(uin, 10) || 0;
|
||||
let selfResolved = false;
|
||||
let friendsLoaded = false;
|
||||
|
||||
// Step 1: Fetch friend list + derive self profile when QQ happens to
|
||||
// include self in the response. Some accounts / versions omit self,
|
||||
@@ -289,6 +317,7 @@ async function warmUpBridgeState(uin: string, bridge: BridgeInterface): Promise<
|
||||
// explicit fallback.
|
||||
try {
|
||||
const friends = await bridge.apis.contacts.fetchFriendList();
|
||||
friendsLoaded = true;
|
||||
log.info('friends loaded: UIN=%s count=%d', uin, friends.length);
|
||||
|
||||
for (const f of friends) {
|
||||
@@ -327,8 +356,10 @@ async function warmUpBridgeState(uin: string, bridge: BridgeInterface): Promise<
|
||||
|
||||
// Step 2: Fetch group list
|
||||
let groups: { groupId: number }[] = [];
|
||||
let groupsLoaded = false;
|
||||
try {
|
||||
groups = await bridge.apis.contacts.fetchGroupList();
|
||||
groupsLoaded = true;
|
||||
log.info('groups loaded: UIN=%s count=%d', uin, groups.length);
|
||||
} catch (e) {
|
||||
log.warn('failed to load groups for UIN %s: %s', uin, e instanceof Error ? e.message : String(e));
|
||||
@@ -360,4 +391,5 @@ async function warmUpBridgeState(uin: string, bridge: BridgeInterface): Promise<
|
||||
loadedMemberCount,
|
||||
failedGroupCount,
|
||||
);
|
||||
return { friendsLoaded, groupsLoaded };
|
||||
}
|
||||
Reference in new issue
Block a user