From 9cc0472745b0b572561e4205d946301d2638405a Mon Sep 17 00:00:00 2001 From: takayama Date: Thu, 25 Mar 2021 00:56:58 +0900 Subject: [PATCH] fix types update history message --- client.d.ts | 9 ++++++++- lib/message/chat.js | 12 +++++++----- lib/message/history.js | 22 +++++++++++++++++++++- package-lock.json | 2 +- package.json | 4 ++-- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/client.d.ts b/client.d.ts index 83003a09..deed5599 100644 --- a/client.d.ts +++ b/client.d.ts @@ -507,8 +507,15 @@ export class Client extends EventEmitter { readonly stat: Statistics; login(password?: Buffer | string): void; //密码支持明文和md5 + + /** + * @deprecated + */ captchaLogin(captcha: string): void; sliderLogin(ticket: string): void; + /** + * @deprecated + */ terminate(): void; //直接关闭连接 logout(): Promise; //先下线再关闭连接 isOnline(): boolean; @@ -518,7 +525,7 @@ export class Client extends EventEmitter { getFriendList(): Ret; getStrangerList(): Ret; getGroupList(): Ret; - getGroupMemberList(group_id: number, no_cache?: boolean): Promise>; + getGroupMemberList(group_id: number, no_cache?: boolean): Promise>>; getStrangerInfo(user_id: number, no_cache?: boolean): Promise>; getGroupInfo(group_id: number, no_cache?: boolean): Promise>; getGroupMemberInfo(group_id: number, user_id: number, no_cache?: boolean): Promise>; diff --git a/lib/message/chat.js b/lib/message/chat.js index 4b5a38e8..54676557 100644 --- a/lib/message/chat.js +++ b/lib/message/chat.js @@ -4,7 +4,7 @@ */ "use strict"; const { Builder } = require("./builder"); -const { getC2CMsgs, getGroupMsgs } = require("./history"); +const { getC2CMsgs, getGroupMsgs, getLastSeq } = require("./history"); const { parseC2CMsg, parseGroupMsg, parseForwardMsg } = require("./parser"); const common = require("../common"); const pb = require("../pb"); @@ -158,7 +158,9 @@ async function getMsgs(message_id, count = 20) { */ let msgs, data = []; if (message_id.length > 24) { - const { group_id, seq } = parseGroupMessageId(message_id); + let { group_id, seq } = parseGroupMessageId(message_id); + if (!seq) + seq = await getLastSeq.call(this, group_id); let from_seq = seq - count + 1; if (from_seq <= 0) from_seq = 1; @@ -170,12 +172,12 @@ async function getMsgs(message_id, count = 20) { } catch { } } } else { - const { user_id, time, random } = parseC2CMessageId(message_id); - msgs = await getC2CMsgs.call(this, user_id, time + 1, count); + let { user_id, time, random } = parseC2CMessageId(message_id); + msgs = await getC2CMsgs.call(this, user_id, time ? time + 1 : common.timestamp(), count); for (let i = msgs.length - 1; i >= 0; --i) { try { const msg = msgs[i]; - if (genRandom(msg[1][7]) !== random && !data.length) + if (time && genRandom(msg[1][7]) !== random && !data.length) continue; data.unshift(Object.assign(this.parseEventType("message.private"), await parseC2CMsg.call(this, msg))); } catch { } diff --git a/lib/message/history.js b/lib/message/history.js index 5bb9724d..e2fca122 100644 --- a/lib/message/history.js +++ b/lib/message/history.js @@ -46,6 +46,26 @@ async function getGroupMsgs(group_id, from_seq, to_seq) { return Array.isArray(o[6]) ? o[6] : [o[6]]; } +/** + * @this {import("../ref").Client} + * @param {number} group_id + * @returns {Promise} + */ +async function getLastSeq(group_id) { + const body = pb.encode({ + 1: this.apk.subid, + 2: { + 1: group_id, + 2: { + 22: 0 + }, + }, + }); + const blob = await this.sendOidb("OidbSvc.0x88d_0", body); + const o = pb.decode(blob)[4][1][3]; + return o[22]; +} + module.exports = { - getC2CMsgs, getGroupMsgs + getC2CMsgs, getGroupMsgs, getLastSeq }; diff --git a/package-lock.json b/package-lock.json index bef6306c..3878d775 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "oicq", - "version": "1.14.1", + "version": "1.14.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index cda11c98..6b320c9d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "oicq", - "version": "1.14.1", - "upday": "2021/3/18", + "version": "1.14.2", + "upday": "2021/3/25", "description": "QQ protocol!", "main": "client.js", "types": "client.d.ts",