diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index d5d7677b..5166f92d 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -34,7 +34,7 @@ import SetGroupAdmin from './group/SetGroupAdmin'; import SetGroupCard from './group/SetGroupCard'; import GetImage from './file/GetImage'; import GetRecord from './file/GetRecord'; -import GoCQHTTPMarkMsgAsRead from './msg/MarkMsgAsRead'; +import { MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead'; import CleanCache from './system/CleanCache'; import GoCQHTTPUploadGroupFile from './go-cqhttp/UploadGroupFile'; import { GetConfigAction, SetConfigAction } from '@/onebot11/action/extends/Config'; @@ -86,7 +86,8 @@ export const actionHandlers = [ new GoCQHTTPGetStrangerInfo(), new GoCQHTTPDownloadFile(), new GetGuildList(), - new GoCQHTTPMarkMsgAsRead(), + new MarkGroupMsgAsRead(), + new MarkPrivateMsgAsRead(), new GoCQHTTPUploadGroupFile(), new GoCQHTTPGetGroupMsgHistory(), new GoCQHTTGetForwardMsgAction(), diff --git a/src/onebot11/action/msg/MarkMsgAsRead.ts b/src/onebot11/action/msg/MarkMsgAsRead.ts index 06b8916a..f2e317a0 100644 --- a/src/onebot11/action/msg/MarkMsgAsRead.ts +++ b/src/onebot11/action/msg/MarkMsgAsRead.ts @@ -1,14 +1,44 @@ +import { ChatType, Peer, RawMessage, SendMessageElement } from '@/core/qqnt/entities'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; +import { NTQQMsgApi } from '@/core/qqnt/apis'; +import { getFriend, getUidByUin } from '@/common/data'; -interface Payload{ - message_id: number +interface Payload { + uin: string, } -export default class GoCQHTTPMarkMsgAsRead extends BaseAction{ - actionName = ActionName.GoCQHTTP_MarkMsgAsRead; - +class MarkMsgAsRead extends BaseAction { + ReqChatType = 0; protected async _handle(payload: Payload): Promise { + let uid: string | undefined = payload.uin; + if (this.ReqChatType != ChatType.group) { + uid = getUidByUin(payload.uin.toString()) + if (!uid) { + throw `记录${payload.uin}不存在`; + } + let friend = await getFriend(uid); + this.ReqChatType = friend ? ChatType.friend : ChatType.temp;//重写 + } + + + + // 获取UID 组装Peer + // GuildId: string 留空 + let ReqPeer: Peer = { chatType: this.ReqChatType, peerUid: uid, guildId: "" }; + // 调用API + let ret = await NTQQMsgApi.setMsgRead(ReqPeer); + if (ret.result != 0) { + throw ('设置已读失败'); + } return null; } +} +export class MarkPrivateMsgAsRead extends MarkMsgAsRead { + actionName = ActionName.MarkPrivateMsgAsRead; + ReqChatType = ChatType.friend; +} +export class MarkGroupMsgAsRead extends MarkMsgAsRead { + actionName = ActionName.MarkGroupMsgAsRead; + ReqChatType = ChatType.group; } \ No newline at end of file diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index ca4beb0e..fd59eacf 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -56,7 +56,8 @@ export enum ActionName { GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg', GoCQHTTP_GetStrangerInfo = 'get_stranger_info', GetGuildList = 'get_guild_list', - GoCQHTTP_MarkMsgAsRead = 'mark_msg_as_read', + MarkPrivateMsgAsRead = 'mark_private_msg_as_read', + MarkGroupMsgAsRead = 'mark_group_msg_as_read', GoCQHTTP_UploadGroupFile = 'upload_group_file', GoCQHTTP_DownloadFile = 'download_file', GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history', diff --git a/src/onebot11/version.ts b/src/onebot11/version.ts index e6218856..d1564232 100644 --- a/src/onebot11/version.ts +++ b/src/onebot11/version.ts @@ -1 +1 @@ -export const version = '1.0.3'; +export const version = '1.1.2';