mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-01 08:18:05 +09:00
[mastodon-client] Fix link pagination prev attribute when minId is set
This commit is contained in:
parent
3204bd9d18
commit
fef807a165
@ -58,7 +58,7 @@ export class ListHelpers {
|
|||||||
.map(p => p.user)
|
.map(p => p.user)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return users;
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ export class NoteHelpers {
|
|||||||
.map(p => p.user)
|
.map(p => p.user)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return users;
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ export class NoteHelpers {
|
|||||||
.map(p => p.user)
|
.map(p => p.user)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return users;
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ export class PaginationHelpers {
|
|||||||
const ids = p.map(x => x.id);
|
const ids = p.map(x => x.id);
|
||||||
ctx.pagination = p.length > 0 ? {
|
ctx.pagination = p.length > 0 ? {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
maxId: ids.at(reverse ? 0 : -1),
|
maxId: ids.at(-1),
|
||||||
minId: ids.at(reverse ? -1 : 0)
|
minId: ids.at(0)
|
||||||
} : undefined;
|
} : undefined;
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
|
@ -216,7 +216,7 @@ export class TimelineHelpers {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.threadId ?? p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.threadId ?? p.id), limit);
|
||||||
return Promise.all(conversations.map(c => awaitAll(c)));
|
return Promise.all(conversations.map(c => awaitAll(c)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ export class UserHelpers {
|
|||||||
} as MastodonEntity.MutedAccount
|
} as MastodonEntity.MutedAccount
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ export class UserHelpers {
|
|||||||
.map(p => p.blockee)
|
.map(p => p.blockee)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return users;
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -317,7 +317,7 @@ export class UserHelpers {
|
|||||||
.map(p => p.follower)
|
.map(p => p.follower)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return users;
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ export class UserHelpers {
|
|||||||
|
|
||||||
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
ctx.pagination = generatePaginationData(res.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(res.map(p => p.id), limit);
|
||||||
return res.map(p => p.note as Note);
|
return res.map(p => p.note as Note);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -423,7 +423,7 @@ export class UserHelpers {
|
|||||||
|
|
||||||
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
ctx.pagination = generatePaginationData(res.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(res.map(p => p.id), limit);
|
||||||
return res.map(p => p.note as Note);
|
return res.map(p => p.note as Note);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ export class UserHelpers {
|
|||||||
return query.take(limit).getMany().then(p => {
|
return query.take(limit).getMany().then(p => {
|
||||||
if (minId !== undefined) p = p.reverse();
|
if (minId !== undefined) p = p.reverse();
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined);
|
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
||||||
return p.map(p => type === "followers" ? p.follower : p.followee).filter(p => p) as User[];
|
return p.map(p => type === "followers" ? p.follower : p.followee).filter(p => p) as User[];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,12 @@ export async function PaginationMiddleware(ctx: MastoContext, next: () => Promis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generatePaginationData(ids: string[], limit: number, reverse: boolean): PaginationData | undefined {
|
export function generatePaginationData(ids: string[], limit: number): PaginationData | undefined {
|
||||||
if (ids.length < 1) return undefined;
|
if (ids.length < 1) return undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
maxId: ids.at(reverse ? 0 : -1),
|
maxId: ids.at(-1),
|
||||||
minId: ids.at(reverse ? -1 : 0)
|
minId: ids.at(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user