[mastodon-client] Correctly return accounts' pinned posts

This commit is contained in:
Laura Hausmann 2023-09-29 17:10:15 +02:00
parent a0cf791e53
commit d4cca752ac
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -8,7 +8,7 @@ import {
NoteFavorites, NoteFavorites,
NoteReactions, NoteReactions,
Notes, Notes,
NoteWatchings, RegistryItems, NoteWatchings, RegistryItems, UserNotePinings,
UserProfiles, UserProfiles,
Users Users
} from "@/models/index.js"; } from "@/models/index.js";
@ -282,11 +282,6 @@ export class UserHelpers {
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[]> { 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 (limit > 40) limit = 40;
if (pinned) {
//FIXME respect pinned
return [];
}
if (tagged !== undefined) { if (tagged !== undefined) {
//FIXME respect tagged //FIXME respect tagged
return []; return [];
@ -298,7 +293,14 @@ export class UserHelpers {
maxId, maxId,
minId minId
) )
.andWhere("note.userId = :userId", { userId: user.id }); .andWhere("note.userId = :userId");
if (pinned) {
const sq = UserNotePinings.createQueryBuilder("pin")
.select("pin.noteId")
.where("pin.userId = :userId");
query.andWhere(`note.id IN (${sq.getQuery()})`);
}
if (excludeReblogs) { if (excludeReblogs) {
query.andWhere( query.andWhere(
@ -315,7 +317,7 @@ export class UserHelpers {
qb.where("note.replyId IS NULL") qb.where("note.replyId IS NULL")
.orWhere(new Brackets(qb => { .orWhere(new Brackets(qb => {
qb.where('note.mentions = :mentions', {mentions: []}) qb.where('note.mentions = :mentions', {mentions: []})
.andWhere('thread.userId = :userId', {userId: user.id}) .andWhere('thread.userId = :userId')
})); }));
})); }));
} }
@ -333,6 +335,8 @@ export class UserHelpers {
query.andWhere("note.visibility != 'hidden'"); query.andWhere("note.visibility != 'hidden'");
query.andWhere("note.visibility != 'specified'"); query.andWhere("note.visibility != 'specified'");
query.setParameters({ userId: user.id });
return PaginationHelpers.execQuery(query, limit, minId !== undefined); return PaginationHelpers.execQuery(query, limit, minId !== undefined);
} }