Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Oct 19, 2023
1 parent fe7ca1d commit 36ed8a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/backend/src/core/NoteUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class NoteUpdateService implements OnApplicationShutdown {
username: MiUser['username'];
host: MiUser['host'];
isBot: MiUser['isBot'];
}, data: Option, note: MiNote, silent = false): Promise<MiNote> {
}, data: Option, note: MiNote, silent = false): Promise<MiNote | null> {
if (data.updatedAt == null) data.updatedAt = new Date();

if (data.text) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class NoteUpdateService implements OnApplicationShutdown {

tags = tags.filter(tag => Array.from(tag ?? '').length <= 128).splice(0, 32);

const updatedNote = await this.updateNote(user, note, data, tags, emojis).then(updatedNote => updatedNote!)
const updatedNote = await this.updateNote(user, note, data, tags, emojis);

if (updatedNote) {
setImmediate('post updated', { signal: this.#shutdownController.signal }).then(
Expand All @@ -123,7 +123,9 @@ export class NoteUpdateService implements OnApplicationShutdown {
}

@bindThis
private async updateNote(user: { id: MiUser['id']; host: MiUser['host']; }, note: MiNote, data: Option, tags: string[], emojis: string[]) {
private async updateNote(user: {
id: MiUser['id']; host: MiUser['host'];
}, note: MiNote, data: Option, tags: string[], emojis: string[]): Promise<MiNote | null> {
const updatedAtHistory = note.updatedAtHistory ? note.updatedAtHistory : [];

const values = new MiNote({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class ApNoteService {
}

@bindThis
public async updateNote(value: string | IObject, resolver?: Resolver, silent = false): Promise<MiNote> {
public async updateNote(value: string | IObject, resolver?: Resolver, silent = false): Promise<MiNote | null> {
if (resolver == null) resolver = this.apResolverService.createResolver();

const object = await resolver.resolve(value);
Expand Down Expand Up @@ -435,6 +435,7 @@ export class ApNoteService {
}, b_note, silent);
} catch (err: any) {
this.logger.info('note update error');
return err;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/endpoints/notes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const updatedNote = await this.noteUpdateService.update(me, data, note, false);

return {
updatedNote: await this.noteEntityService.pack(updatedNote, me),
updatedNote: await this.noteEntityService.pack(updatedNote!, me),
};
});
}
Expand Down

0 comments on commit 36ed8a1

Please sign in to comment.