align ApNoteService updateNote with createNote

This commit is contained in:
dakkar 2024-08-30 13:33:42 +01:00
parent 8b8ee72a81
commit 0796d4bd62
2 changed files with 10 additions and 7 deletions

View file

@ -592,6 +592,9 @@ seems to do a decent job)
* copy all changes (commit after each step): * copy all changes (commit after each step):
* in `packages/backend/src/core/NoteCreateService.ts`, from `create` to * in `packages/backend/src/core/NoteCreateService.ts`, from `create` to
`import` (and vice versa if `git` got confused!) `import` (and vice versa if `git` got confused!)
* in
`packages/backend/src/core/activitypub/models/ApNoteService.ts`,
from `createNote` to `updateNote`
* from `packages/backend/src/core/NoteCreateService.ts` to * from `packages/backend/src/core/NoteCreateService.ts` to
`packages/backend/src/core/NoteEditService.vue` `packages/backend/src/core/NoteEditService.vue`
* in `packages/backend/src/core/activitypub/models/ApNoteService.ts`, * in `packages/backend/src/core/activitypub/models/ApNoteService.ts`,

View file

@ -358,7 +358,7 @@ export class ApNoteService {
value, value,
object, object,
}); });
throw new Error('invalid note'); throw err;
} }
const note = object as IPost; const note = object as IPost;
@ -471,19 +471,19 @@ export class ApNoteService {
| { status: 'ok'; res: MiNote } | { status: 'ok'; res: MiNote }
| { status: 'permerror' | 'temperror' } | { status: 'permerror' | 'temperror' }
> => { > => {
if (!/^https?:/.test(uri)) return { status: 'permerror' }; if (typeof uri !== 'string' || !/^https?:/.test(uri)) return { status: 'permerror' };
try { try {
const res = await this.resolveNote(uri, { resolver }); const res = await this.resolveNote(uri, { resolver });
if (res == null) return { status: 'permerror' }; if (res == null) return { status: 'permerror' };
return { status: 'ok', res }; return { status: 'ok', res };
} catch (e) { } catch (e) {
return { return {
status: (e instanceof StatusError && e.isClientError) ? 'permerror' : 'temperror', status: (e instanceof StatusError && !e.isRetryable) ? 'permerror' : 'temperror',
}; };
} }
}; };
const uris = unique([note._misskey_quote, note.quoteUrl, note.quoteUri].filter((x): x is string => typeof x === 'string')); const uris = unique([note._misskey_quote, note.quoteUrl, note.quoteUri].filter(x => x !== null));
const results = await Promise.all(uris.map(tryResolveNote)); const results = await Promise.all(uris.map(tryResolveNote));
quote = results.filter((x): x is { status: 'ok', res: MiNote } => x.status === 'ok').map(x => x.res).at(0); quote = results.filter((x): x is { status: 'ok', res: MiNote } => x.status === 'ok').map(x => x.res).at(0);
@ -496,10 +496,10 @@ export class ApNoteService {
// vote // vote
if (reply && reply.hasPoll) { if (reply && reply.hasPoll) {
const replyPoll = await this.pollsRepository.findOneByOrFail({ noteId: reply.id }); const poll = await this.pollsRepository.findOneByOrFail({ noteId: reply.id });
const tryCreateVote = async (name: string, index: number): Promise<null> => { const tryCreateVote = async (name: string, index: number): Promise<null> => {
if (replyPoll.expiresAt && Date.now() > new Date(replyPoll.expiresAt).getTime()) { if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
this.logger.warn(`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); this.logger.warn(`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`);
} else if (index >= 0) { } else if (index >= 0) {
this.logger.info(`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); this.logger.info(`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`);
@ -512,7 +512,7 @@ export class ApNoteService {
}; };
if (note.name) { if (note.name) {
return await tryCreateVote(note.name, replyPoll.choices.findIndex(x => x === note.name)); return await tryCreateVote(note.name, poll.choices.findIndex(x => x === note.name));
} }
} }