Skip to content

Commit b8eded8

Browse files
Madoa5561EdamAme-x
andauthored
Add createComment method (and patch loose types) (#113)
* Add createComment method * patch loose * Update packages/linejs/base/timeline/mod.ts --------- Co-authored-by: EdamAmex <121654029+EdamAme-x@users.noreply.github.com>
1 parent ada8a15 commit b8eded8

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

  • packages/linejs/base/timeline

packages/linejs/base/timeline/mod.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// deno-lint-ignore-file no-explicit-any
22
import type { BaseClient } from "../mod.ts";
3+
import type { LooseType } from "@evex/loose-types";
34

4-
export type TimelineResponse<T = any> = {
5+
export type TimelineResponse<T = LooseType> = {
56
code: number;
67
message: string;
78
result: T;
@@ -102,7 +103,7 @@ export class Timeline {
102103
homeId: homeId,
103104
sourceType: sourceType,
104105
});
105-
const postInfo: any = {
106+
const postInfo: LooseType = {
106107
readPermission: {
107108
type: readPermissionType,
108109
gids: readPermissionGids,
@@ -146,7 +147,7 @@ export class Timeline {
146147
obsFace: "[]",
147148
});
148149
});
149-
const contents: any = {
150+
const contents: LooseType = {
150151
contentsStyle: {
151152
textStyle: {
152153
textSizeMode: textSizeMode,
@@ -314,7 +315,7 @@ export class Timeline {
314315
if (!postId) {
315316
throw new Error("postId is required");
316317
}
317-
const postInfo: any = {
318+
const postInfo: LooseType = {
318319
postId: postId,
319320
editableContents: ["ALL"],
320321
readPermission: {
@@ -359,7 +360,7 @@ export class Timeline {
359360
obsFace: "[]",
360361
});
361362
});
362-
const contents: any = {
363+
const contents: LooseType = {
363364
sticonMetas: [],
364365
contentsStyle: {
365366
textStyle: textSizeMode || textAnimation ? {
@@ -433,6 +434,42 @@ export class Timeline {
433434
},
434435
).then((r) => r.json());
435436
}
437+
438+
public async createComment(options: {
439+
contentId: string; // postId
440+
commentText: string;
441+
homeId: string;
442+
sourceType?: string;
443+
contentsList?: LooseType[];
444+
}): Promise<TimelineResponse> {
445+
await this.initTimeline();
446+
const { contentId, commentText, homeId, sourceType, contentsList } = {
447+
sourceType: "TIMELINE",
448+
contentsList: [],
449+
...options,
450+
};
451+
const params = new URLSearchParams({
452+
sourceType,
453+
homeId,
454+
});
455+
const headers = {
456+
...this.timelineHeaders,
457+
"x-lhm": "POST",
458+
};
459+
const body = {
460+
commentText,
461+
contentId,
462+
contentsList,
463+
};
464+
return await this.client.fetch(
465+
`https://${this.client.request.endpoint}/ext/note/nt/api/v57/comment/create.json?${params}`,
466+
{
467+
headers,
468+
method: "POST",
469+
body: JSON.stringify(body),
470+
},
471+
).then((r) => r.json());
472+
}
436473

437474
public async sharePost(options: {
438475
postId: string;

0 commit comments

Comments
 (0)