Fix move endpoint

This commit is contained in:
ThatOneCalculator 2022-12-11 18:18:07 -08:00
parent 70ddfb6a25
commit bc97bbe360
No known key found for this signature in database
GPG key ID: 8703CACD01000000
3 changed files with 22 additions and 21 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "calckey", "name": "calckey",
"version": "13.0.0-rc4", "version": "13.0.0-rc5",
"codename": "aqua", "codename": "aqua",
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -2,6 +2,7 @@ import type { User } from '@/models/entities/user.js';
import { resolveUser } from '@/remote/resolve-user.js'; import { resolveUser } from '@/remote/resolve-user.js';
import { DAY } from '@/const.js'; import { DAY } from '@/const.js';
import DeliverManager from '@/remote/activitypub/deliver-manager.js'; import DeliverManager from '@/remote/activitypub/deliver-manager.js';
import { deliver } from '@/queue/index.js';
import { renderActivity } from '@/remote/activitypub/renderer/index.js'; import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import type { IActivity } from '@/remote/activitypub/type.js'; import type { IActivity } from '@/remote/activitypub/type.js';
import define from '../../define.js'; import define from '../../define.js';
@ -51,6 +52,19 @@ export const paramDef = {
required: ['moveToAccount'], required: ['moveToAccount'],
} as const; } as const;
function moveActivity(to: User, from: User) {
const activity = {
id: 'foo',
actor: from,
type: 'Move',
object: from,
target: to,
} as any;
const content = renderActivity(activity);
deliver(to, content, from.inbox);
}
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => { export default define(meta, paramDef, async (ps, user) => {
if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchMoveTarget); if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchMoveTarget);
@ -75,23 +89,10 @@ export default define(meta, paramDef, async (ps, user) => {
if (!allowed || !moveTo.uri || !user.uri) throw new ApiError(meta.errors.remoteAccountForbids); if (!allowed || !moveTo.uri || !user.uri) throw new ApiError(meta.errors.remoteAccountForbids);
(async (): Promise<void> => { const moveAct = moveActivity(moveTo, user);
const moveAct = await moveActivity(moveTo.uri!, user.uri!);
const dm = new DeliverManager(user, moveAct); const dm = new DeliverManager(user, moveAct);
dm.addFollowersRecipe(); dm.addFollowersRecipe();
dm.execute(); dm.execute();
})();
return true; return true;
}); });
async function moveActivity(to: string, from: string): Promise<IActivity | null> {
const activity = {
id: 'foo',
actor: from,
type: 'Move',
object: from,
target: to,
} as any;
return renderActivity(activity);
}

View file

@ -49,7 +49,7 @@ async function move(account): Promise<void> {
text: i18n.t('migrationConfirm', { account: account.toString() }), text: i18n.t('migrationConfirm', { account: account.toString() }),
}); });
if (confirm.canceled) return; if (confirm.canceled) return;
os.api('i/move', { os.apiWithDialog('i/move', {
moveToAccount: account, moveToAccount: account,
}); });
} }