mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-04-29 01:56:58 +00:00
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/924 Closes #934 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
commit
d5bb83ac08
1 changed files with 29 additions and 2 deletions
|
@ -7,12 +7,14 @@ import ms from 'ms';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { MiNote, MiNoteSchedule, NoteScheduleRepository } from '@/models/_.js';
|
import type { MiNote, MiUser, MiNoteSchedule, NoteScheduleRepository, NotesRepository } from '@/models/_.js';
|
||||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||||
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
||||||
import { QueryService } from '@/core/QueryService.js';
|
import { QueryService } from '@/core/QueryService.js';
|
||||||
import { Packed } from '@/misc/json-schema.js';
|
import { Packed } from '@/misc/json-schema.js';
|
||||||
import { noteVisibilities } from '@/types.js';
|
import { noteVisibilities } from '@/types.js';
|
||||||
|
import { bindThis } from '@/decorators.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['notes'],
|
tags: ['notes'],
|
||||||
|
@ -81,7 +83,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
@Inject(DI.noteScheduleRepository)
|
@Inject(DI.noteScheduleRepository)
|
||||||
private noteScheduleRepository: NoteScheduleRepository,
|
private noteScheduleRepository: NoteScheduleRepository,
|
||||||
|
|
||||||
|
@Inject(DI.notesRepository)
|
||||||
|
private notesRepository: NotesRepository,
|
||||||
|
|
||||||
private userEntityService: UserEntityService,
|
private userEntityService: UserEntityService,
|
||||||
|
private noteEntityService: NoteEntityService,
|
||||||
private driveFileEntityService: DriveFileEntityService,
|
private driveFileEntityService: DriveFileEntityService,
|
||||||
private queryService: QueryService,
|
private queryService: QueryService,
|
||||||
) {
|
) {
|
||||||
|
@ -106,6 +112,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
userId: string;
|
userId: string;
|
||||||
scheduledAt: string;
|
scheduledAt: string;
|
||||||
}[] = await Promise.all(scheduleNotes.map(async (item: MiNoteSchedule) => {
|
}[] = await Promise.all(scheduleNotes.map(async (item: MiNoteSchedule) => {
|
||||||
|
const renote = await this.fetchNote(item.note.renote, me);
|
||||||
|
const reply = await this.fetchNote(item.note.reply, me);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
scheduledAt: item.scheduledAt.toISOString(),
|
scheduledAt: item.scheduledAt.toISOString(),
|
||||||
|
@ -115,12 +124,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
user: user,
|
user: user,
|
||||||
visibility: item.note.visibility ?? 'public',
|
visibility: item.note.visibility ?? 'public',
|
||||||
reactionAcceptance: item.note.reactionAcceptance ?? null,
|
reactionAcceptance: item.note.reactionAcceptance ?? null,
|
||||||
visibleUsers: item.note.visibleUsers ? await userEntityService.packMany(item.note.visibleUsers.map(u => u.id), me) : [],
|
visibleUsers: item.note.visibleUsers ? await this.userEntityService.packMany(item.note.visibleUsers.map(u => u.id), me) : [],
|
||||||
fileIds: item.note.files ? item.note.files : [],
|
fileIds: item.note.files ? item.note.files : [],
|
||||||
files: await this.driveFileEntityService.packManyByIds(item.note.files),
|
files: await this.driveFileEntityService.packManyByIds(item.note.files),
|
||||||
createdAt: item.scheduledAt.toISOString(),
|
createdAt: item.scheduledAt.toISOString(),
|
||||||
isSchedule: true,
|
isSchedule: true,
|
||||||
id: item.id,
|
id: item.id,
|
||||||
|
renote, reply,
|
||||||
|
renoteId: item.note.renote,
|
||||||
|
replyId: item.note.reply,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
@ -128,4 +140,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
return scheduleNotesPack;
|
return scheduleNotesPack;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
private async fetchNote(
|
||||||
|
id: MiNote['id'] | null | undefined,
|
||||||
|
me: MiUser,
|
||||||
|
): Promise<Packed<'Note'> | null> {
|
||||||
|
if (id) {
|
||||||
|
const note = await this.notesRepository.findOneBy({ id });
|
||||||
|
if (note) {
|
||||||
|
note.reactionAndUserPairCache ??= [];
|
||||||
|
return this.noteEntityService.pack(note, me);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue