[mastodon-client] Fix GET /accounts/:id/statuses

This commit is contained in:
Laura Hausmann 2023-09-15 22:37:32 +02:00
parent 81b08bebd0
commit 16c10f55a3
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 7 additions and 6 deletions

View File

@ -161,8 +161,9 @@ export function apiAccountMastodon(router: Router): void {
}
const userId = convertId(ctx.params.id, IdType.IceshrimpId);
const query = await getUser(userId);
const args = normalizeUrlQuery(convertTimelinesArgsId(argsToBools(limitToInt(ctx.query))));
const tl = await UserHelpers.getUserStatuses(userId, user, args.max_id, args.since_id, args.min_id, args.limit, args.only_media, args.exclude_replies, args.exclude_reblogs, args.pinned, args.tagged)
const tl = await UserHelpers.getUserStatuses(query, user, args.max_id, args.since_id, args.min_id, args.limit, args.only_media, args.exclude_replies, args.exclude_reblogs, args.pinned, args.tagged)
.then(n => NoteConverter.encodeMany(n, user));
ctx.body = tl.map(s => convertStatus(s));

View File

@ -1,4 +1,5 @@
import { Note } from "@/models/entities/note.js";
import { User } from "@/models/entities/user.js";
import { ILocalUser } from "@/models/entities/user.js";
import { Followings, Notes } from "@/models/index.js";
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
@ -16,7 +17,7 @@ import { meta } from "@/server/api/endpoints/notes/global-timeline.js";
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
export class UserHelpers {
public static async getUserStatuses(userId: string, localUser: ILocalUser | null, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20, onlyMedia: boolean = false, excludeReplies: boolean = false, excludeReblogs: boolean = false, pinned: boolean = false, tagged: string | undefined): Promise<Note[]> {
public static async getUserStatuses(user: User, localUser: ILocalUser | null, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20, onlyMedia: boolean = false, excludeReplies: boolean = false, excludeReblogs: boolean = false, pinned: boolean = false, tagged: string | undefined): Promise<Note[]> {
if (limit > 40) limit = 40;
if (pinned) {
@ -35,7 +36,7 @@ export class UserHelpers {
sinceId ?? minId,
maxId,
)
.andWhere("note.userId = :userId", { userId });
.andWhere("note.userId = :userId", { userId: user.id });
if (excludeReblogs) query.andWhere("(note.renoteId IS NOT NULL) OR (note.text IS NOT NULL)");
@ -52,13 +53,12 @@ export class UserHelpers {
.leftJoinAndSelect("renoteUser.avatar", "renoteUserAvatar")
.leftJoinAndSelect("renoteUser.banner", "renoteUserBanner");
//FIXME this doesn't exclude replies to your own reply to someone else's post
generateRepliesQuery(query, !excludeReplies, localUser);
generateVisibilityQuery(query, localUser);
if (localUser) {
generateMutedUserQuery(query, localUser);
generateMutedNoteQuery(query, localUser);
generateMutedUserQuery(query, localUser, user);
generateBlockedUserQuery(query, localUser);
generateMutedUserRenotesQueryForNotes(query, localUser);
}
if (onlyMedia) query.andWhere("note.fileIds != '{}'");