Skip to content

Commit

Permalink
add "getServerTime" and format
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Sep 20, 2024
1 parent d20b0cd commit d0cc5e1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 52 deletions.
1 change: 1 addition & 0 deletions 2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cache":"{}","e2eeKeys:4711761":"{\"keyId\":\"4711761\",\"privKey\":\"GLGdt4yaiiX6w2A1Bs5LI6K3pRnuth/fGbXbmkcZ7GA=\",\"pubKey\":\"zjE9eIwZWEWTgXJ+pbnklaEjY1UdQRFWeRL6lWExUkM=\",\"e2eeVersion\":\"1\"}"}
16 changes: 16 additions & 0 deletions packages/linejs/client/clients/base-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,22 @@ export class BaseClient extends TypedEventEmitter<ClientEvents> {
}
}

/**
* @description Gets the server time
*/
public async getServerTime(): Promise<number> {
return await this.request(
[
128, 1, 0, 1, 0, 0, 0, 13, 103, 101, 116, 83, 101, 114, 118, 101, 114,
84, 105, 109, 101, 0, 0, 0, 0, 0,
],
"getServerTime",
this.LINEService_PROTOCOL_TYPE,
false,
this.LINEService_API_PATH,
);
}

/**
* @description Gets the profile of the current user.
*/
Expand Down
7 changes: 6 additions & 1 deletion packages/linejs/client/clients/internal/liff-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ export class LiffClient extends BaseClient {
forceIssue?: boolean;
}): Promise<LooseType> {
let token: string;
const { to, messages, tryConsent: _tryConsent, forceIssue } = {
const {
to,
messages,
tryConsent: _tryConsent,
forceIssue,
} = {
tryConsent: true,
forceIssue: false,
...options,
Expand Down
5 changes: 4 additions & 1 deletion packages/linejs/client/clients/timeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class Timeline extends SettingsClient {
).then((r) => r.json());
}

public async deletePost(options: { homeId: string; postId: string }): Promise<LooseType> {
public async deletePost(options: {
homeId: string;
postId: string;
}): Promise<LooseType> {
const { homeId, postId } = { ...options };
const headers = {
...this.timelineHeaders,
Expand Down
109 changes: 60 additions & 49 deletions packages/linejs/client/entities/message-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ export class User {
static async from(mid: string, client: Client) {
if (mid === client.user?.mid) {
return new this(
{ ...(await client.getContactsV2({ mids: [mid] })).contacts[mid], contact: await client.getContact({ mid }) },
{
...(await client.getContactsV2({ mids: [mid] })).contacts[mid],
contact: await client.getContact({ mid }),
},
client,
);
}
Expand All @@ -212,9 +215,11 @@ export class User {
private client: Client,
) {
const { contact } = contactEntry;
this.birthday = contactEntry.calendarEvents?.events && contactEntry.calendarEvents.events[0];
this.birthday =
contactEntry.calendarEvents?.events &&
contactEntry.calendarEvents.events[0];
this.rawSource = contact;
console.log(contactEntry)
console.log(contactEntry);
this.mid = contact.mid;
this.createdTime = new Date(contact.createdTime * 1000);
this.type = contact.type;
Expand Down Expand Up @@ -291,14 +296,14 @@ export class User {
options:
| string
| {
text?: string;
contentType?: number;
contentMetadata?: LooseType;
relatedMessageId?: string;
location?: LINETypes.Location;
chunk?: string[] | Buffer[];
e2ee?: boolean;
},
text?: string;
contentType?: number;
contentMetadata?: LooseType;
relatedMessageId?: string;
location?: LINETypes.Location;
chunk?: string[] | Buffer[];
e2ee?: boolean;
},
): Promise<LINETypes.Message> {
if (typeof options === "string") {
return this.send({ text: options });
Expand All @@ -315,7 +320,7 @@ export class User {
public async updateStatus() {
this.updateStatusFrom(
(await this.client.getContactsV2({ mids: [this.mid] })).contacts[
this.mid
this.mid
],
);
}
Expand Down Expand Up @@ -370,14 +375,17 @@ export class Group {
mids: Object.keys(chat.extra.groupExtra.memberMids),
})
).contacts;
console.log(_members)
console.log(_members);
const members: User[] = [];
for (const key in _members) {
if (Object.prototype.hasOwnProperty.call(_members, key)) {
let user: User;
if (key === client.user?.mid) {
user = new User(
{ ..._members[key], contact: await client.getContact({ mid: key }) },
{
..._members[key],
contact: await client.getContact({ mid: key }),
},
client,
);
} else {
Expand All @@ -401,7 +409,10 @@ export class Group {
let user: User;
if (key === client.user?.mid) {
user = new User(
{ ..._invitee[key], contact: await client.getContact({ mid: key }) },
{
..._invitee[key],
contact: await client.getContact({ mid: key }),
},
client,
);
} else {
Expand Down Expand Up @@ -441,14 +452,14 @@ export class Group {
options:
| string
| {
text?: string;
contentType?: number;
contentMetadata?: LooseType;
relatedMessageId?: string;
location?: LINETypes.Location;
chunk?: string[] | Buffer[];
e2ee?: boolean;
},
text?: string;
contentType?: number;
contentMetadata?: LooseType;
relatedMessageId?: string;
location?: LINETypes.Location;
chunk?: string[] | Buffer[];
e2ee?: boolean;
},
): Promise<LINETypes.Message> {
if (typeof options === "string") {
return this.send({ text: options });
Expand Down Expand Up @@ -1358,14 +1369,14 @@ export class TalkMessage extends ClientMessage {
public send(
options:
| {
text?: string | undefined;
contentType?: number | undefined;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
location?: LooseType;
chunk?: string[] | undefined;
e2ee?: boolean | undefined;
}
text?: string | undefined;
contentType?: number | undefined;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
location?: LooseType;
chunk?: string[] | undefined;
e2ee?: boolean | undefined;
}
| string,
): Promise<LINETypes.Message> {
if (typeof options === "string") {
Expand All @@ -1388,14 +1399,14 @@ export class TalkMessage extends ClientMessage {
public reply(
options:
| {
text?: string | undefined;
contentType?: number | undefined;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
location?: LooseType;
chunk?: string[] | undefined;
e2ee?: boolean | undefined;
}
text?: string | undefined;
contentType?: number | undefined;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
location?: LooseType;
chunk?: string[] | undefined;
e2ee?: boolean | undefined;
}
| string,
): Promise<LINETypes.Message> {
if (typeof options === "string") {
Expand Down Expand Up @@ -1516,11 +1527,11 @@ export class SquareMessage extends ClientMessage {
public send(
options:
| {
text?: string | undefined;
contentType?: LooseType;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
}
text?: string | undefined;
contentType?: LooseType;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
}
| string,
safe: boolean = true,
): Promise<LINETypes.SendMessageResponse> {
Expand All @@ -1539,11 +1550,11 @@ export class SquareMessage extends ClientMessage {
public reply(
options:
| {
text?: string | undefined;
contentType?: LooseType;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
}
text?: string | undefined;
contentType?: LooseType;
contentMetadata?: LooseType;
relatedMessageId?: string | undefined;
}
| string,
safe: boolean = true,
): Promise<LINETypes.SendMessageResponse> {
Expand Down
2 changes: 1 addition & 1 deletion packages/linejs/client/libs/thrift/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function writeStruct(output: LooseType, clValue: NestedArray = []): void {

clValue.forEach((e: LooseType) => {
if (e === null || e === undefined) {
return
return;
}
writeValue(output, e[0], e[1], e[2]);
});
Expand Down

0 comments on commit d0cc5e1

Please sign in to comment.