From 4a82df492db94df957dc841a96560730f227c7c8 Mon Sep 17 00:00:00 2001 From: piloking <141794311+piloking@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:27:09 +0900 Subject: [PATCH] update --- packages/linejs/client/clients/base-client.ts | 107 ++++++----- packages/linejs/client/clients/e2ee/index.ts | 105 +++++++--- .../client/clients/internal/channel-client.ts | 4 +- .../client/clients/internal/liff-client.ts | 56 +++--- .../clients/internal/relation-client.ts | 4 +- .../client/clients/internal/square-client.ts | 180 +++++++++--------- .../client/clients/internal/talk-client.ts | 92 ++++++--- .../linejs/client/clients/timeline/index.ts | 6 +- packages/linejs/client/entities/object.ts | 18 +- .../linejs/client/libs/storage/dir-storage.ts | 2 +- packages/linejs/client/libs/thrift/parser.ts | 1 + 11 files changed, 334 insertions(+), 241 deletions(-) diff --git a/packages/linejs/client/clients/base-client.ts b/packages/linejs/client/clients/base-client.ts index 97f4df4..cbbaf11 100644 --- a/packages/linejs/client/clients/base-client.ts +++ b/packages/linejs/client/clients/base-client.ts @@ -243,7 +243,11 @@ export class BaseClient extends TypedEventEmitter { return; } - const myEventsArg = { subscriptionId: noopMyEvents.subscription?.subscriptionId as number, syncToken: noopMyEvents.syncToken, continuationToken: noopMyEvents.continuationToken } + const myEventsArg = { + subscriptionId: noopMyEvents.subscription?.subscriptionId as number, + syncToken: noopMyEvents.syncToken, + continuationToken: noopMyEvents.continuationToken, + }; let previousMessageId: string | undefined = undefined; while (true) { @@ -278,7 +282,7 @@ export class BaseClient extends TypedEventEmitter { safe: boolean = true, ) => { if (typeof options === "string") { - return await this.sendSquareMessage( + return this.sendSquareMessage( { squareChatMid: message.to, text: options, @@ -287,7 +291,7 @@ export class BaseClient extends TypedEventEmitter { safe, ); } else { - return await this.sendSquareMessage( + return this.sendSquareMessage( { squareChatMid: message.to, relatedMessageId: undefined, @@ -303,7 +307,7 @@ export class BaseClient extends TypedEventEmitter { safe: boolean = true, ) => { if (typeof options === "string") { - return await this.sendSquareMessage( + return this.sendSquareMessage( { squareChatMid: message.to, text: options, @@ -312,7 +316,7 @@ export class BaseClient extends TypedEventEmitter { safe, ); } else { - return await this.sendSquareMessage( + return this.sendSquareMessage( { squareChatMid: message.to, relatedMessageId: message.id, @@ -325,13 +329,13 @@ export class BaseClient extends TypedEventEmitter { const react = async (options: SquareMessageReactionOptions) => { if (typeof options === "number") { - return await this.reactToSquareMessage({ + return this.reactToSquareMessage({ squareChatMid: payload.squareChatMid, reactionType: options as LINETypes.MessageReactionType, squareMessageId: message.id, }); } else { - return await this.reactToSquareMessage({ + return this.reactToSquareMessage({ squareChatMid: payload.squareChatMid, reactionType: ( options as Exclude< @@ -411,7 +415,8 @@ export class BaseClient extends TypedEventEmitter { } myEventsArg.syncToken = myEvents.syncToken; myEventsArg.continuationToken = myEvents.continuationToken; - myEventsArg.subscriptionId = myEvents.subscription?.subscriptionId as number + myEventsArg.subscriptionId = myEvents.subscription + ?.subscriptionId as number; } await new Promise((resolve) => setTimeout(resolve, 1000)); @@ -468,13 +473,13 @@ export class BaseClient extends TypedEventEmitter { } const send = async (options: SquareMessageSendOptions) => { if (typeof options === "string") { - return await this.sendMessage({ + return this.sendMessage({ to: sendIn, text: options, relatedMessageId: undefined, }); } else { - return await this.sendMessage({ + return this.sendMessage({ to: sendIn, relatedMessageId: undefined, ...options, @@ -484,13 +489,13 @@ export class BaseClient extends TypedEventEmitter { const reply = async (options: MessageReplyOptions) => { if (typeof options === "string") { - return await this.sendMessage({ + return this.sendMessage({ to: sendIn, text: options, relatedMessageId: message.id, }); } else { - return await this.sendMessage({ + return this.sendMessage({ to: sendIn, relatedMessageId: message.id, ...options, @@ -500,12 +505,12 @@ export class BaseClient extends TypedEventEmitter { const react = async (options: SquareMessageReactionOptions) => { if (typeof options === "number") { - return await this.reactToMessage({ + return this.reactToMessage({ reactionType: options as LINETypes.MessageReactionType, messageId: message.id, }); } else { - return await this.reactToMessage({ + return this.reactToMessage({ reactionType: ( options as Exclude< SquareMessageReactionOptions, @@ -520,23 +525,23 @@ export class BaseClient extends TypedEventEmitter { const chat = message.toType === LINETypes.MIDType._USER ? async () => { - return await this.getContact({ mid: sendIn }); - } + return this.getContact({ mid: sendIn }); + } : undefined; const group = message.toType !== LINETypes.MIDType._USER ? async () => { - return (await this.getChats({ mids: [sendIn] })).chats[0]; - } + return (await this.getChats({ mids: [sendIn] })).chats[0]; + } : (undefined as LooseType); const getContact = async () => { - return await this.getContact({ mid: message._from }); + return this.getContact({ mid: message._from }); }; const getMyProfile = async () => { - return await this.refreshProfile(true); + return this.refreshProfile(true); }; this.emit("message", { @@ -1097,7 +1102,7 @@ export class BaseClient extends TypedEventEmitter { /** * @description Will override. */ - public decodeE2EEKeyV1(_data: LooseType, _secret: Buffer): LooseType { } + public decodeE2EEKeyV1(_data: LooseType, _secret: Buffer): LooseType {} /** * @description Will override. @@ -1111,7 +1116,7 @@ export class BaseClient extends TypedEventEmitter { } public async createSession(): Promise { - return await this.direct_request( + return this.direct_request( [], "createSession", 4, @@ -1121,7 +1126,7 @@ export class BaseClient extends TypedEventEmitter { } public async createQrCode(qrcode: string): Promise { - return await this.request( + return this.request( [[11, 1, qrcode]], "createQrCode", 4, @@ -1153,7 +1158,7 @@ export class BaseClient extends TypedEventEmitter { qrcode: string, cert?: string | undefined, ): Promise { - return await this.request( + return this.request( [ [11, 1, qrcode], [11, 2, cert], @@ -1166,7 +1171,7 @@ export class BaseClient extends TypedEventEmitter { } public async createPinCode(qrcode: string): Promise { - return await this.request( + return this.request( [[11, 1, qrcode]], "createPinCode", 4, @@ -1198,7 +1203,7 @@ export class BaseClient extends TypedEventEmitter { authSessionId: string, autoLoginIsRequired: boolean = true, ): Promise { - return await this.request( + return this.request( [ [11, 1, authSessionId], [11, 2, this.system?.device], @@ -1217,7 +1222,7 @@ export class BaseClient extends TypedEventEmitter { systemName: string = "linejs", autoLoginIsRequired: boolean = true, ): Promise { - return await this.request( + return this.request( [ [11, 1, authSessionId], [11, 2, systemName], @@ -1235,7 +1240,7 @@ export class BaseClient extends TypedEventEmitter { verifier: string, deviceSecret: Buffer, ): Promise { - return await this.direct_request( + return this.direct_request( [ [11, 1, verifier], [11, 2, deviceSecret], @@ -1260,7 +1265,7 @@ export class BaseClient extends TypedEventEmitter { if (verifier) { loginType = 1; } - return await this.direct_request( + return this.direct_request( [ [ 12, @@ -1296,7 +1301,7 @@ export class BaseClient extends TypedEventEmitter { * @throws {FetchError} If failed to fetch RSA key info. */ public async getRSAKeyInfo(provider: number = 0): Promise { - return await this.request( + return this.request( [[8, 2, provider]], "getRSAKeyInfo", 3, @@ -1338,9 +1343,9 @@ export class BaseClient extends TypedEventEmitter { ).value; } catch (error) { if ((error as Error).message === "InputBufferUnderrunError") { - throw new InternalError("ServerError","Incorrect buffer received") + throw new InternalError("ServerError", "Incorrect buffer received"); } - throw error + throw error; } } @@ -1373,14 +1378,14 @@ export class BaseClient extends TypedEventEmitter { headers, undefined, parse, - true + true, ) ).value; } catch (error) { if ((error as Error).message === "InputBufferUnderrunError") { - throw new InternalError("ServerError","Incorrect buffer received") + throw new InternalError("ServerError", "Incorrect buffer received"); } - throw error + throw error; } } @@ -1489,7 +1494,8 @@ export class BaseClient extends TypedEventEmitter { const isRefresh = res.e && - res.e["code"] === "MUST_REFRESH_V3_TOKEN" && this.storage.get("refreshToken") + res.e["code"] === "MUST_REFRESH_V3_TOKEN" && + this.storage.get("refreshToken"); if (res.e && !isRefresh) { throw new InternalError( @@ -1500,9 +1506,9 @@ export class BaseClient extends TypedEventEmitter { } if (isRefresh && !isReRequest) { - this.log("V3_Refresh", res.e) - await this.tryRefreshToken() - return await this.rawRequest( + this.log("V3_Refresh", res.e); + await this.tryRefreshToken(); + return this.rawRequest( path, value, methodName, @@ -1595,7 +1601,7 @@ export class BaseClient extends TypedEventEmitter { * @description Gets the server time */ public async getServerTime(): Promise { - return await this.direct_request( + return this.direct_request( [], "getServerTime", this.LINEService_PROTOCOL_TYPE, @@ -1608,7 +1614,7 @@ export class BaseClient extends TypedEventEmitter { * @description Gets the profile of the current user. */ public async getProfile(): Promise { - return await this.request( + return this.request( [], "getProfile", this.LINEService_PROTOCOL_TYPE, @@ -1740,7 +1746,7 @@ export class BaseClient extends TypedEventEmitter { public async refreshAccessToken( refreshToken: string, ): Promise { - return await this.request( + return this.request( [[11, 1, refreshToken]], "refresh", 4, @@ -1759,16 +1765,13 @@ export class BaseClient extends TypedEventEmitter { if (!this.metadata) { throw new InternalError("Not setup yet", "Please call 'login()' first"); } - return await this.customFetch( - this.LINE_OBS.getDataUrl(messageId, isPreview), - { - headers: { - accept: "application/json, text/plain, */*", - "x-line-application": this.system?.type as string, - "x-Line-access": this.metadata.authToken, - }, + return this.customFetch(this.LINE_OBS.getDataUrl(messageId, isPreview), { + headers: { + accept: "application/json, text/plain, */*", + "x-line-application": this.system?.type as string, + "x-Line-access": this.metadata.authToken, }, - ).then((r) => { + }).then((r) => { return r.blob(); }); } @@ -1814,7 +1817,7 @@ export class BaseClient extends TypedEventEmitter { } const toType: "talk" | "g2" = to[0] === "m" || to[0] === "t" ? "g2" : "talk"; - return await this.customFetch( + return this.customFetch( this.LINE_OBS.prefix + "r/" + toType + "/m/reqseq", { headers: { diff --git a/packages/linejs/client/clients/e2ee/index.ts b/packages/linejs/client/clients/e2ee/index.ts index 929e1f5..3c498c0 100644 --- a/packages/linejs/client/clients/e2ee/index.ts +++ b/packages/linejs/client/clients/e2ee/index.ts @@ -26,10 +26,13 @@ class E2EE extends TalkClient { const key = keys[i]; const { keyId } = key; const _keyData = this.getE2EESelfKeyDataByKeyId(keyId); - if (_keyData) return _keyData; + if (_keyData) { + this.saveE2EESelfKeyData(_keyData); + return _keyData; + } } throw new InternalError( - "No E2EEKey", + "NoE2EEKey", "E2EE Key has not been saved, try register `saveE2EESelfKeyDataByKeyId` or use E2EE Login", ); } @@ -43,6 +46,9 @@ class E2EE extends TalkClient { public saveE2EESelfKeyDataByKeyId(keyId: string | number, value: LooseType) { this.storage.set("e2eeKeys:" + keyId, JSON.stringify(value)); } + public saveE2EESelfKeyData(value: LooseType) { + this.storage.set("e2eeKeys:" + this.user?.mid, JSON.stringify(value)); + } override getToType(mid: string): number | null { /** * USER(0), @@ -51,7 +57,8 @@ class E2EE extends TalkClient { * SQUARE(3), * SQUARE_CHAT(4), * SQUARE_MEMBER(5), - * BOT(6); + * SQUARE_BOT(6), + * SQUARE_THREAD(7):; */ const _u = mid.charAt(0); switch (_u) { @@ -69,6 +76,8 @@ class E2EE extends TalkClient { return 5; case "v": return 6; + case "t": + return 7; default: return null; } @@ -121,17 +130,26 @@ class E2EE extends TalkClient { key = undefined; } if (!key) { - const E2EEGroupSharedKey = await this.getLastE2EEGroupSharedKey({ - keyVersion: 2, - chatMid: mid, - }); - const groupKeyId = E2EEGroupSharedKey.groupKeyId; - const creator = E2EEGroupSharedKey.creator; - const creatorKeyId = E2EEGroupSharedKey.creatorKeyId; - const _receiver = E2EEGroupSharedKey.receiver; - const receiverKeyId = E2EEGroupSharedKey.receiverKeyId; + let e2eeGroupSharedKey: LINETypes.E2EEGroupSharedKey | undefined; + try { + e2eeGroupSharedKey = await this.getLastE2EEGroupSharedKey({ + keyVersion: 2, + chatMid: mid, + }); + } catch (error) { + if ((error as InternalError).data.code == "NOT_FOUND") { + e2eeGroupSharedKey = await this.tryRegisterE2EEGroupKey(mid); + } else { + throw error; + } + } + const groupKeyId = e2eeGroupSharedKey.groupKeyId; + const creator = e2eeGroupSharedKey.creator; + const creatorKeyId = e2eeGroupSharedKey.creatorKeyId; + const _receiver = e2eeGroupSharedKey.receiver; + const receiverKeyId = e2eeGroupSharedKey.receiverKeyId; const encryptedSharedKey = - E2EEGroupSharedKey.encryptedSharedKey as Buffer; + e2eeGroupSharedKey.encryptedSharedKey as Buffer; const selfKey = Buffer.from( this.getE2EESelfKeyDataByKeyId(receiverKeyId)["privKey"], "base64", @@ -155,27 +173,12 @@ class E2EE extends TalkClient { aes_key, aes_iv, ); - //decipher.setAutoPadding(false); const plainText = Buffer.concat([ decipher.update(encryptedSharedKey), decipher.final(), ]); - /* - const cipherParams = CryptoJS.lib.CipherParams.create({ - ciphertext: encryptedSharedKey.toString(), - iv: aes_iv.toString(), - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7, - }); - - const plainText = CryptoJS.AES.decrypt( - cipherParams, - aes_key.toString(), - { mode: CryptoJS.mode.CBC }, - ); - */ this.e2eeLog("getE2EELocalPublicKeyDecryptedLength", plainText.length); - const decrypted = plainText.toString("base64"); //.toString(CryptoJS.enc.Base64); + const decrypted = plainText.toString("base64"); this.e2eeLog("getE2EELocalPublicKeyDecrypted", decrypted); const data = { privKey: decrypted, @@ -189,7 +192,49 @@ class E2EE extends TalkClient { } return Buffer.from(key, "base64"); } - + public async tryRegisterE2EEGroupKey( + chatMid: string, + ): Promise { + const e2eePublicKeys = await this.getLastE2EEPublicKeys({ chatMid }); + const members: string[] = []; + const keyIds: number[] = []; + const encryptedSharedKeys: Buffer[] = []; + const selfKeyId = e2eePublicKeys[this.user!.mid].keyId; + const selfKeyData = this.getE2EESelfKeyDataByKeyId(selfKeyId); + if (!selfKeyData) { + throw new InternalError( + "NoE2EEKey", + "E2EE Key has not been saved, try register `saveE2EESelfKeyDataByKeyId` or use E2EE Login", + ); + } + const selfKey = Buffer.from(selfKeyData.privKey, "base64"); + const private_key = crypto.randomBytes(32); + for (const mid in e2eePublicKeys) { + if (Object.prototype.hasOwnProperty.call(e2eePublicKeys, mid)) { + const key = e2eePublicKeys[mid]; + members.push(mid); + const { keyId, keyData } = key; + keyIds.push(keyId); + + const aesKey = this.generateSharedSecret(selfKey, keyData); + const aes_key = this.getSHA256Sum(Buffer.from(aesKey), "Key"); + const aes_iv = this.xor(this.getSHA256Sum(Buffer.from(aesKey), "IV")); + const cipher = crypto.createCipheriv("aes-256-cbc", aes_key, aes_iv); + const encryptedSharedKey = Buffer.concat([ + cipher.update(private_key), + cipher.final(), + ]); + encryptedSharedKeys.push(encryptedSharedKey); + } + } + return this.registerE2EEGroupKey({ + keyVersion: 1, + chatMid, + keyIds, + members, + encryptedSharedKeys, + }); + } public generateSharedSecret( privateKey: Buffer, publicKey: Buffer, diff --git a/packages/linejs/client/clients/internal/channel-client.ts b/packages/linejs/client/clients/internal/channel-client.ts index 7a8fbc4..13ab842 100644 --- a/packages/linejs/client/clients/internal/channel-client.ts +++ b/packages/linejs/client/clients/internal/channel-client.ts @@ -13,13 +13,13 @@ export class ChannelClient extends SquareClient { * channelIds: * - linevoom: 1341209850 */ - public async approveChannelAndIssueChannelToken(options: { + public approveChannelAndIssueChannelToken(options: { channelId: string; }): Promise { const { channelId } = { ...options, }; - return await this.direct_request( + return this.direct_request( [[11, 1, channelId]], "approveChannelAndIssueChannelToken", this.ChannelService_PROTOCOL_TYPE, diff --git a/packages/linejs/client/clients/internal/liff-client.ts b/packages/linejs/client/clients/internal/liff-client.ts index a8e81e4..f1065cc 100644 --- a/packages/linejs/client/clients/internal/liff-client.ts +++ b/packages/linejs/client/clients/internal/liff-client.ts @@ -55,7 +55,7 @@ export class LiffClient extends BaseClient { } context = [12, chaLINETypes, [chat]]; } - return await this.request( + return this.request( [ [11, 1, liffId], [12, 2, [context]], @@ -93,8 +93,8 @@ export class LiffClient extends BaseClient { if (error instanceof InternalError) { this.log("liff-error", { ...error.data }); if (error.data.code === 3 && tryConsent) { - const data: LINETypes.LiffException = error - .data as LINETypes.LiffException; + const data: LINETypes.LiffException = + error.data as LINETypes.LiffException; const payload = data.payload; const consentRequired = payload.consentRequired; const channelId = consentRequired.channelId; @@ -103,12 +103,8 @@ export class LiffClient extends BaseClient { let hasConsent = false; if (channelId && consentUrl) { - if ( - toType === 4 || this.system?.device === "DESKTOPWIN" - ) { - hasConsent = await this.tryConsentAuthorize( - consentUrl, - ); + if (toType === 4 || this.system?.device === "DESKTOPWIN") { + hasConsent = await this.tryConsentAuthorize(consentUrl); } else { hasConsent = await this.tryConsentLiff(channelId); } @@ -120,9 +116,7 @@ export class LiffClient extends BaseClient { } } throw new Error( - `Failed to get LiffToken: ${liffId}${ - chatMid ? "@" + chatMid : "" - }`, + `Failed to get LiffToken: ${liffId}${chatMid ? "@" + chatMid : ""}`, ); } } @@ -173,9 +167,7 @@ export class LiffClient extends BaseClient { }); if (!response.ok) { - throw new Error( - `Failed to send Liff message: ${response.statusText}`, - ); + throw new Error(`Failed to send Liff message: ${response.statusText}`); } const responseBody = await response.json(); @@ -213,27 +205,31 @@ export class LiffClient extends BaseClient { ): Promise { const headers: Record = { "X-Line-Access": this.metadata?.authToken as string, - "User-Agent": this.system?.device === "IOS" - ? `Mozilla/5.0 (iPhone; CPU iPhone OS ${this.system.systemVersion} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari Line/${this.system.appVersion}` - : "Mozilla/5.0 (Linux; Android 8.0.1; SAMSUNG Realise/LineJS; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/56.0.2924.87 Mobile Safari/537.36", + "User-Agent": + this.system?.device === "IOS" + ? `Mozilla/5.0 (iPhone; CPU iPhone OS ${this.system.systemVersion} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari Line/${this.system.appVersion}` + : "Mozilla/5.0 (Linux; Android 8.0.1; SAMSUNG Realise/LineJS; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/56.0.2924.87 Mobile Safari/537.36", "X-Line-Application": this.system?.type as string, }; const response = await fetch(consentUrl, { method: "GET", headers }); if (response.ok) { const text = await response.text(); - const consentResponse = "DOMParser" in window - ? new ((window as LooseType).DOMParser)().parseFromString( - text, - "text/html", - ) - : new (await import("jsdom"))(text).dom.window.document; - const channelId = consentResponse - .querySelector('meta[name="channelId"]') - ?.getAttribute("content") ?? null; - const csrfToken = consentResponse - .querySelector('meta[name="csrfToken"]') - ?.getAttribute("content") ?? null; + const consentResponse = + "DOMParser" in window + ? new (window as LooseType).DOMParser().parseFromString( + text, + "text/html", + ) + : new (await import("jsdom"))(text).dom.window.document; + const channelId = + consentResponse + .querySelector('meta[name="channelId"]') + ?.getAttribute("content") ?? null; + const csrfToken = + consentResponse + .querySelector('meta[name="csrfToken"]') + ?.getAttribute("content") ?? null; if (channelId && csrfToken) { const payload = new URLSearchParams({ diff --git a/packages/linejs/client/clients/internal/relation-client.ts b/packages/linejs/client/clients/internal/relation-client.ts index c2f1cb4..25086ce 100644 --- a/packages/linejs/client/clients/internal/relation-client.ts +++ b/packages/linejs/client/clients/internal/relation-client.ts @@ -21,7 +21,7 @@ export class RelationClient extends E2EE { trackingMetaType: 5, ...options, }; - return await this.request( + return this.request( [ [8, 1, 0], // seq [11, 2, mid], @@ -54,7 +54,7 @@ export class RelationClient extends E2EE { checkUserStatusStrictly: false, ...options, }; - return await this.request( + return this.request( [ [15, 1, [12, mids.map((mid) => [[11, 1, mid, "targetUserMid"]])]], [8, 2, syncReason], diff --git a/packages/linejs/client/clients/internal/square-client.ts b/packages/linejs/client/clients/internal/square-client.ts index cd451a4..e31975c 100644 --- a/packages/linejs/client/clients/internal/square-client.ts +++ b/packages/linejs/client/clients/internal/square-client.ts @@ -106,7 +106,7 @@ export class SquareClient extends LiffClient { }); } if (continueRequest && response.continuationToken) { - return await this.continueRequest({ + return this.continueRequest({ response: response as LooseType, continuationToken: response.continuationToken, method: { @@ -122,14 +122,14 @@ export class SquareClient extends LiffClient { /** * @description Invite to square chat. */ - public async inviteIntoSquareChat(options: { + public inviteIntoSquareChat(options: { squareChatMid: string; targetMids: string[]; }): Promise { const { squareChatMid, targetMids } = { ...options, }; - return await this.request( + return this.request( [ [15, 1, [11, targetMids]], [11, 2, squareChatMid], @@ -144,7 +144,7 @@ export class SquareClient extends LiffClient { /** * @description Invite to square. */ - public async inviteToSquare(options: { + public inviteToSquare(options: { squareMid: string; squareChatMid: string; targetMids: string[]; @@ -152,7 +152,7 @@ export class SquareClient extends LiffClient { const { squareMid, squareChatMid, targetMids } = { ...options, }; - return await this.request( + return this.request( [ [11, 2, squareMid], [15, 3, [11, targetMids]], @@ -168,7 +168,7 @@ export class SquareClient extends LiffClient { /** * @description Mark as read for square chat. */ - public async markAsReadInSquare(options: { + public markAsReadInSquare(options: { squareChatMid: string; squareMessageId: string; squareThreadMid?: string; @@ -176,7 +176,7 @@ export class SquareClient extends LiffClient { const { squareChatMid, squareMessageId, squareThreadMid } = { ...options, }; - return await this.request( + return this.request( [ [11, 2, squareChatMid], [11, 4, squareMessageId], @@ -202,9 +202,9 @@ export class SquareClient extends LiffClient { * SAD = 6, * OMG = 7, */ - override async reactToSquareMessage(options: { + override reactToSquareMessage(options: { squareChatMid: string; - reactionType?: LINETypes.MessageReactionType; + reactionType?: LINETypes.MessageReactionType & number; squareMessageId: string; squareThreadMid?: string; }): Promise { @@ -212,7 +212,7 @@ export class SquareClient extends LiffClient { reactionType: 2, ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq("sq")], [11, 2, squareChatMid], @@ -230,11 +230,11 @@ export class SquareClient extends LiffClient { /** * @description Find square by invitation ticket. */ - public async findSquareByInvitationTicket(options: { + public findSquareByInvitationTicket(options: { invitationTicket: string; }): Promise { const { invitationTicket } = { ...options }; - return await this.request( + return this.request( [[11, 2, invitationTicket]], "findSquareByInvitationTicket", this.SquareService_PROTOCOL_TYPE, @@ -246,11 +246,11 @@ export class SquareClient extends LiffClient { /** * @description Find square by invitation ticket v2. */ - public async findSquareByInvitationTicketV2(options: { + public findSquareByInvitationTicketV2(options: { invitationTicket: string; }): Promise { const { invitationTicket } = { ...options }; - return await this.request( + return this.request( [[11, 1, invitationTicket]], "findSquareByInvitationTicketV2", this.SquareService_PROTOCOL_TYPE, @@ -262,12 +262,12 @@ export class SquareClient extends LiffClient { /** * @description Find square by Emid. */ - public async findSquareByEmid(options: { + public findSquareByEmid(options: { emid: string; }): Promise { // ...??? const { emid } = { ...options }; - return await this.request( + return this.request( [[11, 1, emid]], "findSquareByEmid", this.SquareService_PROTOCOL_TYPE, @@ -279,7 +279,7 @@ export class SquareClient extends LiffClient { /** * @description Fetch square events. */ - public override async fetchMyEvents( + public override fetchMyEvents( options: { limit?: number; syncToken?: string; @@ -291,7 +291,7 @@ export class SquareClient extends LiffClient { limit: 100, ...options, }; - return await this.request( + return this.request( [ [10, 1, subscriptionId], [11, 2, syncToken], @@ -308,7 +308,7 @@ export class SquareClient extends LiffClient { /** * @description Fetch square chat events. */ - public async fetchSquareChatEvents(options: { + public fetchSquareChatEvents(options: { squareChatMid: string; limit?: number; syncToken?: string; @@ -324,7 +324,7 @@ export class SquareClient extends LiffClient { subscriptionId, squareThreadMid, } = { limit: 100, ...options }; - return await this.request( + return this.request( [ [10, 1, subscriptionId], [11, 2, squareChatMid], @@ -350,8 +350,8 @@ export class SquareClient extends LiffClient { options: { squareChatMid: string; text?: string; - contentType?: LINETypes.ContentType; - contentMetadata?: LooseType; + contentType?: LINETypes.ContentType & number; + contentMetadata?: Record; relatedMessageId?: string; }, safe: boolean = true, @@ -487,13 +487,13 @@ export class SquareClient extends LiffClient { /** * @description Get joinable square chats. */ - public async getJoinableSquareChats(options: { + public getJoinableSquareChats(options: { squareMid: string; limit?: number; continuationToken?: string; }): Promise { const { squareMid, limit, continuationToken } = { limit: 100, ...options }; - return await this.request( + return this.request( [ [11, 1, squareMid], [11, 10, continuationToken], @@ -516,13 +516,13 @@ export class SquareClient extends LiffClient { * APPROVAL(1), * CODE(2); */ - public async createSquare(options: { + public createSquare(options: { squareName: string; displayName: string; profileImageObsHash?: string; description?: string; searchable?: boolean; - SquareJoinMethodType?: LINETypes.SquareJoinMethodType; + SquareJoinMethodType?: LINETypes.SquareJoinMethodType & number; }): Promise { const { squareName, @@ -538,7 +538,7 @@ export class SquareClient extends LiffClient { SquareJoinMethodType: 0, ...options, }; - return await this.request( + return this.request( [ [8, 2, this.getReqseq("sq")], [ @@ -579,11 +579,11 @@ export class SquareClient extends LiffClient { /** * @description Get square chat announcements. */ - public async getSquareChatAnnouncements(options: { + public getSquareChatAnnouncements(options: { squareChatMid: string; }): Promise { const { squareChatMid } = { ...options }; - return await this.request( + return this.request( [[11, 2, squareChatMid]], "getSquareChatAnnouncements", this.SquareService_PROTOCOL_TYPE, @@ -606,11 +606,11 @@ export class SquareClient extends LiffClient { * DISABLE_TRANSFER_ADMIN(9), * CREATING_LIVE_TALK(10); */ - public async updateSquareFeatureSet(options: { + public updateSquareFeatureSet(options: { squareMid: string; - updateAttributes: LINETypes.SquareFeatureSetAttribute[]; + updateAttributes: (LINETypes.SquareFeatureSetAttribute & number)[]; revision?: number; - creatingSecretSquareChat?: LINETypes.BooleanState; + creatingSecretSquareChat?: LINETypes.BooleanState & number; }): Promise { const { squareMid, updateAttributes, revision, creatingSecretSquareChat } = { revision: 0, creatingSecretSquareChat: 0, ...options }; @@ -628,7 +628,7 @@ export class SquareClient extends LiffClient { ], ]); } - return await this.request( + return this.request( [ [14, 2, [8, updateAttributes]], [12, 3, SquareFeatureSet], @@ -643,7 +643,7 @@ export class SquareClient extends LiffClient { /** * @description Join square. */ - public async joinSquare(options: { + public joinSquare(options: { squareMid: string; displayName: string; ableToReceiveMessage?: boolean; @@ -653,7 +653,7 @@ export class SquareClient extends LiffClient { ableToReceiveMessage: false, ...options, }; - return await this.request( + return this.request( [ [11, 2, squareMid], [ @@ -678,11 +678,11 @@ export class SquareClient extends LiffClient { /** * @description Remove square subscriptions. */ - public async removeSubscriptions(options: { + public removeSubscriptions(options: { subscriptionIds: number[]; }): Promise { const { subscriptionIds } = { ...options }; - return await this.request( + return this.request( [[15, 2, [10, subscriptionIds]]], "removeSubscriptions", this.SquareService_PROTOCOL_TYPE, @@ -694,12 +694,12 @@ export class SquareClient extends LiffClient { /** * @description Unsend square chat message. */ - public async unsendSquareMessage(options: { + public unsendSquareMessage(options: { squareChatMid: string; squareMessageId: string; }): Promise { const { squareChatMid, squareMessageId } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareChatMid], [11, 3, squareMessageId], @@ -714,13 +714,13 @@ export class SquareClient extends LiffClient { /** * @description Create square chat. */ - public async createSquareChat(options: { + public createSquareChat(options: { squareChatMid: string; squareName: string; chatImageObsHash?: string; - squareChatType?: LINETypes.SquareChatType; + squareChatType?: LINETypes.SquareChatType & number; maxMemberCount?: number; - ableToSearchMessage?: LINETypes.BooleanState; + ableToSearchMessage?: LINETypes.BooleanState & number; squareMemberMids?: string[]; }): Promise { const { @@ -739,7 +739,7 @@ export class SquareClient extends LiffClient { squareMemberMids: [], ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq("sq")], [ @@ -766,12 +766,12 @@ export class SquareClient extends LiffClient { /** * @description Delete square chat. */ - public async deleteSquareChat(options: { + public deleteSquareChat(options: { squareChatMid: string; revision?: number; }): Promise { const { squareChatMid, revision } = { revision: 0, ...options }; - return await this.request( + return this.request( [ [11, 2, squareChatMid], [10, 3, revision], @@ -833,7 +833,7 @@ export class SquareClient extends LiffClient { } if (continueRequest && response.continuationToken) { - return await this.continueRequest({ + return this.continueRequest({ response: response as LooseType, continuationToken: response.continuationToken, method: { @@ -849,11 +849,11 @@ export class SquareClient extends LiffClient { /** * @description Get square feature set. */ - public async getSquareFeatureSet(options: { + public getSquareFeatureSet(options: { squareMid: string; }): Promise { const { squareMid } = { ...options }; - return await this.request( + return this.request( [[11, 2, squareMid]], "getSquareFeatureSet", this.SquareService_PROTOCOL_TYPE, @@ -865,11 +865,11 @@ export class SquareClient extends LiffClient { /** * @description Get square invitation ticket Url. */ - public async getSquareInvitationTicketUrl(options: { + public getSquareInvitationTicketUrl(options: { mid: string; }): Promise { const { mid } = { ...options }; - return await this.request( + return this.request( [[11, 2, mid]], "getInvitationTicketUrl", this.SquareService_PROTOCOL_TYPE, @@ -881,10 +881,10 @@ export class SquareClient extends LiffClient { /** * @description Update square chat member. */ - public async updateSquareChatMember(options: { + public updateSquareChatMember(options: { squareMemberMid: string; squareChatMid: string; - updatedAttrs?: LINETypes.SquareChatMemberAttribute[]; + updatedAttrs?: (LINETypes.SquareChatMemberAttribute & number)[]; notificationForMessage?: boolean; notificationForNewMember?: boolean; }): Promise { @@ -900,7 +900,7 @@ export class SquareClient extends LiffClient { notificationForNewMember: true, ...options, }; - return await this.request( + return this.request( [ [14, 2, [8, updatedAttrs]], [ @@ -924,13 +924,13 @@ export class SquareClient extends LiffClient { /** * @description Update square member. */ - public async updateSquareMember(options: { + public updateSquareMember(options: { squareMemberMid: string; squareMid: string; displayName?: string; - membershipState?: LINETypes.SquareMembershipState; - role?: LINETypes.SquareMemberRole; - updatedAttrs?: LINETypes.SquareMemberAttribute[]; + membershipState?: LINETypes.SquareMembershipState & number; + role?: LINETypes.SquareMemberRole & number; + updatedAttrs?: (LINETypes.SquareMemberAttribute & number)[]; updatedPreferenceAttrs?: number[]; revision?: number; }): Promise { @@ -963,7 +963,7 @@ export class SquareClient extends LiffClient { squareMember.push([8, 8, role]); } squareMember.push([10, 9, revision]); - return await this.request( + return this.request( [ [14, 2, [8, updatedAttrs]], [14, 3, [8, updatedPreferenceAttrs]], @@ -994,7 +994,7 @@ export class SquareClient extends LiffClient { const getSquareMemberResp = await this.getSquareMember({ squareMemberMid }); const squareMember = getSquareMemberResp.squareMember; const squareMemberRevision = squareMember.revision; - return await this.updateSquareMember({ + return this.updateSquareMember({ squareMemberMid, squareMid, membershipState: MEMBERSHIP_STATE, @@ -1007,12 +1007,12 @@ export class SquareClient extends LiffClient { /** * @description Check square join code. */ - public async checkSquareJoinCode(options: { + public checkSquareJoinCode(options: { squareMid: string; code: string; }): Promise { const { squareMid, code } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareMid], [11, 3, code], @@ -1027,13 +1027,13 @@ export class SquareClient extends LiffClient { /** * @description Create square chat announcement. */ - public async createSquareChatAnnouncement(options: { + public createSquareChatAnnouncement(options: { squareChatMid: string; squareMessageId: string; text: string; senderSquareMemberMid: string; createdAt: number; - announcementType?: LINETypes.SquareChatAnnouncementType; + announcementType?: LINETypes.SquareChatAnnouncementType & number; }): Promise { const { squareChatMid, @@ -1043,7 +1043,7 @@ export class SquareClient extends LiffClient { createdAt, announcementType, } = { announcementType: 0, ...options }; - return await this.request( + return this.request( [ [8, 1, 0], [11, 2, squareChatMid], @@ -1108,7 +1108,7 @@ export class SquareClient extends LiffClient { /** * @description Search square chat members. */ - public async searchSquareChatMembers(options: { + public searchSquareChatMembers(options: { squareChatMid: string; displayName: string; continuationToken?: string; @@ -1118,7 +1118,7 @@ export class SquareClient extends LiffClient { limit: 200, ...options, }; - return await this.request( + return this.request( [ [11, 1, squareChatMid], [12, 2, [[11, 1, displayName]]], @@ -1135,11 +1135,11 @@ export class SquareClient extends LiffClient { /** * @description Get square emid. */ - public async getSquareEmid(options: { + public getSquareEmid(options: { squareMid: string; }): Promise { const { squareMid } = { ...options }; - return await this.request( + return this.request( [[11, 1, squareMid]], "getSquareEmid", this.SquareService_PROTOCOL_TYPE, @@ -1195,13 +1195,13 @@ export class SquareClient extends LiffClient { /** * @description Manual square repair. */ - public async manualRepair(options: { + public manualRepair(options: { limit?: number; syncToken?: string; continuationToken?: string; }): Promise { const { limit, syncToken, continuationToken } = { limit: 100, ...options }; - return await this.request( + return this.request( [ [11, 1, syncToken], [8, 2, limit], @@ -1217,11 +1217,11 @@ export class SquareClient extends LiffClient { /** * @description Leave square. */ - public async leaveSquare(options: { + public leaveSquare(options: { squareMid: string; }): Promise { const { squareMid } = { ...options }; - return await this.request( + return this.request( [[11, 2, squareMid]], "leaveSquare", this.SquareService_PROTOCOL_TYPE, @@ -1233,13 +1233,13 @@ export class SquareClient extends LiffClient { /** * @description Report square. */ - public async reportSquare(options: { + public reportSquare(options: { squareMid: string; - reportType: LINETypes.ReportType; + reportType: LINETypes.ReportType & number; otherReason?: string; }): Promise { const { squareMid, reportType, otherReason } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareMid], [10, 3, reportType], @@ -1255,11 +1255,11 @@ export class SquareClient extends LiffClient { /** * @description Report square message. */ - public async reportSquareMessage(options: { + public reportSquareMessage(options: { squareMid: string; squareChatMid: string; squareMessageId: string; - reportType: LINETypes.ReportType; + reportType: LINETypes.ReportType & number; otherReason?: string; threadMid?: string; }): Promise { @@ -1271,7 +1271,7 @@ export class SquareClient extends LiffClient { otherReason, threadMid, } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareMid], [11, 3, squareChatMid], @@ -1290,9 +1290,9 @@ export class SquareClient extends LiffClient { /** * @description Report square member. */ - public async reportSquareMember(options: { + public reportSquareMember(options: { squareMemberMid: string; - reportType: LINETypes.ReportType; + reportType: LINETypes.ReportType & number; otherReason?: string; squareChatMid?: string; threadMid?: string; @@ -1304,7 +1304,7 @@ export class SquareClient extends LiffClient { squareChatMid, threadMid, } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareMemberMid], [8, 3, reportType], @@ -1322,12 +1322,12 @@ export class SquareClient extends LiffClient { /** * @description Delete square message. */ - public async destroySquareMessage(options: { + public destroySquareMessage(options: { squareChatMid?: string; messageId?: string; }): Promise { const { squareChatMid, messageId } = { ...options }; - return await this.request( + return this.request( [ [11, 2, squareChatMid], [11, 4, messageId], @@ -1342,11 +1342,11 @@ export class SquareClient extends LiffClient { /** * @description Send square thrift request. */ - public async sendSquareRequest( + public sendSquareRequest( methodName: string, params: NestedArray, ): Promise { - return await this.request( + return this.request( params, methodName, this.SquareService_PROTOCOL_TYPE, @@ -1366,7 +1366,7 @@ export class SquareClient extends LiffClient { * @experimental * @description Fetch square thread events. */ - public async fetchSquareThreadEvents(options: { + public fetchSquareThreadEvents(options: { squareChatMid: string; squareThreadMid: string; limit?: number; @@ -1374,18 +1374,18 @@ export class SquareClient extends LiffClient { continuationToken?: string; subscriptionId?: number; }): Promise { - return await this.fetchSquareChatEvents(options); + return this.fetchSquareChatEvents(options); } /** * @experimental * @description Send message to square thread. */ - public async sendSquareThreadMessage(options: { + public sendSquareThreadMessage(options: { squareThreadMid: string; squareChatMid: string; text?: string; - contentType?: LINETypes.ContentType; + contentType?: LINETypes.ContentType & number; contentMetadata?: LooseType; relatedMessageId?: string; }): Promise { @@ -1407,7 +1407,7 @@ export class SquareClient extends LiffClient { msg.push([11, 21, relatedMessageId], [8, 22, 3], [8, 24, 2]); } - return await this.request( + return this.request( [ [8, 1, this.getReqseq("sq")], [11, 2, squareChatMid], diff --git a/packages/linejs/client/clients/internal/talk-client.ts b/packages/linejs/client/clients/internal/talk-client.ts index 94fddb4..b6e8047 100644 --- a/packages/linejs/client/clients/internal/talk-client.ts +++ b/packages/linejs/client/clients/internal/talk-client.ts @@ -104,7 +104,7 @@ export class TalkClient extends ChannelClient { e2ee, chunk, }; - return await this.sendMessage(options); + return this.sendMessage(options); } const message: NestedArray = [ @@ -143,7 +143,7 @@ export class TalkClient extends ChannelClient { message.push([8, 24, 1]); } try { - return await this.direct_request( + return this.direct_request( [ [8, 1, this.getReqseq()], [12, 2, message], @@ -160,7 +160,7 @@ export class TalkClient extends ChannelClient { !e2ee ) { options.e2ee = true; - return await this.sendMessage(options); + return this.sendMessage(options); } else { throw error; } @@ -176,7 +176,7 @@ export class TalkClient extends ChannelClient { const { messageId } = { ...options, }; - return await this.direct_request( + return this.direct_request( [ [ 12, @@ -199,12 +199,12 @@ export class TalkClient extends ChannelClient { */ override async reactToMessage(options: { messageId: string; - reactionType: LINETypes.MessageReactionType; + reactionType: LINETypes.MessageReactionType & number; }): Promise { const { messageId, reactionType } = { ...options, }; - return await this.direct_request( + return this.direct_request( [ [ [ @@ -248,7 +248,7 @@ export class TalkClient extends ChannelClient { mid: string; }): Promise { const { mid } = { ...options }; - return await this.direct_request( + return this.direct_request( [[11, 2, mid]], "negotiateE2EEPublicKey", this.TalkService_PROTOCOL_TYPE, @@ -262,7 +262,7 @@ export class TalkClient extends ChannelClient { chatMid: string; }): Promise { const { keyVersion, chatMid } = { ...options }; - return await this.direct_request( + return this.direct_request( [ [8, 2, keyVersion], [11, 3, chatMid], @@ -282,7 +282,7 @@ export class TalkClient extends ChannelClient { lastMessageId: string; }): Promise { const { lastMessageId, chatMid } = { ...options }; - return await this.direct_request( + return this.direct_request( [ [8, 1, this.getReqseq()], [11, 2, chatMid], @@ -345,7 +345,9 @@ export class TalkClient extends ChannelClient { receivedOnly: false, ...options, }; - const id64 = new Int64((typeof id==="string"?BigInt(id):id).toString(16)); + const id64 = new Int64( + (typeof id === "string" ? BigInt(id) : id).toString(16), + ); return ( await this.direct_request( [ @@ -589,7 +591,7 @@ export class TalkClient extends ChannelClient { withMembers: true, ...options, }; - return await this.direct_request( + return this.direct_request( [ [ 12, @@ -612,7 +614,7 @@ export class TalkClient extends ChannelClient { * @description Get information on all friend. */ public async getAllContactIds(): Promise { - return await this.direct_request( + return this.direct_request( [], "getAllContactIds", this.TalkService_PROTOCOL_TYPE, @@ -631,7 +633,7 @@ export class TalkClient extends ChannelClient { const { to, mid } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, to], @@ -653,7 +655,7 @@ export class TalkClient extends ChannelClient { const { to } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, to], @@ -675,7 +677,7 @@ export class TalkClient extends ChannelClient { const { to, mids } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, to], @@ -697,7 +699,7 @@ export class TalkClient extends ChannelClient { const { to } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, to], @@ -718,7 +720,7 @@ export class TalkClient extends ChannelClient { const { groupMid } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, groupMid], @@ -739,7 +741,7 @@ export class TalkClient extends ChannelClient { const { ticketId } = { ...options, }; - return await this.request( + return this.request( [[11, 1, ticketId]], "findChatByTicket", this.TalkService_PROTOCOL_TYPE, @@ -758,7 +760,7 @@ export class TalkClient extends ChannelClient { const { to, ticket } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [11, 2, to], @@ -777,13 +779,13 @@ export class TalkClient extends ChannelClient { public async updateChat(options: { chatMid: string; chatSet: Partial; - updatedAttribute: LINETypes.ChatAttribute; + updatedAttribute: LINETypes.ChatAttribute & number; }): Promise { const { chatMid, chatSet, updatedAttribute } = { ...options, }; - return await this.request( + return this.request( [ [8, 1, this.getReqseq()], [ @@ -840,7 +842,7 @@ export class TalkClient extends ChannelClient { displayFields: 5, ...options, }; - return await this.direct_request( + return this.direct_request( [ [8, 1, this.getReqseq()], [11, 2, chatRoomMid], @@ -862,4 +864,50 @@ export class TalkClient extends ChannelClient { this.TalkService_API_PATH, ); } + + public async getLastE2EEPublicKeys(options: { chatMid: string }): Promise< + Record + > { + const { chatMid } = { ...options }; + const _res = await this.direct_request( + [[11, 2, chatMid]], + "getLastE2EEPublicKeys", + this.TalkService_PROTOCOL_TYPE, + false, + this.TalkService_API_PATH, + ); + const res: Record = {}; + for (const key in _res) { + if (Object.prototype.hasOwnProperty.call(_res, key)) { + const val = _res[key]; + res[key] = this.parser.rename_thrift("E2EEPublicKey", val); + } + } + return res; + } + + public async registerE2EEGroupKey(options: { + keyVersion: number; + chatMid: string; + members: string[]; + keyIds: number[]; + encryptedSharedKeys: Buffer[]; + }): Promise { + const { keyVersion, chatMid, members, keyIds, encryptedSharedKeys } = { + ...options, + }; + return this.direct_request( + [ + [8, 2, keyVersion], + [11, 3, chatMid], + [15, 4, [11, members]], + [15, 5, [8, keyIds]], + [15, 6, [11, encryptedSharedKeys]], + ], + "registerE2EEGroupKey", + this.TalkService_PROTOCOL_TYPE, + "E2EEGroupSharedKey", + this.TalkService_API_PATH, + ); + } } diff --git a/packages/linejs/client/clients/timeline/index.ts b/packages/linejs/client/clients/timeline/index.ts index c9afee5..58a38cd 100644 --- a/packages/linejs/client/clients/timeline/index.ts +++ b/packages/linejs/client/clients/timeline/index.ts @@ -159,7 +159,7 @@ export class Timeline extends SettingsClient { "x-lhm": "POST", "Content-type": "application/json", }; - return await this.customFetch( + return this.customFetch( `https://${this.endpoint}/mh/api/v57/post/create.json?${params}`, { headers, body: JSON.stringify(data), method: "POST" }, ).then((r) => r.json()); @@ -180,7 +180,7 @@ export class Timeline extends SettingsClient { homeId, postId, }); - return await this.customFetch( + return this.customFetch( `https://${this.endpoint}/mh/api/v57/post/get.json?${params}`, { headers }, ).then((r) => r.json()); @@ -210,7 +210,7 @@ export class Timeline extends SettingsClient { data.updatedTime = updatedTime.toString(); } const params = new URLSearchParams(data); - return await this.customFetch( + return this.customFetch( `https://${this.endpoint}/mh/api/v57/post/list.json?${params}`, { headers }, ).then((r) => r.json()); diff --git a/packages/linejs/client/entities/object.ts b/packages/linejs/client/entities/object.ts index 7456cbf..8b1e9b0 100644 --- a/packages/linejs/client/entities/object.ts +++ b/packages/linejs/client/entities/object.ts @@ -514,7 +514,7 @@ export class User extends TypedEventEmitter { this.rawSource = contact; console.log(contactEntry); this.mid = contact.mid; - this.createdTime = new Date(contact.createdTime as number * 1000); + this.createdTime = new Date((contact.createdTime as number) * 1000); this.type = contact.type; this.status = contact.status; this.relation = contact.relation; @@ -524,7 +524,7 @@ export class User extends TypedEventEmitter { this.thumbnailUrl = contact.thumbnailUrl; this.statusMessage = contact.statusMessage; this.displayNameOverridden = contact.displayNameOverridden; - this.favoriteTime = new Date(contact.favoriteTime as number * 1000); + this.favoriteTime = new Date((contact.favoriteTime as number) * 1000); this.capableVoiceCall = contact.capableVoiceCall; this.capableVideoCall = contact.capableVideoCall; this.capableMyhome = contact.capableMyhome; @@ -551,7 +551,7 @@ export class User extends TypedEventEmitter { this.birthday = contactEntry.calendarEvents.events[0]; this.rawSource = contact; this.mid = contact.mid; - this.createdTime = new Date(contact.createdTime as number * 1000); + this.createdTime = new Date((contact.createdTime as number) * 1000); this.type = contact.type; this.status = contact.status; this.relation = contact.relation; @@ -561,7 +561,7 @@ export class User extends TypedEventEmitter { this.thumbnailUrl = contact.thumbnailUrl; this.statusMessage = contact.statusMessage; this.displayNameOverridden = contact.displayNameOverridden; - this.favoriteTime = new Date(contact.favoriteTime as number * 1000); + this.favoriteTime = new Date((contact.favoriteTime as number) * 1000); this.capableVoiceCall = contact.capableVoiceCall; this.capableVideoCall = contact.capableVideoCall; this.capableMyhome = contact.capableMyhome; @@ -688,7 +688,7 @@ export class Group extends TypedEventEmitter { user = new User(_members[key], client); } user.groupStatus.joinedAt = new Date( - chat.extra.groupExtra.memberMids[key] as number * 1000, + (chat.extra.groupExtra.memberMids[key] as number) * 1000, ); user.kick = user.kick.bind(user, chat.chatMid); members.push(); @@ -715,7 +715,7 @@ export class Group extends TypedEventEmitter { user = new User(_invitee[key], client); } user.groupStatus.invitedAt = new Date( - chat.extra.groupExtra.inviteeMids[key] as number * 1000, + (chat.extra.groupExtra.inviteeMids[key] as number) * 1000, ); user.kick = user.kick.bind(user, chat.chatMid); members.push(); @@ -734,7 +734,7 @@ export class Group extends TypedEventEmitter { this.rawSource = chat; this.mid = chat.chatMid; - this.createdTime = new Date(chat.createdTime as number * 1000); + this.createdTime = new Date((chat.createdTime as number) * 1000); this.name = chat.chatName; this.picturePath = chat.picturePath; this.notificationDisabled = chat.notificationDisabled; @@ -844,7 +844,7 @@ export class Operation { this.client = client; this.revision = source.revision as number; this.checksum = source.checksum; - this.createdTime = new Date(source.createdTime as number * 1000); + this.createdTime = new Date((source.createdTime as number) * 1000); this.type = (parseEnum("OpType", source.type) as LINETypes.OpType) || source.type; this.reqSeq = source.reqSeq; @@ -1403,7 +1403,7 @@ export class Message { "ContentType", this.rawMessage.contentType, ) as LINETypes.ContentType) || this.rawMessage.contentType; - this.createdTime = new Date(this.rawMessage.createdTime as number * 1000); + this.createdTime = new Date((this.rawMessage.createdTime as number) * 1000); this.id = this.rawMessage.id; if (this.rawMessage.text) { this.content = this.rawMessage.text; diff --git a/packages/linejs/client/libs/storage/dir-storage.ts b/packages/linejs/client/libs/storage/dir-storage.ts index bd40474..ba85856 100644 --- a/packages/linejs/client/libs/storage/dir-storage.ts +++ b/packages/linejs/client/libs/storage/dir-storage.ts @@ -99,7 +99,7 @@ export class DirStorage extends BaseStorage { case "number": return "n" + obj.toString(); case "boolean": - return "b" + obj?"T":""; + return "b" + obj ? "T" : ""; default: return "x"; } diff --git a/packages/linejs/client/libs/thrift/parser.ts b/packages/linejs/client/libs/thrift/parser.ts index 35a9bc3..34b89fe 100644 --- a/packages/linejs/client/libs/thrift/parser.ts +++ b/packages/linejs/client/libs/thrift/parser.ts @@ -1,4 +1,5 @@ import type { LooseType } from "../../entities/common.ts"; +import type * as LINEType from "../../../../types/line_types.ts"; const TYPE = { STOP: 0,