forked from thislooksfun/snoots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add getters for moderation listings
- Loading branch information
1 parent
a386903
commit 1c3876e
Showing
3 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { InvalidKindError } from "../helper/errors"; | ||
import type { Comment, Post } from "../objects"; | ||
import type { _Listing, Context, Fetcher } from "./listing"; | ||
import Listing, { Pager } from "./listing"; | ||
|
||
export class PostOrCommentPager extends Pager<Post | Comment> { | ||
async fetch(ctx: Context): Promise<PostOrCommentListing> { | ||
const pg = await this.nextPage(ctx); | ||
return new PostOrCommentListing(pg, ctx); | ||
} | ||
} | ||
|
||
export default class PostOrCommentListing extends Listing<Post | Comment> { | ||
constructor(l: _Listing, ctx: Context) { | ||
let fetcher: Fetcher<Post | Comment> | undefined; | ||
|
||
if (l.after != null) { | ||
fetcher = new PostOrCommentPager(l.after); | ||
} | ||
|
||
const arr: (Post | Comment)[] = []; | ||
for (const c of l.children) { | ||
switch (c.kind) { | ||
case "t1": | ||
arr.push(ctx.client.comments.fromRaw(c)); | ||
break; | ||
case "t3": | ||
arr.push(ctx.client.posts.fromRaw(c)); | ||
break; | ||
default: | ||
throw new InvalidKindError("t1 or t3", c.kind); | ||
} | ||
} | ||
|
||
super(ctx, arr, fetcher); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters