feat(onebot): fetch real group history from server (#99)
get_group_msg_history was served only from the local observed-message store, so it could never return more than what SnowLuma saw live (the "only 100 messages" symptom). It now fetches real history from the server. - protocol: new SsoGetGroupMsg packet (trpc.msg.register_proxy.RegisterProxy .SsoGetGroupMsg, sequence-range fetch; fields per Lagrange). Each returned PushMsgBody is decoded by the existing group decoder via a factored-out buildContextFromMessage. - core: MessageApi.getGroupHistory walks backward in small sequence windows with rate-limiting + data-volume guards — a process-wide throttle (≥300ms between sends), 30-seq chunks, ≤12 requests, ≤200 messages per call — so a hammering client can't make us flood the server and get kicked. - onebot: get_group_msg_history resolves the anchor sequence (requested message_id or latest observed), fetches from the server, converts + returns, and persists each fetched message. Falls back to the local store on unknown anchor / empty / error. Persisting fetched history also fixes replying to pre-injection messages: the reply path resolves message_id→sequence via the store, which now contains the fetched messages. Tests: SsoGetGroupMsg request/response round-trip + decode reuse (protocol); walk-back chunking/dedup/cap/floor (core).
This commit is contained in:
11 files changed
+419
-12
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type { IdentityService } from '../identity-service';
|
||||
import type { ContentHead, MessageBody, PushMsg, ResponseHead } from '@snowluma/proto-defs/message';
|
||||
import type { ContentHead, MessageBody, PushMsg, PushMsgBody as ProtoMessage, ResponseHead } from '@snowluma/proto-defs/message';
|
||||
|
||||
export type PushMsgBody = MessageBody;
|
||||
export type PushMsgResponseHead = ResponseHead;
|
||||
@@ -37,7 +37,27 @@ export function buildContext(pkt: PacketInfo, identity: IdentityService): MsgPus
|
||||
const push = protobuf_decode<PushMsg>(pkt.body);
|
||||
if (!push?.message) return null;
|
||||
|
||||
const msg = push.message;
|
||||
let selfUin = 0;
|
||||
if (pkt.uin) {
|
||||
const n = parseInt(pkt.uin, 10);
|
||||
if (!isNaN(n)) selfUin = n;
|
||||
}
|
||||
|
||||
return buildContextFromMessage(push.message, selfUin, identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a push context from an already-extracted per-message struct (the same
|
||||
* `PushMsgBody` shape that `PushMsg.message` carries). Used both by
|
||||
* {@link buildContext} (live OlPush) and by the group-history fetch, whose
|
||||
* `SsoGetGroupMsgResponse.body.messages` are these same structs — so the
|
||||
* regular msg-push decoders parse fetched history unchanged.
|
||||
*/
|
||||
export function buildContextFromMessage(
|
||||
msg: ProtoMessage,
|
||||
selfUin: number,
|
||||
identity: IdentityService,
|
||||
): MsgPushContext | null {
|
||||
if (!msg.contentHead) return null;
|
||||
|
||||
const head: MsgPushHead = {
|
||||
@@ -55,12 +75,6 @@ export function buildContext(pkt: PacketInfo, identity: IdentityService): MsgPus
|
||||
fromUid = msg.responseHead.fromUid ?? '';
|
||||
}
|
||||
|
||||
let selfUin = 0;
|
||||
if (pkt.uin) {
|
||||
const n = parseInt(pkt.uin, 10);
|
||||
if (!isNaN(n)) selfUin = n;
|
||||
}
|
||||
|
||||
const content = msg.body?.msgContent ?? new Uint8Array(0);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user