mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-28 21:08:52 -07:00
[mastodon-client] Improve query filters for /accounts/:id/statuses
This commit is contained in:
parent
b1643cfee7
commit
19a990aebb
2 changed files with 23 additions and 9 deletions
|
@ -110,7 +110,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const cache = UserHelpers.getFreshAccountCache();
|
const cache = UserHelpers.getFreshAccountCache();
|
||||||
const query = await UserHelpers.getUserCached(userId, cache);
|
const query = await UserHelpers.getUserCached(userId, cache);
|
||||||
const args = normalizeUrlQuery(convertPaginationArgsIds(argsToBools(limitToInt(ctx.query))));
|
const args = normalizeUrlQuery(convertPaginationArgsIds(argsToBools(limitToInt(ctx.query))));
|
||||||
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)
|
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, cache));
|
.then(n => NoteConverter.encodeMany(n, user, cache));
|
||||||
|
|
||||||
ctx.body = tl.map(s => convertStatus(s));
|
ctx.body = tl.map(s => convertStatus(s));
|
||||||
|
|
|
@ -32,7 +32,7 @@ import { publishUserEvent } from "@/services/stream.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
import acceptFollowRequest from "@/services/following/requests/accept.js";
|
import acceptFollowRequest from "@/services/following/requests/accept.js";
|
||||||
import { rejectFollowRequest } from "@/services/following/reject.js";
|
import { rejectFollowRequest } from "@/services/following/reject.js";
|
||||||
import { IsNull } from "typeorm";
|
import { Brackets, IsNull } from "typeorm";
|
||||||
import { VisibilityConverter } from "@/server/api/mastodon/converters/visibility.js";
|
import { VisibilityConverter } from "@/server/api/mastodon/converters/visibility.js";
|
||||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||||
|
|
||||||
|
@ -300,15 +300,28 @@ export class UserHelpers {
|
||||||
)
|
)
|
||||||
.andWhere("note.userId = :userId", { userId: user.id });
|
.andWhere("note.userId = :userId", { userId: user.id });
|
||||||
|
|
||||||
if (excludeReblogs) query.andWhere("(note.renoteId IS NOT NULL) OR (note.text IS NOT NULL)");
|
if (excludeReblogs) {
|
||||||
|
query.andWhere(
|
||||||
|
new Brackets(qb => {
|
||||||
|
qb.where('note.renoteId IS NULL')
|
||||||
|
.orWhere('note.text IS NOT NULL');
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
query
|
if (excludeReplies) {
|
||||||
.leftJoinAndSelect("note.renote", "renote");
|
query.leftJoin("note", "thread", "note.threadId = thread.id")
|
||||||
|
.andWhere(
|
||||||
|
new Brackets(qb => {
|
||||||
|
qb.where("note.replyId IS NULL")
|
||||||
|
.orWhere(new Brackets(qb => {
|
||||||
|
qb.where('note.mentions = :mentions', {mentions: []})
|
||||||
|
.andWhere('thread.userId = :userId', {userId: user.id})
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
query.leftJoinAndSelect("note.renote", "renote");
|
||||||
|
|
||||||
//this doesn't exclude replies to your own reply to someone else's post
|
|
||||||
//this also breaks when checking your own profile
|
|
||||||
//FIXME write new the replies query generator specific to the mastodon client api
|
|
||||||
generateRepliesQuery(query, !excludeReplies, localUser);
|
|
||||||
generateVisibilityQuery(query, localUser);
|
generateVisibilityQuery(query, localUser);
|
||||||
if (localUser) {
|
if (localUser) {
|
||||||
generateMutedUserQuery(query, localUser, user);
|
generateMutedUserQuery(query, localUser, user);
|
||||||
|
@ -318,6 +331,7 @@ export class UserHelpers {
|
||||||
if (onlyMedia) query.andWhere("note.fileIds != '{}'");
|
if (onlyMedia) query.andWhere("note.fileIds != '{}'");
|
||||||
|
|
||||||
query.andWhere("note.visibility != 'hidden'");
|
query.andWhere("note.visibility != 'hidden'");
|
||||||
|
query.andWhere("note.visibility != 'specified'");
|
||||||
|
|
||||||
return PaginationHelpers.execQuery(query, limit, minId !== undefined);
|
return PaginationHelpers.execQuery(query, limit, minId !== undefined);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue