This commit is contained in:
cutestnekoaqua 2022-12-09 01:17:31 +01:00
parent 7dd540bf43
commit 30597c747f
1 changed files with 18 additions and 18 deletions

View File

@ -7,6 +7,7 @@ import { Followings, Users } from '@/models/index.js';
import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js'; import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js';
import deleteFollowing from '@/services/following/delete.js'; import deleteFollowing from '@/services/following/delete.js';
import create from '@/services/following/create.js'; import create from '@/services/following/create.js';
import { getUser } from '../../common/getters.js';
import { IdentifiableError } from '@/misc/identifiable-error.js'; import { IdentifiableError } from '@/misc/identifiable-error.js';
import { ApiError } from '@/server/api/error.js'; import { ApiError } from '@/server/api/error.js';
import { meta } from '@/server/api/endpoints/following/create.js'; import { meta } from '@/server/api/endpoints/following/create.js';
@ -21,52 +22,51 @@ export default async (actor: CacheableRemoteUser, activity: IMove): Promise<stri
const resolver = new Resolver(); const resolver = new Resolver();
let new_acc = await dbResolver.getUserFromApId(activity.target); let new_acc = await dbResolver.getUserFromApId(activity.target);
let actor_new; let actor_new;
let actor_old;
if (!new_acc) actor_new = await resolver.resolve(<string>activity.target) as IActor; if (!new_acc) actor_new = await resolver.resolve(<string>activity.target) as IActor;
let old_acc = actor;
if (!old_acc) actor_old = await resolver.resolve(<string>activity.actor) as IActor;
if ((!new_acc || new_acc.uri === null) && (!actor_new || actor_new.id === null)) { if ((!new_acc || new_acc.uri === null) && (!actor_new || actor_new.id === null)) {
return 'move: new acc not found'; return 'move: new acc not found';
} }
if ((!old_acc || old_acc.uri === null) && (!actor_old || actor_old.id === null)) {
return 'move: old acc not found';
}
let newUri: string | null | undefined let newUri: string | null | undefined
let oldUri: string | null | undefined
newUri = new_acc ? new_acc.uri : newUri = new_acc ? new_acc.uri :
actor_new?.url?.toString(); actor_new?.url?.toString();
oldUri = old_acc ? old_acc.uri :
actor_old?.url?.toString();
if(newUri === null || newUri === undefined) return 'move: new acc not found #2'; if(newUri === null || newUri === undefined) return 'move: new acc not found #2';
if(oldUri === null || oldUri === undefined) return 'move: old acc not found #2';
await updatePerson(newUri); await updatePerson(newUri);
await updatePerson(oldUri); await updatePerson(actor.uri!);
new_acc = await dbResolver.getUserFromApId(newUri); new_acc = await dbResolver.getUserFromApId(newUri);
let old = await dbResolver.getUserFromApId(oldUri); let old = await dbResolver.getUserFromApId(actor.uri!);
if (old === null || old.uri === null || !new_acc?.alsoKnownAs?.includes(old.uri)) return 'move: accounts invalid'; if (old === null || old.uri === null || !new_acc?.alsoKnownAs?.includes(old.uri)) return 'move: accounts invalid';
old.movedToUri = new_acc.uri; old.movedToUri = new_acc.uri;
const followings = await Followings.createQueryBuilder('following').select('*') const followee = await getUser(actor.id).catch(e => {
.where('following.followeeId = :userId', { userId: old.id }) if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
throw e;
});
const followeeNew = await getUser(new_acc.id).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
throw e;
});
const followings = await Followings.createQueryBuilder('following')
.where('following.followeeId = :userId', { userId: followee })
.getMany(); .getMany();
console.log(followings); console.log(followings);
followings.forEach(async following => { followings.forEach(async following => {
//if follower is local
if (!following.follower?.host) { if (!following.follower?.host) {
const follower = following.follower; const follower = following.follower;
await deleteFollowing(follower!, old!); await deleteFollowing(follower!, followee);
try { try {
await create(follower!, new_acc!); await create(follower!, followeeNew);
} catch (e) { } catch (e) {
if (e instanceof IdentifiableError) { if (e instanceof IdentifiableError) {
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') return meta.errors.blocking; if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') return meta.errors.blocking;