Skip to content

Commit

Permalink
update events and fix ts5.6 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Oct 10, 2024
1 parent bdc00c9 commit 3889369
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/linejs/client/clients/base-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class BaseClient extends TypedEventEmitter<ClientEvents> {
for (const event of myEvents.events) {
this.emit("square:event", event);

if (event.type === LINETypes.SquareEventType.NOTIFICATION_MESSAGE) {
if (event.type === LINETypes.SquareEventType._NOTIFICATION_MESSAGE) {
const payload = event.payload.notificationMessage;

if (!payload) {
Expand Down Expand Up @@ -395,6 +395,17 @@ export class BaseClient extends TypedEventEmitter<ClientEvents> {
await this.getMessageObsData(message.id, preview)),
message,
});
}else if (event.type === LINETypes.SquareEventType._NOTIFIED_UPDATE_SQUARE_CHAT_STATUS) {
const payload = event.payload.notifiedUpdateSquareChatStatus;

if (!payload) {
continue;
}

this.emit("square:status", {
...payload,
...payload["statusWithoutMessage"],
});
}
}
myEventsSyncToken = myEvents.syncToken;
Expand Down
3 changes: 2 additions & 1 deletion packages/linejs/client/clients/internal/talk-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type * as LINETypes from "@evex/linejs-types";
import type { LooseType } from "../../entities/common.ts";
import { ChannelClient } from "./channel-client.ts";
import type { Buffer } from "node:buffer";
import { InternalError } from "../../entities/errors.ts";

export class TalkClient extends ChannelClient {
public useTalkCache: boolean = false;
Expand Down Expand Up @@ -149,7 +150,7 @@ export class TalkClient extends ChannelClient {
this.TalkService_API_PATH,
);
} catch (error) {
if ((error.data?.code as string).includes("E2EE") && !e2ee) {
if (error instanceof InternalError && (error.data?.code as string).includes("E2EE") && !e2ee) {
options.e2ee = true;
return await this.sendMessage(options);
} else {
Expand Down
5 changes: 3 additions & 2 deletions packages/linejs/client/entities/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Log } from "./log.ts";
import type * as LINETypes from "@evex/linejs-types";
import type { Message, SquareMessage } from "./message.ts";
import type { SquaerStatus } from "./square-events.ts";

export type ClientEvents = {
pincall: (pincode: string) => void;
Expand All @@ -13,8 +14,8 @@ export type ClientEvents = {
"update:qrcert": (qrCert: string) => void;
log: (data: Log) => void;
"square:message": (squareMessage: SquareMessage) => void;
"square:member": (
squareMember: LINETypes.SquareEventNotificationMemberUpdate,
"square:status": (
squareStatus: SquaerStatus,
) => void;
"square:event": (squareEvent: LINETypes.SquareEvent) => void;
message: (message: Message) => void;
Expand Down
5 changes: 5 additions & 0 deletions packages/linejs/client/entities/square-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type * as LINETypes from "@evex/linejs-types";

export type SquaerStatus =
& LINETypes.SquareEventNotifiedUpdateSquareChatStatus
& LINETypes.SquareEventNotifiedUpdateSquareChatStatus["statusWithoutMessage"];

0 comments on commit 3889369

Please sign in to comment.