feat: implement default mark msg as read and add get clientkey onebot api
This commit is contained in:
1 parent
e3e364db63
commit
7e2ba60073
5 files changed
+50
-3
No files matched your search
@@ -9,5 +9,8 @@ dist/
|
|||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
/config/
|
||||||
|
/data/
|
||||||
|
|
||||||
# macOS metadata
|
# macOS metadata
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
fetchGroupRequests as fetchGroupRequests_,
|
fetchGroupRequests as fetchGroupRequests_,
|
||||||
fetchDownloadRKeys as fetchDownloadRKeys_,
|
fetchDownloadRKeys as fetchDownloadRKeys_,
|
||||||
} from './bridge-contacts';
|
} from './bridge-contacts';
|
||||||
import { WebHonorType } from './web/group-honor';
|
import type { WebHonorType } from './web/group-honor';
|
||||||
import {
|
import {
|
||||||
muteGroupMember as muteGroupMember_,
|
muteGroupMember as muteGroupMember_,
|
||||||
muteGroupAll as muteGroupAll_,
|
muteGroupAll as muteGroupAll_,
|
||||||
@@ -65,7 +65,8 @@ import {
|
|||||||
markGroupMessageRead as markPrivateMsgAsRead_,
|
markGroupMessageRead as markPrivateMsgAsRead_,
|
||||||
setFriendRemark as setFriendRemark_,
|
setFriendRemark as setFriendRemark_,
|
||||||
fetchGroupFileCount as fetchGroupFileCount_,
|
fetchGroupFileCount as fetchGroupFileCount_,
|
||||||
getGroupHonorInfo as getGroupHonorInfo_,
|
getGroupHonorInfo as getGroupHonorInfo_,
|
||||||
|
forceFetchClientKey as forceFetchClientKey_,
|
||||||
} from './bridge-actions';
|
} from './bridge-actions';
|
||||||
import type { GroupFilesResult } from './bridge-actions';
|
import type { GroupFilesResult } from './bridge-actions';
|
||||||
import type { MediaIndexNode } from './bridge-actions';
|
import type { MediaIndexNode } from './bridge-actions';
|
||||||
@@ -90,6 +91,12 @@ export interface DownloadRKeyInfo {
|
|||||||
type: number;
|
type: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ClientKeyInfo {
|
||||||
|
clientKey: string;
|
||||||
|
expireTime: string;
|
||||||
|
keyIndex: string
|
||||||
|
}
|
||||||
|
|
||||||
const log = createLogger('Bridge');
|
const log = createLogger('Bridge');
|
||||||
const eventLog = createLogger('Event');
|
const eventLog = createLogger('Event');
|
||||||
|
|
||||||
@@ -455,6 +462,7 @@ export class Bridge {
|
|||||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||||
return getGroupHonorInfo_(this, groupId, type);
|
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); }
|
async fetchGroupFileCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> { return fetchGroupFileCount_(this, groupId); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,6 +172,31 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
|||||||
return okResponse();
|
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 ---
|
// --- RKey ---
|
||||||
|
|
||||||
@@ -542,7 +567,14 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
h.registerAction('get_clientkey', async () => {
|
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 () => {
|
h.registerAction('get_mini_app_ark', async () => {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { register as registerRequest } from './actions/request';
|
|||||||
import { register as registerExtended } from './actions/extended';
|
import { register as registerExtended } from './actions/extended';
|
||||||
|
|
||||||
import { WebHonorType } from '@/bridge/web/group-honor';
|
import { WebHonorType } from '@/bridge/web/group-honor';
|
||||||
|
import {ClientKeyInfo} from "@/bridge/bridge";
|
||||||
|
|
||||||
export interface MessageSendResult {
|
export interface MessageSendResult {
|
||||||
messageId: number;
|
messageId: number;
|
||||||
@@ -64,6 +65,7 @@ export interface ApiActionContext {
|
|||||||
sendGroupPoke?: (groupId: number, userId: number) => Promise<void>;
|
sendGroupPoke?: (groupId: number, userId: number) => Promise<void>;
|
||||||
setEssenceMsg?: (messageId: number) => Promise<void>;
|
setEssenceMsg?: (messageId: number) => Promise<void>;
|
||||||
deleteEssenceMsg?: (messageId: number) => Promise<void>;
|
deleteEssenceMsg?: (messageId: number) => Promise<void>;
|
||||||
|
forceFetchClientKey? : () => Promise<{clientKey: string, keyIndex: string, expireTime: string}>;
|
||||||
// New context methods
|
// New context methods
|
||||||
setGroupReaction?: (groupId: number, sequence: number, code: string, isSet: boolean) => Promise<void>;
|
setGroupReaction?: (groupId: number, sequence: number, code: string, isSet: boolean) => Promise<void>;
|
||||||
handleDeleteFriend?: (userId: number, block?: boolean) => Promise<void>;
|
handleDeleteFriend?: (userId: number, block?: boolean) => Promise<void>;
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ export function buildApiContext(ref: InstanceRef): ApiActionContext {
|
|||||||
getForwardMsg: async (resId) => {
|
getForwardMsg: async (resId) => {
|
||||||
return handleGetForward(ref, resId);
|
return handleGetForward(ref, resId);
|
||||||
},
|
},
|
||||||
|
forceFetchClientKey: async () => bridge.forceFetchClientKey(),
|
||||||
|
|
||||||
// Extended NapCat-compatible
|
// Extended NapCat-compatible
|
||||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||||
|
|||||||
Reference in new issue
Block a user