mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-25 05:29:07 +01:00
Handle deleted antenna results correctly
This commit is contained in:
parent
aeddce2a60
commit
79471cf450
@ -2,12 +2,12 @@ import define from "../../define.js";
|
||||
import readNote from "@/services/note/read.js";
|
||||
import { Antennas, Notes } from "@/models/index.js";
|
||||
import { redisClient } from "@/db/redis.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
||||
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js";
|
||||
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
|
||||
import { Note } from "@/models/entities/note.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["antennas", "account", "notes"],
|
||||
@ -44,8 +44,8 @@ export const meta = {
|
||||
nullable: false,
|
||||
ref: "Note",
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
@ -65,32 +65,36 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
let pagination = ps.pagination || "+";
|
||||
|
||||
if (antenna == null) {
|
||||
throw new ApiError(meta.errors.noSuchAntenna);
|
||||
}
|
||||
|
||||
let notes: Note[] = [];
|
||||
let paginationMap: string[][] = [];
|
||||
|
||||
while (notes.length < ps.limit && pagination !== "-1") {
|
||||
// exclusive range
|
||||
if (pagination != "+" && !pagination.startsWith("("))
|
||||
pagination = `(${pagination}`;
|
||||
|
||||
const noteIdsRes = await redisClient.xrevrange(
|
||||
`antennaTimeline:${antenna.id}`,
|
||||
ps.pagination || "+",
|
||||
pagination,
|
||||
"-",
|
||||
"COUNT",
|
||||
ps.limit + 1,
|
||||
ps.limit - notes.length,
|
||||
);
|
||||
|
||||
if (noteIdsRes.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const noteIds = noteIdsRes
|
||||
.map((x) => x[1][1]);
|
||||
const noteIds = noteIdsRes.map((x) => x[1][1]);
|
||||
|
||||
if (noteIds.length === 0) {
|
||||
return {pagination: "", notes: []};
|
||||
pagination = "-1";
|
||||
break;
|
||||
}
|
||||
|
||||
const query = makePaginationQuery(
|
||||
Notes.createQueryBuilder("note")
|
||||
)
|
||||
const query = makePaginationQuery(Notes.createQueryBuilder("note"))
|
||||
.where("note.id IN (:...noteIds)", { noteIds: noteIds })
|
||||
.innerJoinAndSelect("note.user", "user")
|
||||
.leftJoinAndSelect("user.avatar", "avatar")
|
||||
@ -109,14 +113,30 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
generateMutedUserQuery(query, user);
|
||||
generateBlockedUserQuery(query, user);
|
||||
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
pagination = noteIdsRes[noteIdsRes.length - 1][0];
|
||||
paginationMap = paginationMap.concat(
|
||||
noteIdsRes.map((x) => [x[1][1], x[0]]),
|
||||
);
|
||||
notes = notes.concat(await query.take(ps.limit - notes.length).getMany());
|
||||
}
|
||||
|
||||
if (notes.length > 0) {
|
||||
if (notes.length === 0) {
|
||||
return { pagination: "-1", notes: [] };
|
||||
} else {
|
||||
readNote(user.id, notes);
|
||||
}
|
||||
|
||||
if (notes.length < ps.limit) {
|
||||
pagination = "-1";
|
||||
} else {
|
||||
// I'm so sorry, FIXME: rewrite pagination system
|
||||
pagination = paginationMap.find(
|
||||
(p) => p[0] == notes[notes.length - (notes.length > 1 ? 2 : 1)].id,
|
||||
)[1];
|
||||
}
|
||||
|
||||
return {
|
||||
pagination: noteIdsRes[noteIdsRes.length - 1][0],
|
||||
pagination: pagination,
|
||||
notes: await Notes.packMany(notes, user),
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user