mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-30 15:58:05 +09:00
Fix antenna pagination
This commit is contained in:
parent
471d39da0b
commit
aeddce2a60
@ -25,15 +25,27 @@ export const meta = {
|
||||
},
|
||||
|
||||
res: {
|
||||
type: "array",
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Note",
|
||||
},
|
||||
properties: {
|
||||
pagination: {
|
||||
type: "string",
|
||||
nullable: false,
|
||||
optional: false,
|
||||
},
|
||||
notes: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Note",
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
} as const;
|
||||
|
||||
@ -42,10 +54,7 @@ export const paramDef = {
|
||||
properties: {
|
||||
antennaId: { type: "string", format: "misskey:id" },
|
||||
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
|
||||
sinceId: { type: "string", format: "misskey:id" },
|
||||
untilId: { type: "string", format: "misskey:id" },
|
||||
sinceDate: { type: "integer" },
|
||||
untilDate: { type: "integer" },
|
||||
pagination: { type: "string", default: "+" },
|
||||
},
|
||||
required: ["antennaId"],
|
||||
} as const;
|
||||
@ -62,30 +71,25 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
|
||||
const noteIdsRes = await redisClient.xrevrange(
|
||||
`antennaTimeline:${antenna.id}`,
|
||||
ps.untilDate || "+",
|
||||
ps.pagination || "+",
|
||||
"-",
|
||||
"COUNT",
|
||||
ps.limit + 1,
|
||||
); // untilIdに指定したものも含まれるため+1
|
||||
);
|
||||
|
||||
if (noteIdsRes.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const noteIds = noteIdsRes
|
||||
.map((x) => x[1][1])
|
||||
.filter((x) => x !== ps.untilId);
|
||||
.map((x) => x[1][1]);
|
||||
|
||||
if (noteIds.length === 0) {
|
||||
return [];
|
||||
return {pagination: "", notes: []};
|
||||
}
|
||||
|
||||
const query = makePaginationQuery(
|
||||
Notes.createQueryBuilder("note"),
|
||||
ps.sinceId,
|
||||
ps.untilId,
|
||||
ps.sinceDate,
|
||||
ps.untilDate,
|
||||
Notes.createQueryBuilder("note")
|
||||
)
|
||||
.where("note.id IN (:...noteIds)", { noteIds: noteIds })
|
||||
.innerJoinAndSelect("note.user", "user")
|
||||
@ -111,5 +115,8 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
readNote(user.id, notes);
|
||||
}
|
||||
|
||||
return await Notes.packMany(notes, user);
|
||||
return {
|
||||
pagination: noteIdsRes[noteIdsRes.length - 1][0],
|
||||
notes: await Notes.packMany(notes, user),
|
||||
};
|
||||
});
|
||||
|
@ -139,6 +139,8 @@ const isBackTop = ref(false);
|
||||
const empty = computed(() => items.value.length === 0);
|
||||
const error = ref(false);
|
||||
|
||||
let redisPaginationStr = ref("+");
|
||||
|
||||
const init = async (): Promise<void> => {
|
||||
queue.value = [];
|
||||
fetching.value = true;
|
||||
@ -156,6 +158,10 @@ const init = async (): Promise<void> => {
|
||||
})
|
||||
.then(
|
||||
(res) => {
|
||||
if (props.pagination.endpoint == 'antennas/notes') {
|
||||
redisPaginationStr = res.pagination;
|
||||
res = res.notes;
|
||||
}
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const item = res[i];
|
||||
if (props.pagination.reversed) {
|
||||
@ -251,6 +257,11 @@ const fetchMore = async (): Promise<void> => {
|
||||
? props.pagination.params.value
|
||||
: props.pagination.params
|
||||
: {};
|
||||
|
||||
if (props.pagination.endpoint == 'antennas/notes') {
|
||||
params.pagination = redisPaginationStr;
|
||||
}
|
||||
|
||||
await os
|
||||
.api(props.pagination.endpoint, {
|
||||
...params,
|
||||
@ -269,6 +280,11 @@ const fetchMore = async (): Promise<void> => {
|
||||
})
|
||||
.then(
|
||||
(res) => {
|
||||
if (props.pagination.endpoint == 'antennas/notes') {
|
||||
redisPaginationStr = res.pagination;
|
||||
res = res.notes;
|
||||
}
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const item = res[i];
|
||||
if (props.pagination.reversed) {
|
||||
@ -312,6 +328,11 @@ const fetchMoreAhead = async (): Promise<void> => {
|
||||
? props.pagination.params.value
|
||||
: props.pagination.params
|
||||
: {};
|
||||
|
||||
if (props.pagination.endpoint == 'antennas/notes') {
|
||||
params.pagination = redisPaginationStr;
|
||||
}
|
||||
|
||||
await os
|
||||
.api(props.pagination.endpoint, {
|
||||
...params,
|
||||
@ -330,6 +351,11 @@ const fetchMoreAhead = async (): Promise<void> => {
|
||||
})
|
||||
.then(
|
||||
(res) => {
|
||||
if (props.pagination.endpoint == 'antennas/notes') {
|
||||
redisPaginationStr = res.pagination;
|
||||
res = res.notes;
|
||||
}
|
||||
|
||||
if (res.length > SECOND_FETCH_LIMIT) {
|
||||
res.pop();
|
||||
items.value = props.pagination.reversed
|
||||
|
Loading…
Reference in New Issue
Block a user