diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts index 6ca71c08e..744d07289 100644 --- a/packages/backend/src/server/api/endpoints/antennas/notes.ts +++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts @@ -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), + }; }); diff --git a/packages/client/src/components/MkPagination.vue b/packages/client/src/components/MkPagination.vue index 8c3cc9327..a49f8fe76 100644 --- a/packages/client/src/components/MkPagination.vue +++ b/packages/client/src/components/MkPagination.vue @@ -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 => { queue.value = []; fetching.value = true; @@ -156,6 +158,10 @@ const init = async (): Promise => { }) .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 => { ? 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 => { }) .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 => { ? 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 => { }) .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