feat: implement default mark msg as read and add get clientkey onebot api

This commit is contained in:
H3CoF6 committed 2026-05-08 16:42:19 +08:00
1 parent e3e364db63
commit 7e2ba60073
5 files changed
+50 -3

No files matched your search

+10 -2
View File
@@ -26,7 +26,7 @@ import {
fetchGroupRequests as fetchGroupRequests_,
fetchDownloadRKeys as fetchDownloadRKeys_,
} from './bridge-contacts';
import { WebHonorType } from './web/group-honor';
import type { WebHonorType } from './web/group-honor';
import {
muteGroupMember as muteGroupMember_,
muteGroupAll as muteGroupAll_,
@@ -65,7 +65,8 @@ import {
markGroupMessageRead as markPrivateMsgAsRead_,
setFriendRemark as setFriendRemark_,
fetchGroupFileCount as fetchGroupFileCount_,
getGroupHonorInfo as getGroupHonorInfo_,
getGroupHonorInfo as getGroupHonorInfo_,
forceFetchClientKey as forceFetchClientKey_,
} from './bridge-actions';
import type { GroupFilesResult } from './bridge-actions';
import type { MediaIndexNode } from './bridge-actions';
@@ -90,6 +91,12 @@ export interface DownloadRKeyInfo {
type: number;
}
export interface ClientKeyInfo {
clientKey: string;
expireTime: string;
keyIndex: string
}
const log = createLogger('Bridge');
const eventLog = createLogger('Event');
@@ -455,6 +462,7 @@ export class Bridge {
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
return getGroupHonorInfo_(this, groupId, type);
}
async forceFetchClientKey(): Promise<ClientKeyInfo> { return forceFetchClientKey_(this)}
async fetchGroupFileCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> { return fetchGroupFileCount_(this, groupId); }
}
+33 -1
View File
@@ -172,6 +172,31 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return okResponse();
});
h.registerAction('mark_msg_as_read', async (params) => {
const messageId = asNumber(params.message_id);
const targetId = asNumber(params.target_id);
if (!Number.isInteger(messageId) || messageId === 0) {
return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
}
const meta = ctx.getMessageMeta(messageId);
if (!meta) return failedResponse(RETCODE.ACTION_FAILED, 'message not found');
if (targetId && targetId !== meta.targetId) {
return failedResponse(RETCODE.BAD_REQUEST, 'target_id does not match message session');
}
if (!(ctx.markPrivateMsgAsRead && ctx.markGroupMsgAsRead)) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
if (meta.isGroup) {
await ctx.markGroupMsgAsRead(targetId, meta.sequence);
} else {
await ctx.markPrivateMsgAsRead(targetId, meta.sequence);
}
return okResponse();
});
// --- RKey ---
@@ -542,7 +567,14 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
});
h.registerAction('get_clientkey', async () => {
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
if (!ctx.forceFetchClientKey) {
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
}
const clientKeyInfo = await ctx.forceFetchClientKey();
if (!clientKeyInfo.clientKey) {
return failedResponse(RETCODE.ACTION_FAILED, 'get clientkey error');
}
return okResponse(clientKeyInfo);
});
h.registerAction('get_mini_app_ark', async () => {
+2
View File
@@ -11,6 +11,7 @@ import { register as registerRequest } from './actions/request';
import { register as registerExtended } from './actions/extended';
import { WebHonorType } from '@/bridge/web/group-honor';
import {ClientKeyInfo} from "@/bridge/bridge";
export interface MessageSendResult {
messageId: number;
@@ -64,6 +65,7 @@ export interface ApiActionContext {
sendGroupPoke?: (groupId: number, userId: number) => Promise<void>;
setEssenceMsg?: (messageId: number) => Promise<void>;
deleteEssenceMsg?: (messageId: number) => Promise<void>;
forceFetchClientKey? : () => Promise<{clientKey: string, keyIndex: string, expireTime: string}>;
// New context methods
setGroupReaction?: (groupId: number, sequence: number, code: string, isSet: boolean) => Promise<void>;
handleDeleteFriend?: (userId: number, block?: boolean) => Promise<void>;
@@ -112,6 +112,8 @@ export function buildApiContext(ref: InstanceRef): ApiActionContext {
getForwardMsg: async (resId) => {
return handleGetForward(ref, resId);
},
forceFetchClientKey: async () => bridge.forceFetchClientKey(),
// Extended NapCat-compatible
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),