Skip to content

Commit c12912f

Browse files
authored
fix: sort by new for listPersonContent (#28)
1 parent 645798a commit c12912f

2 files changed

Lines changed: 49 additions & 46 deletions

File tree

src/providers/lemmyv0/index.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export class UnsafeLemmyV0Client implements BaseClient {
119119

120120
async deleteImage(
121121
payload: Parameters<BaseClient["deleteImage"]>[0],
122-
options?: RequestOptions,
122+
options?: RequestOptions
123123
): ReturnType<BaseClient["deleteImage"]> {
124124
await this.#client.deleteImage(
125125
{
126126
filename: new URL(payload.url).pathname.split("/").pop()!,
127127
token: payload.delete_token,
128128
},
129-
options,
129+
options
130130
);
131131
}
132132

@@ -199,16 +199,16 @@ export class UnsafeLemmyV0Client implements BaseClient {
199199

200200
async getComments(
201201
payload: Parameters<BaseClient["getComments"]>[0],
202-
options?: RequestOptions,
202+
options?: RequestOptions
203203
): ReturnType<BaseClient["getComments"]> {
204204
if (payload.mode && payload.mode !== "lemmyv0")
205205
throw new InvalidPayloadError(
206-
`Connected to lemmyv1, ${payload.mode} is not supported`,
206+
`Connected to lemmyv1, ${payload.mode} is not supported`
207207
);
208208

209209
const response = await this.#client.getComments(
210210
cleanThreadiverseParams(compat.fromPageParams(payload)),
211-
options,
211+
options
212212
);
213213

214214
return {
@@ -239,11 +239,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
239239

240240
async getModlog(
241241
payload: Parameters<BaseClient["getModlog"]>[0],
242-
options?: RequestOptions,
242+
options?: RequestOptions
243243
): ReturnType<BaseClient["getModlog"]> {
244244
const response = await this.#client.getModlog(
245245
compat.fromPageParams(payload),
246-
options,
246+
options
247247
);
248248

249249
return {
@@ -257,7 +257,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
257257

258258
async getNotifications(
259259
payload: Parameters<BaseClient["getNotifications"]>[0],
260-
options?: RequestOptions,
260+
options?: RequestOptions
261261
): ReturnType<BaseClient["getNotifications"]> {
262262
const params = compat.fromPageParams(payload);
263263

@@ -274,7 +274,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
274274
].sort(
275275
(a, b) =>
276276
Date.parse(getInboxItemPublished(b)) -
277-
Date.parse(getInboxItemPublished(a)),
277+
Date.parse(getInboxItemPublished(a))
278278
);
279279

280280
return {
@@ -285,14 +285,14 @@ export class UnsafeLemmyV0Client implements BaseClient {
285285

286286
async getPersonDetails(
287287
payload: Parameters<BaseClient["getPersonDetails"]>[0],
288-
options?: RequestOptions,
288+
options?: RequestOptions
289289
): ReturnType<BaseClient["getPersonDetails"]> {
290290
const response = await this.#client.getPersonDetails(
291291
{
292292
...payload,
293293
limit: 1, // Lemmy melts down if limit is 0
294294
},
295-
options,
295+
options
296296
);
297297

298298
return {
@@ -303,11 +303,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
303303

304304
async getPersonMentions(
305305
payload: Parameters<BaseClient["getPersonMentions"]>[0],
306-
options?: RequestOptions,
306+
options?: RequestOptions
307307
): ReturnType<BaseClient["getPersonMentions"]> {
308308
const response = await this.#client.getPersonMentions(
309309
{ ...payload, sort: "New" },
310-
options,
310+
options
311311
);
312312

313313
return {
@@ -328,11 +328,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
328328

329329
async getPosts(
330330
payload: Parameters<BaseClient["getPosts"]>[0],
331-
options?: RequestOptions,
331+
options?: RequestOptions
332332
): ReturnType<BaseClient["getPosts"]> {
333333
if (payload.mode && payload.mode !== "lemmyv0")
334334
throw new InvalidPayloadError(
335-
`Connected to lemmyv1, ${payload.mode} is not supported`,
335+
`Connected to lemmyv1, ${payload.mode} is not supported`
336336
);
337337

338338
const page_cursor = payload.page_cursor;
@@ -346,7 +346,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
346346
...cleanThreadiverseParams(payload),
347347
page_cursor,
348348
},
349-
options,
349+
options
350350
);
351351

352352
return {
@@ -361,11 +361,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
361361

362362
async getPrivateMessages(
363363
payload: Parameters<BaseClient["getPrivateMessages"]>[0],
364-
options?: RequestOptions,
364+
options?: RequestOptions
365365
): ReturnType<BaseClient["getPrivateMessages"]> {
366366
const response = await this.#client.getPrivateMessages(
367367
compat.fromPageParams(payload),
368-
options,
368+
options
369369
);
370370

371371
return {
@@ -378,17 +378,17 @@ export class UnsafeLemmyV0Client implements BaseClient {
378378
..._params: Parameters<BaseClient["getRandomCommunity"]>
379379
): ReturnType<BaseClient["getRandomCommunity"]> {
380380
throw new UnsupportedError(
381-
"Get random community is not supported by Lemmy v0",
381+
"Get random community is not supported by Lemmy v0"
382382
);
383383
}
384384

385385
async getReplies(
386386
payload: Parameters<BaseClient["getReplies"]>[0],
387-
options?: RequestOptions,
387+
options?: RequestOptions
388388
): ReturnType<BaseClient["getReplies"]> {
389389
const response = await this.#client.getReplies(
390390
compat.fromPageParams({ ...payload, sort: "New" }),
391-
options,
391+
options
392392
);
393393

394394
return {
@@ -409,7 +409,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
409409
...site.my_user,
410410
follows: site.my_user.follows.map(compat.toCommunityFollowerView),
411411
moderates: site.my_user.moderates.map(
412-
compat.toCommunityModeratorView,
412+
compat.toCommunityModeratorView
413413
),
414414
...compat.toBlocks(site.my_user),
415415
}
@@ -455,11 +455,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
455455

456456
async listCommentReports(
457457
payload: Parameters<BaseClient["listCommentReports"]>[0],
458-
options?: RequestOptions,
458+
options?: RequestOptions
459459
): ReturnType<BaseClient["listCommentReports"]> {
460460
const response = await this.#client.listCommentReports(
461461
compat.fromPageParams(payload),
462-
options,
462+
options
463463
);
464464

465465
return {
@@ -470,16 +470,16 @@ export class UnsafeLemmyV0Client implements BaseClient {
470470

471471
async listCommunities(
472472
payload: Parameters<BaseClient["listCommunities"]>[0],
473-
options?: RequestOptions,
473+
options?: RequestOptions
474474
): ReturnType<BaseClient["listCommunities"]> {
475475
if (payload.mode && payload.mode !== "lemmyv0")
476476
throw new InvalidPayloadError(
477-
`Connected to lemmyv1, ${payload.mode} is not supported`,
477+
`Connected to lemmyv1, ${payload.mode} is not supported`
478478
);
479479

480480
const response = await this.#client.listCommunities(
481481
cleanThreadiverseParams(compat.fromPageParams(payload)),
482-
options,
482+
options
483483
);
484484

485485
return {
@@ -490,11 +490,14 @@ export class UnsafeLemmyV0Client implements BaseClient {
490490

491491
async listPersonContent(
492492
payload: Parameters<BaseClient["listPersonContent"]>[0],
493-
options?: RequestOptions,
493+
options?: RequestOptions
494494
): ReturnType<BaseClient["listPersonContent"]> {
495495
const response = await this.#client.getPersonDetails(
496-
compat.fromPageParams(payload),
497-
options,
496+
{
497+
...compat.fromPageParams(payload),
498+
sort: "New",
499+
},
500+
options
498501
);
499502

500503
const data = (() => {
@@ -507,7 +510,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
507510
].sort(
508511
(a, b) =>
509512
getPostCommentItemCreatedDate(b) -
510-
getPostCommentItemCreatedDate(a),
513+
getPostCommentItemCreatedDate(a)
511514
);
512515
case "Comments":
513516
return response.comments.map(compat.toCommentView);
@@ -524,7 +527,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
524527

525528
async listPersonLiked(
526529
{ type, ...payload }: Parameters<BaseClient["listPersonLiked"]>[0],
527-
options?: RequestOptions,
530+
options?: RequestOptions
528531
): Promise<ListPersonLikedResponse> {
529532
const v0Payload: LemmyV0.GetComments & LemmyV0.GetPosts = {
530533
...compat.fromPageParams(payload),
@@ -549,25 +552,25 @@ export class UnsafeLemmyV0Client implements BaseClient {
549552

550553
async listPersonSaved(
551554
payload: Parameters<BaseClient["listPersonSaved"]>[0],
552-
options?: RequestOptions,
555+
options?: RequestOptions
553556
): ReturnType<BaseClient["listPersonSaved"]> {
554557
return this.listPersonContent(
555558
{
556559
...payload,
557560
// @ts-expect-error Dogfood the api
558561
saved_only: true,
559562
},
560-
options,
563+
options
561564
);
562565
}
563566

564567
async listPostReports(
565568
payload: Parameters<BaseClient["listPostReports"]>[0],
566-
options?: RequestOptions,
569+
options?: RequestOptions
567570
): ReturnType<BaseClient["listPostReports"]> {
568571
const response = await this.#client.listPostReports(
569572
compat.fromPageParams(payload),
570-
options,
573+
options
571574
);
572575

573576
return {
@@ -578,7 +581,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
578581

579582
async listReports(
580583
payload: Parameters<BaseClient["listReports"]>[0],
581-
options?: RequestOptions,
584+
options?: RequestOptions
582585
): ReturnType<BaseClient["listReports"]> {
583586
const params = compat.fromPageParams(payload);
584587

@@ -594,7 +597,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
594597
...post_reports.map(compat.toPostReportView),
595598
].sort(
596599
(a, b) =>
597-
getPostCommentItemCreatedDate(b) - getPostCommentItemCreatedDate(a),
600+
getPostCommentItemCreatedDate(b) - getPostCommentItemCreatedDate(a)
598601
),
599602
};
600603
}
@@ -685,7 +688,7 @@ export class UnsafeLemmyV0Client implements BaseClient {
685688

686689
async resolveObject(
687690
payload: Parameters<BaseClient["resolveObject"]>[0],
688-
options?: RequestOptions,
691+
options?: RequestOptions
689692
): ReturnType<BaseClient["resolveObject"]> {
690693
const response = await this.#client.resolveObject(payload, options);
691694

@@ -735,16 +738,16 @@ export class UnsafeLemmyV0Client implements BaseClient {
735738

736739
async search(
737740
payload: Parameters<BaseClient["search"]>[0],
738-
options?: RequestOptions,
741+
options?: RequestOptions
739742
): ReturnType<BaseClient["search"]> {
740743
if (payload.mode && payload.mode !== "lemmyv0")
741744
throw new InvalidPayloadError(
742-
`Connected to lemmyv1, ${payload.mode} is not supported`,
745+
`Connected to lemmyv1, ${payload.mode} is not supported`
743746
);
744747

745748
const response = await this.#client.search(
746749
cleanThreadiverseParams(compat.fromPageParams(payload)),
747-
options,
750+
options
748751
);
749752

750753
return {
@@ -760,11 +763,11 @@ export class UnsafeLemmyV0Client implements BaseClient {
760763

761764
async uploadImage(
762765
payload: Parameters<BaseClient["uploadImage"]>[0],
763-
options?: RequestOptions,
766+
options?: RequestOptions
764767
): ReturnType<BaseClient["uploadImage"]> {
765768
const response = await this.#client.uploadImage(
766769
{ image: payload.file },
767-
options,
770+
options
768771
);
769772

770773
const fileResponse = response.files?.[0];

src/providers/piefed/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export class UnsafePiefedClient implements BaseClient {
952952
) {
953953
const response = await this.#client.GET("/api/alpha/comment/list", {
954954
...options,
955-
params: { query: compat.fromPageParams(payload) },
955+
params: { query: { ...compat.fromPageParams(payload), sort: "New" } },
956956
});
957957

958958
return {
@@ -967,7 +967,7 @@ export class UnsafePiefedClient implements BaseClient {
967967
) {
968968
const response = await this.#client.GET("/api/alpha/post/list", {
969969
...options,
970-
params: { query: compat.fromPageParams(payload) },
970+
params: { query: { ...compat.fromPageParams(payload), sort: "New" } },
971971
});
972972

973973
return {

0 commit comments

Comments
 (0)