From 413c508efd4b9a784d1b7e7bdd981e6dfafe2340 Mon Sep 17 00:00:00 2001 From: Alexander Harding Date: Thu, 18 Sep 2025 21:42:45 -0500 Subject: [PATCH] fix(piefed): get profile content Regression from 3079e33 --- src/providers/piefed/index.ts | 103 ++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 22 deletions(-) diff --git a/src/providers/piefed/index.ts b/src/providers/piefed/index.ts index ba995c9..066a839 100644 --- a/src/providers/piefed/index.ts +++ b/src/providers/piefed/index.ts @@ -8,7 +8,11 @@ import { import { InvalidPayloadError, UnsupportedError } from "../../errors"; import { cleanThreadiverseParams } from "../../helpers"; import buildSafeClient from "../../SafeClient"; -import { PostView } from "../../types"; +import { + ListPersonContent, + ListPersonContentResponse, + PostView, +} from "../../types"; import { getInboxItemPublished, getPostCommentItemCreatedDate, @@ -614,13 +618,55 @@ export class UnsafePiefedClient implements BaseClient { } async listPersonContent( + payload: ListPersonContent, + options?: RequestOptions, + ): Promise { + switch (payload.type) { + case "All": + case undefined: { + const response = await Promise.all([ + this.#listPersonPosts(payload, options), + + this.#listPersonComments(payload, options), + ]).then(([posts, comments]) => + [...posts.data, ...comments.data].sort( + (a, b) => + getPostCommentItemCreatedDate(b) - + getPostCommentItemCreatedDate(a), + ), + ); + + return { + ...compat.toPageResponse(payload), + + data: response, + }; + } + + case "Comments": + return this.#listPersonComments(payload, options); + + case "Posts": + return this.#listPersonPosts(payload, options); + } + } + + async listPersonLiked( + ..._params: Parameters + ): ReturnType { + throw new UnsupportedError("List person liked is not supported by piefed"); + } + + async listPersonSaved( payload: Parameters[0], options?: RequestOptions, ): ReturnType { const response = await this.#client.GET("/user", { ...options, - // @ts-expect-error TODO: fix this - params: { query: compat.fromPageParams(payload) }, + params: { + // @ts-expect-error TODO: fix this + query: { ...compat.fromPageParams(payload), saved_only: true }, + }, }); const data = (() => { @@ -647,25 +693,6 @@ export class UnsafePiefedClient implements BaseClient { data, }; } - async listPersonLiked( - ..._params: Parameters - ): ReturnType { - throw new UnsupportedError("List person liked is not supported by piefed"); - } - - async listPersonSaved( - payload: Parameters[0], - options?: RequestOptions, - ): ReturnType { - return this.listPersonContent( - { - ...payload, - // @ts-expect-error TODO: fix this - saved_only: true, - }, - options, - ); - } async listPostReports( ..._params: Parameters @@ -924,6 +951,38 @@ export class UnsafePiefedClient implements BaseClient { url: data.url, }; } + + async #listPersonComments( + payload: Parameters[0], + options?: RequestOptions, + ) { + const response = await this.#client.GET("/comment/list", { + ...options, + // @ts-expect-error TODO: fix this + params: { query: compat.fromPageParams(payload) }, + }); + + return { + ...compat.toPageResponse(payload), + data: response.data!.comments.map(compat.toCommentView), + }; + } + + async #listPersonPosts( + payload: Parameters[0], + options?: RequestOptions, + ) { + const response = await this.#client.GET("/post/list", { + ...options, + // @ts-expect-error TODO: fix this + params: { query: compat.fromPageParams(payload) }, + }); + + return { + ...compat.toPageResponse(payload), + data: response.data!.posts.map(compat.toPostView), + }; + } } export default buildSafeClient(UnsafePiefedClient);