Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
update history message
  • Loading branch information
takayama-lily committed Mar 24, 2021
1 parent a87e891 commit 9cc0472
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
9 changes: 8 additions & 1 deletion client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>; //先下线再关闭连接
isOnline(): boolean;
Expand All @@ -518,7 +525,7 @@ export class Client extends EventEmitter {
getFriendList(): Ret<Client["fl"]>;
getStrangerList(): Ret<Client["sl"]>;
getGroupList(): Ret<Client["gl"]>;
getGroupMemberList(group_id: number, no_cache?: boolean): Promise<Ret<Client["gml"]>>;
getGroupMemberList(group_id: number, no_cache?: boolean): Promise<Ret<ReadonlyMap<number, MemberInfo>>>;
getStrangerInfo(user_id: number, no_cache?: boolean): Promise<Ret<StrangerInfo>>;
getGroupInfo(group_id: number, no_cache?: boolean): Promise<Ret<GroupInfo>>;
getGroupMemberInfo(group_id: number, user_id: number, no_cache?: boolean): Promise<Ret<MemberInfo>>;
Expand Down
12 changes: 7 additions & 5 deletions lib/message/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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 { }
Expand Down
22 changes: 21 additions & 1 deletion lib/message/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>}
*/
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
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 9cc0472

Please sign in to comment.