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.
fix: unbreak search()ed post comments yet again
The previous fix for comment replies broke top level comments. This fixes that issue. I hate Reddit's REST API so much. Fixes thislooksfun#71
- Loading branch information
1 parent
ed33872
commit 09876c6
Showing
2 changed files
with
33 additions
and
9 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,28 @@ | ||
import type { | ||
Fetcher, | ||
ListingContext, | ||
ListingObject, | ||
} from "../../listing/listing"; | ||
import type { Comment } from "../object"; | ||
|
||
import { emptyRedditListing } from "../../listing/util"; | ||
import { CommentListing } from "./listing"; | ||
|
||
/** @internal */ | ||
export class PostComments implements Fetcher<Comment> { | ||
async fetch(context: ListingContext): Promise<CommentListing> { | ||
if (!context.post) { | ||
// This should never happen, but just in case... | ||
throw new Error("Precondition failed: context.post is falsy"); | ||
} | ||
|
||
const pth = `comments/${context.post}`; | ||
const childrenResponse: [unknown, ListingObject] = | ||
await context.client.gateway.get(pth, { comment: context.post }); | ||
|
||
return new CommentListing( | ||
childrenResponse[1].data ?? emptyRedditListing, | ||
context | ||
); | ||
} | ||
} |