allow Update(Note) and Update(Poll) to implicitly create missing notes
This commit is contained in:
parent
2bbccde2ce
commit
9d3321fca4
|
@ -388,7 +388,7 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async create(actor: MiRemoteUser, activity: ICreate, resolver?: Resolver): Promise<string | void> {
|
private async create(actor: MiRemoteUser, activity: ICreate | IUpdate, resolver?: Resolver): Promise<string | void> {
|
||||||
const uri = getApId(activity);
|
const uri = getApId(activity);
|
||||||
|
|
||||||
this.logger.info(`Create: ${uri}`);
|
this.logger.info(`Create: ${uri}`);
|
||||||
|
@ -423,14 +423,14 @@ export class ApInboxService {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isPost(object)) {
|
if (isPost(object)) {
|
||||||
await this.createNote(resolver, actor, object, false, activity);
|
await this.createNote(resolver, actor, object, false);
|
||||||
} else {
|
} else {
|
||||||
return `Unknown type: ${getApType(object)}`;
|
return `Unknown type: ${getApType(object)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async createNote(resolver: Resolver, actor: MiRemoteUser, note: IObject, silent = false, activity?: ICreate): Promise<string> {
|
private async createNote(resolver: Resolver, actor: MiRemoteUser, note: IObject, silent = false): Promise<string> {
|
||||||
const uri = getApId(note);
|
const uri = getApId(note);
|
||||||
|
|
||||||
if (typeof note === 'object') {
|
if (typeof note === 'object') {
|
||||||
|
@ -789,7 +789,7 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async update(actor: MiRemoteUser, activity: IUpdate, resolver?: Resolver): Promise<string> {
|
private async update(actor: MiRemoteUser, activity: IUpdate, resolver?: Resolver): Promise<string | void> {
|
||||||
if (actor.uri !== activity.actor) {
|
if (actor.uri !== activity.actor) {
|
||||||
return 'skip: invalid actor';
|
return 'skip: invalid actor';
|
||||||
}
|
}
|
||||||
|
@ -808,9 +808,19 @@ export class ApInboxService {
|
||||||
await this.apPersonService.updatePerson(actor.uri, resolver, object);
|
await this.apPersonService.updatePerson(actor.uri, resolver, object);
|
||||||
return 'ok: Person updated';
|
return 'ok: Person updated';
|
||||||
} else if (getApType(object) === 'Question') {
|
} else if (getApType(object) === 'Question') {
|
||||||
|
// If we get an Update(Question) for a note that doesn't exist, then create it instead
|
||||||
|
if (!await this.apNoteService.hasNote(object)) {
|
||||||
|
return await this.create(actor, activity, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
await this.apQuestionService.updateQuestion(object, actor, resolver).catch(err => console.error(err));
|
await this.apQuestionService.updateQuestion(object, actor, resolver).catch(err => console.error(err));
|
||||||
return 'ok: Question updated';
|
return 'ok: Question updated';
|
||||||
} else if (isPost(object)) {
|
} else if (isPost(object)) {
|
||||||
|
// If we get an Update(Note) for a note that doesn't exist, then create it instead
|
||||||
|
if (!await this.apNoteService.hasNote(object)) {
|
||||||
|
return await this.create(actor, activity, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
await this.apNoteService.updateNote(object, actor, resolver).catch(err => console.error(err));
|
await this.apNoteService.updateNote(object, actor, resolver).catch(err => console.error(err));
|
||||||
return 'ok: Note updated';
|
return 'ok: Note updated';
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -142,6 +142,15 @@ export class ApNoteService {
|
||||||
return await this.apDbResolverService.getNoteFromApId(object);
|
return await this.apDbResolverService.getNoteFromApId(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the provided object / ID exists in the local database.
|
||||||
|
*/
|
||||||
|
@bindThis
|
||||||
|
public async hasNote(object: string | IObject | [string | IObject]): Promise<boolean> {
|
||||||
|
const uri = getApId(object);
|
||||||
|
return await this.notesRepository.existsBy({ uri });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Noteを作成します。
|
* Noteを作成します。
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue