server: implement moveTo property on actors
Co-authored-by: Mary Strodl <ipadlover8322@gmail.com>
This commit is contained in:
parent
8ff6b5dd60
commit
3c7b7d4279
1 changed files with 24 additions and 3 deletions
|
@ -39,7 +39,7 @@ const summaryLength = 2048;
|
|||
* @param x Fetched object
|
||||
* @param uri Fetch target URI
|
||||
*/
|
||||
function validateActor(x: IObject): IActor {
|
||||
async function validateActor(x: IObject, resolver: Resolver): Promise<IActor> {
|
||||
if (x == null) {
|
||||
throw new Error('invalid Actor: object is null');
|
||||
}
|
||||
|
@ -61,6 +61,25 @@ function validateActor(x: IObject): IActor {
|
|||
throw new StatusError('cannot resolve local user', 400, 'cannot resolve local user');
|
||||
}
|
||||
|
||||
if (x.movedTo !== undefined) {
|
||||
if (!(typeof x.movedTo === 'string' && x.movedTo.length > 0)) {
|
||||
throw new Error('invalid Actor: wrong movedTo');
|
||||
}
|
||||
if (x.movedTo === uri) {
|
||||
throw new Error('invalid Actor: moved to self');
|
||||
}
|
||||
await resolvePerson(x.movedTo, resolver)
|
||||
.then(moveTarget => {
|
||||
x.movedTo = moveTarget.id
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
// Can't find the move target for some reason.
|
||||
// Don't treat the actor as invalid, just ignore the movedTo.
|
||||
logger.warn(`cannot find move target "${x.movedTo}", error: ${err.toString()}`);
|
||||
delete x.movedTo;
|
||||
});
|
||||
}
|
||||
|
||||
if (!(typeof x.inbox === 'string' && x.inbox.length > 0)) {
|
||||
throw new Error('invalid Actor: wrong inbox');
|
||||
}
|
||||
|
@ -137,7 +156,7 @@ export async function fetchPerson(uri: string): Promise<CacheableUser | null> {
|
|||
export async function createPerson(value: string | IObject, resolver: Resolver): Promise<User> {
|
||||
const object = await resolver.resolve(value) as any;
|
||||
|
||||
const person = validateActor(object);
|
||||
const person = await validateActor(object, resolver);
|
||||
|
||||
apLogger.info(`Creating the Person: ${person.id}`);
|
||||
|
||||
|
@ -177,6 +196,7 @@ export async function createPerson(value: string | IObject, resolver: Resolver):
|
|||
isBot,
|
||||
isCat: (person as any).isCat === true,
|
||||
showTimelineReplies: false,
|
||||
movedToId: person.movedTo,
|
||||
})) as IRemoteUser;
|
||||
|
||||
await transactionalEntityManager.save(new UserProfile({
|
||||
|
@ -287,7 +307,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
|||
|
||||
const object = await resolver.resolve(value);
|
||||
|
||||
const person = validateActor(object);
|
||||
const person = await validateActor(object, resolver);
|
||||
|
||||
apLogger.info(`Updating the Person: ${person.id}`);
|
||||
|
||||
|
@ -328,6 +348,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
|||
isCat: (person as any).isCat === true,
|
||||
isLocked: !!person.manuallyApprovesFollowers,
|
||||
isExplorable: !!person.discoverable,
|
||||
movedToId: person.movedTo,
|
||||
} as Partial<User>;
|
||||
|
||||
if (avatar) {
|
||||
|
|
Loading…
Reference in a new issue