mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 08:53:48 +01:00
[mastodon-client] Use execQueryLinkPagination in more places
This commit is contained in:
parent
fef807a165
commit
4717cc85b5
@ -1,6 +1,5 @@
|
|||||||
import { ILocalUser, User } from "@/models/entities/user.js";
|
import { ILocalUser, User } from "@/models/entities/user.js";
|
||||||
import { Blockings, UserListJoinings, UserLists, Users } from "@/models/index.js";
|
import { Blockings, UserListJoinings, UserLists, Users } from "@/models/index.js";
|
||||||
import { generatePaginationData } from "@/server/api/mastodon/middleware/pagination.js";
|
|
||||||
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
||||||
import { UserList } from "@/models/entities/user-list.js";
|
import { UserList } from "@/models/entities/user-list.js";
|
||||||
import { pushUserToUserList } from "@/services/user-list/push.js";
|
import { pushUserToUserList } from "@/services/user-list/push.js";
|
||||||
@ -52,14 +51,11 @@ export class ListHelpers {
|
|||||||
.andWhere("member.userListId = :listId", { listId: list.id })
|
.andWhere("member.userListId = :listId", { listId: list.id })
|
||||||
.innerJoinAndSelect("member.user", "user");
|
.innerJoinAndSelect("member.user", "user");
|
||||||
|
|
||||||
return query.take(limit).getMany().then(async p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(members => {
|
||||||
const users = p
|
return members
|
||||||
.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);
|
|
||||||
return users;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import { genId } from "@/misc/gen-id.js";
|
|||||||
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||||
import { generatePaginationData } from "@/server/api/mastodon/middleware/pagination.js"
|
|
||||||
import { addPinned, removePinned } from "@/services/i/pin.js";
|
import { addPinned, removePinned } from "@/services/i/pin.js";
|
||||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { awaitAll } from "@/prelude/await-all.js";
|
import { awaitAll } from "@/prelude/await-all.js";
|
||||||
@ -171,14 +170,11 @@ export class NoteHelpers {
|
|||||||
.andWhere("reaction.noteId = :noteId", { noteId: note.id })
|
.andWhere("reaction.noteId = :noteId", { noteId: note.id })
|
||||||
.innerJoinAndSelect("reaction.user", "user");
|
.innerJoinAndSelect("reaction.user", "user");
|
||||||
|
|
||||||
return query.take(limit).getMany().then(async p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(reactions => {
|
||||||
const users = p
|
return reactions
|
||||||
.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);
|
|
||||||
return users;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,14 +239,11 @@ export class NoteHelpers {
|
|||||||
|
|
||||||
generateVisibilityQuery(query, user);
|
generateVisibilityQuery(query, user);
|
||||||
|
|
||||||
return query.take(limit).getMany().then(async p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(renotes => {
|
||||||
const users = p
|
return renotes
|
||||||
.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);
|
|
||||||
return users;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ import { MediaHelpers } from "@/server/api/mastodon/helpers/media.js";
|
|||||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||||
import { verifyLink } from "@/services/fetch-rel-me.js";
|
import { verifyLink } from "@/services/fetch-rel-me.js";
|
||||||
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js";
|
||||||
import { generatePaginationData } from "@/server/api/mastodon/middleware/pagination.js";
|
|
||||||
import { MastoContext } from "@/server/api/mastodon/index.js";
|
import { MastoContext } from "@/server/api/mastodon/index.js";
|
||||||
|
|
||||||
export type AccountCache = {
|
export type AccountCache = {
|
||||||
@ -252,23 +251,20 @@ export class UserHelpers {
|
|||||||
query.andWhere("muting.muterId = :userId", { userId: user.id })
|
query.andWhere("muting.muterId = :userId", { userId: user.id })
|
||||||
.innerJoinAndSelect("muting.mutee", "mutee");
|
.innerJoinAndSelect("muting.mutee", "mutee");
|
||||||
|
|
||||||
return query.take(limit).getMany().then(async p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(async mutes => {
|
||||||
const users = p
|
const users = mutes
|
||||||
.map(p => p.mutee)
|
.map(p => p.mutee)
|
||||||
.filter(p => p) as User[];
|
.filter(p => p) as User[];
|
||||||
|
|
||||||
const result = await UserConverter.encodeMany(users, ctx)
|
return await UserConverter.encodeMany(users, ctx)
|
||||||
.then(res => res.map(m => {
|
.then(res => res.map(m => {
|
||||||
const muting = p.find(acc => acc.muteeId === m.id);
|
const muting = mutes.find(acc => acc.muteeId === m.id);
|
||||||
return {
|
return {
|
||||||
...m,
|
...m,
|
||||||
mute_expires_at: muting?.expiresAt?.toISOString() ?? null
|
mute_expires_at: muting?.expiresAt?.toISOString() ?? null
|
||||||
} as MastodonEntity.MutedAccount
|
} as MastodonEntity.MutedAccount
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
|
||||||
return result;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,14 +282,11 @@ export class UserHelpers {
|
|||||||
query.andWhere("blocking.blockerId = :userId", { userId: user.id })
|
query.andWhere("blocking.blockerId = :userId", { userId: user.id })
|
||||||
.innerJoinAndSelect("blocking.blockee", "blockee");
|
.innerJoinAndSelect("blocking.blockee", "blockee");
|
||||||
|
|
||||||
return query.take(limit).getMany().then(p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(blocks => {
|
||||||
const users = p
|
return blocks
|
||||||
.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);
|
|
||||||
return users;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,14 +304,11 @@ export class UserHelpers {
|
|||||||
query.andWhere("request.followeeId = :userId", { userId: user.id })
|
query.andWhere("request.followeeId = :userId", { userId: user.id })
|
||||||
.innerJoinAndSelect("request.follower", "follower");
|
.innerJoinAndSelect("request.follower", "follower");
|
||||||
|
|
||||||
return query.take(limit).getMany().then(p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(requests => {
|
||||||
const users = p
|
return requests
|
||||||
.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);
|
|
||||||
return users;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,11 +389,8 @@ export class UserHelpers {
|
|||||||
|
|
||||||
generateVisibilityQuery(query, localUser);
|
generateVisibilityQuery(query, localUser);
|
||||||
|
|
||||||
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
.then(res => {
|
.then(res => res.map(p => p.note as Note));
|
||||||
ctx.pagination = generatePaginationData(res.map(p => p.id), limit);
|
|
||||||
return res.map(p => p.note as Note);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getUserFavorites(maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20, ctx: MastoContext): Promise<Note[]> {
|
public static async getUserFavorites(maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20, ctx: MastoContext): Promise<Note[]> {
|
||||||
@ -421,11 +408,8 @@ export class UserHelpers {
|
|||||||
|
|
||||||
generateVisibilityQuery(query, localUser);
|
generateVisibilityQuery(query, localUser);
|
||||||
|
|
||||||
return PaginationHelpers.execQuery(query, limit, minId !== undefined)
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
.then(res => {
|
.then(res => res.map(p => p.note as Note));
|
||||||
ctx.pagination = generatePaginationData(res.map(p => p.id), limit);
|
|
||||||
return res.map(p => p.note as Note);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async getUserRelationships(type: RelationshipType, user: User, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40, ctx: MastoContext): Promise<User[]> {
|
private static async getUserRelationships(type: RelationshipType, user: User, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40, ctx: MastoContext): Promise<User[]> {
|
||||||
@ -463,12 +447,10 @@ export class UserHelpers {
|
|||||||
.innerJoinAndSelect("following.followee", "followee");
|
.innerJoinAndSelect("following.followee", "followee");
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.take(limit).getMany().then(p => {
|
return PaginationHelpers.execQueryLinkPagination(query, limit, minId !== undefined, ctx)
|
||||||
if (minId !== undefined) p = p.reverse();
|
.then(relations => relations
|
||||||
|
.map(p => type === "followers" ? p.follower : p.followee)
|
||||||
ctx.pagination = generatePaginationData(p.map(p => p.id), limit);
|
.filter(p => p) as User[]);
|
||||||
return p.map(p => type === "followers" ? p.follower : p.followee).filter(p => p) as User[];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getUserFollowers(user: User, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40, ctx: MastoContext): Promise<User[]> {
|
public static async getUserFollowers(user: User, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40, ctx: MastoContext): Promise<User[]> {
|
||||||
|
Loading…
Reference in New Issue
Block a user