mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 03:43:08 +02:00
refactoring
This commit is contained in:
parent
e881e1bfb3
commit
0e6fbdfa5b
2 changed files with 9 additions and 9 deletions
|
@ -235,7 +235,7 @@ export class NoteRepository extends Repository<Note> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async packMany(
|
public async packMany(
|
||||||
notes: (Note['id'] | Note)[],
|
notes: Note[],
|
||||||
me?: User['id'] | User | null | undefined,
|
me?: User['id'] | User | null | undefined,
|
||||||
options?: {
|
options?: {
|
||||||
detail?: boolean;
|
detail?: boolean;
|
||||||
|
@ -245,11 +245,10 @@ export class NoteRepository extends Repository<Note> {
|
||||||
if (notes.length === 0) return [];
|
if (notes.length === 0) return [];
|
||||||
|
|
||||||
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
||||||
const noteIds = notes.map(n => typeof n === 'object' ? n.id : n);
|
|
||||||
const myReactionsMap = new Map<Note['id'], NoteReaction | null>();
|
const myReactionsMap = new Map<Note['id'], NoteReaction | null>();
|
||||||
if (meId) {
|
if (meId) {
|
||||||
const renoteIds = notes.filter(n => (typeof n === 'object') && (n.renoteId != null)).map(n => (n as Note).renoteId!);
|
const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);
|
||||||
const targets = [...noteIds, ...renoteIds];
|
const targets = [...notes.map(n => n.id), ...renoteIds];
|
||||||
const myReactions = await NoteReactions.find({
|
const myReactions = await NoteReactions.find({
|
||||||
userId: meId,
|
userId: meId,
|
||||||
noteId: In(targets),
|
noteId: In(targets),
|
||||||
|
|
|
@ -161,10 +161,11 @@ export class UserRepository extends Repository<User> {
|
||||||
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
||||||
|
|
||||||
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
|
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
|
||||||
const pins = opts.detail ? await UserNotePinings.find({
|
const pins = opts.detail ? await UserNotePinings.createQueryBuilder('pin')
|
||||||
where: { userId: user.id },
|
.where('pin.userId = :userId', { userId: user.id })
|
||||||
order: { id: 'DESC' }
|
.innerJoinAndSelect('pin.note', 'note')
|
||||||
}) : [];
|
.orderBy('id', 'DESC')
|
||||||
|
.getMany() : [];
|
||||||
const profile = opts.detail ? await UserProfiles.findOneOrFail(user.id) : null;
|
const profile = opts.detail ? await UserProfiles.findOneOrFail(user.id) : null;
|
||||||
|
|
||||||
const falsy = opts.detail ? false : undefined;
|
const falsy = opts.detail ? false : undefined;
|
||||||
|
@ -211,7 +212,7 @@ export class UserRepository extends Repository<User> {
|
||||||
followingCount: user.followingCount,
|
followingCount: user.followingCount,
|
||||||
notesCount: user.notesCount,
|
notesCount: user.notesCount,
|
||||||
pinnedNoteIds: pins.map(pin => pin.noteId),
|
pinnedNoteIds: pins.map(pin => pin.noteId),
|
||||||
pinnedNotes: Notes.packMany(pins.map(pin => pin.noteId), meId, {
|
pinnedNotes: Notes.packMany(pins.map(pin => pin.note!), meId, {
|
||||||
detail: true
|
detail: true
|
||||||
}),
|
}),
|
||||||
pinnedPageId: profile!.pinnedPageId,
|
pinnedPageId: profile!.pinnedPageId,
|
||||||
|
|
Loading…
Reference in a new issue