movedTo(Uri), alsoKnownAsはユーザーidを返すように

This commit is contained in:
tamaina 2023-04-22 05:16:23 +00:00
parent eb4bca83fd
commit 3d88a91f61
7 changed files with 51 additions and 16 deletions

View file

@ -369,8 +369,11 @@ export class UserEntityService implements OnModuleInit {
...(opts.detail ? { ...(opts.detail ? {
url: profile!.url, url: profile!.url,
uri: user.uri, uri: user.uri,
movedToUri: user.movedToUri ? this.apPersonService.resolvePerson(user.movedToUri).then(user => user.uri).catch(() => null) : null, movedTo: user.movedToUri ? this.apPersonService.resolvePerson(user.movedToUri).then(user => user.id).catch(() => null) : null,
alsoKnownAs: user.alsoKnownAs, alsoKnownAs: user.alsoKnownAs
? Promise.all(user.alsoKnownAs.map(uri => this.apPersonService.fetchPerson(uri).then(user => user?.id).catch(() => null)))
.then(xs => xs.length === 0 ? null : xs.filter(x => x != null) as string[])
: null,
createdAt: user.createdAt.toISOString(), createdAt: user.createdAt.toISOString(),
updatedAt: user.updatedAt ? user.updatedAt.toISOString() : null, updatedAt: user.updatedAt ? user.updatedAt.toISOString() : null,
lastFetchedAt: user.lastFetchedAt ? user.lastFetchedAt.toISOString() : null, lastFetchedAt: user.lastFetchedAt ? user.lastFetchedAt.toISOString() : null,

View file

@ -80,9 +80,12 @@ export const packedUserDetailedNotMeOnlySchema = {
}, },
alsoKnownAs: { alsoKnownAs: {
type: 'array', type: 'array',
format: 'uri',
nullable: true, nullable: true,
optional: false, optional: false,
items: {
type: 'string',
format: 'id',
},
}, },
createdAt: { createdAt: {
type: 'string', type: 'string',

View file

@ -1,5 +1,5 @@
<template> <template>
<div :class="$style.root"> <div v-show="user" :class="$style.root">
<i class="ti ti-plane-departure" style="margin-right: 8px;"></i> <i class="ti ti-plane-departure" style="margin-right: 8px;"></i>
{{ i18n.ts.accountMoved }} {{ i18n.ts.accountMoved }}
<MkMention :class="$style.link" :username="username" :host="host ?? localHost"/> <MkMention :class="$style.link" :username="username" :host="host ?? localHost"/>
@ -10,11 +10,17 @@
import MkMention from './MkMention.vue'; import MkMention from './MkMention.vue';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { host as localHost } from '@/config'; import { host as localHost } from '@/config';
import { ref } from 'vue';
import { UserLite } from 'misskey-js/built/entities';
import { api } from '@/os';
defineProps<{ const user = ref<UserLite>();
username: string;
host: string; const props = defineProps<{
movedTo: string; // user id
}>(); }>();
api('users/show', { userId: props.movedTo }).then(u => user.value = u);
</script> </script>
<style lang="scss" module> <style lang="scss" module>

View file

@ -51,20 +51,40 @@ import MkFolder from '@/components/MkFolder.vue';
import * as os from '@/os'; import * as os from '@/os';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { $i } from '@/account';
import { toString } from 'misskey-js/built/acct';
import { unisonReload } from '@/scripts/unison-reload';
const moveToAccount = ref(''); const moveToAccount = ref('');
const accountAliases = ref(['']); const accountAliases = ref(['']);
async function init() {
if ($i?.movedTo) {
const movedTo = await os.api('users/show', { userId: $i.movedTo });
moveToAccount.value = movedTo ? toString(movedTo) : '';
} else {
moveToAccount.value = '';
}
if ($i?.alsoKnownAs && $i.alsoKnownAs.length > 0) {
const alsoKnownAs = await os.api('users/show', { userIds: $i.alsoKnownAs });
accountAliases.value = (alsoKnownAs && alsoKnownAs.length > 0) ? alsoKnownAs.map(user => `@${toString(user)}`) : [''];
} else {
accountAliases.value = [''];
}
}
async function move(): Promise<void> { async function move(): Promise<void> {
const account = moveToAccount.value; const account = moveToAccount.value;
const confirm = await os.confirm({ const confirm = await os.confirm({
type: 'warning', type: 'warning',
text: i18n.t('_accountMigration.migrationConfirm', { account: account.toString() }), text: i18n.t('_accountMigration.migrationConfirm', { account }),
}); });
if (confirm.canceled) return; if (confirm.canceled) return;
os.apiWithDialog('i/move', { await os.apiWithDialog('i/move', {
moveToAccount: account, moveToAccount: account,
}); });
unisonReload();
} }
function add(): void { function add(): void {
@ -73,12 +93,15 @@ function add(): void {
async function save(): Promise<void> { async function save(): Promise<void> {
const alsoKnownAs = accountAliases.value.map(alias => alias.trim()).filter(alias => alias !== ''); const alsoKnownAs = accountAliases.value.map(alias => alias.trim()).filter(alias => alias !== '');
os.apiWithDialog('i/update', { const i = await os.apiWithDialog('i/update', {
alsoKnownAs, alsoKnownAs,
}); });
accountAliases.value = alsoKnownAs.length === 0 ? [''] : alsoKnownAs; $i.alsoKnownAs = i.alsoKnownAs;
init();
} }
init();
definePageMetadata({ definePageMetadata({
title: i18n.ts.accountMigration, title: i18n.ts.accountMigration,
icon: 'ti ti-plane', icon: 'ti ti-plane',

View file

@ -7,7 +7,7 @@
<!-- <div class="punished" v-if="user.isSilenced"><i class="ti ti-alert-triangle" style="margin-right: 8px;"></i> {{ i18n.ts.userSilenced }}</div> --> <!-- <div class="punished" v-if="user.isSilenced"><i class="ti ti-alert-triangle" style="margin-right: 8px;"></i> {{ i18n.ts.userSilenced }}</div> -->
<div class="profile _gaps"> <div class="profile _gaps">
<MkAccountMoved v-if="user.movedToUri" :host="user.movedToUri.host" :username="user.movedToUri.username"/> <MkAccountMoved v-if="user.movedTo" :movedTo="user.movedTo" />
<MkRemoteCaution v-if="user.host != null" :href="user.url ?? user.uri!" class="warn"/> <MkRemoteCaution v-if="user.host != null" :href="user.url ?? user.uri!" class="warn"/>
<div :key="user.id" class="main _panel"> <div :key="user.id" class="main _panel">

View file

@ -2631,6 +2631,7 @@ type User = UserLite | UserDetailed;
// @public (undocumented) // @public (undocumented)
type UserDetailed = UserLite & { type UserDetailed = UserLite & {
alsoKnownAs: string[];
bannerBlurhash: string | null; bannerBlurhash: string | null;
bannerColor: string | null; bannerColor: string | null;
bannerUrl: string | null; bannerUrl: string | null;
@ -2661,7 +2662,7 @@ type UserDetailed = UserLite & {
lang: string | null; lang: string | null;
lastFetchedAt?: DateString; lastFetchedAt?: DateString;
location: string | null; location: string | null;
movedToUri: string; movedTo: string;
notesCount: number; notesCount: number;
pinnedNoteIds: ID[]; pinnedNoteIds: ID[];
pinnedNotes: Note[]; pinnedNotes: Note[];
@ -2695,7 +2696,6 @@ type UserLite = {
onlineStatus: 'online' | 'active' | 'offline' | 'unknown'; onlineStatus: 'online' | 'active' | 'offline' | 'unknown';
avatarUrl: string; avatarUrl: string;
avatarBlurhash: string; avatarBlurhash: string;
alsoKnownAs: string[];
emojis: { emojis: {
name: string; name: string;
url: string; url: string;

View file

@ -14,7 +14,6 @@ export type UserLite = {
onlineStatus: 'online' | 'active' | 'offline' | 'unknown'; onlineStatus: 'online' | 'active' | 'offline' | 'unknown';
avatarUrl: string; avatarUrl: string;
avatarBlurhash: string; avatarBlurhash: string;
alsoKnownAs: string[];
emojis: { emojis: {
name: string; name: string;
url: string; url: string;
@ -30,6 +29,7 @@ export type UserLite = {
}; };
export type UserDetailed = UserLite & { export type UserDetailed = UserLite & {
alsoKnownAs: string[];
bannerBlurhash: string | null; bannerBlurhash: string | null;
bannerColor: string | null; bannerColor: string | null;
bannerUrl: string | null; bannerUrl: string | null;
@ -57,7 +57,7 @@ export type UserDetailed = UserLite & {
lang: string | null; lang: string | null;
lastFetchedAt?: DateString; lastFetchedAt?: DateString;
location: string | null; location: string | null;
movedToUri: string; movedTo: string;
notesCount: number; notesCount: number;
pinnedNoteIds: ID[]; pinnedNoteIds: ID[];
pinnedNotes: Note[]; pinnedNotes: Note[];