This commit is contained in:
tamaina 2021-09-05 00:27:58 +09:00
parent aab5f260ab
commit 885c0fae9a
2 changed files with 31 additions and 16 deletions

View file

@ -32,6 +32,7 @@ import * as os from '@client/os';
import { noteVisibilities } from '@/types';
import { parseAcct } from '@/misc/acct';
import * as symbols from '@client/symbols';
import * as Misskey from 'misskey-js';
export default defineComponent({
components: {
@ -53,9 +54,8 @@ export default defineComponent({
renote: null as any,
visibility: null as string | null,
localOnly: null as boolean | null,
files: null as any[] | null,
visibleUsers: [] as any[],
files: [] as Misskey.entities.DriveFile[],
visibleUsers: [] as Misskey.entities.User[],
}
},
@ -82,11 +82,21 @@ export default defineComponent({
if (this.visibility === 'specified') {
const visibleUserIds = urlParams.get('visibleUserIds');
const visibleAccts = urlParams.get('visibleAccts');
this.visibleUsers = await Promise.all([
...(visibleUserIds ? visibleUserIds.split(',').map(userId => ({ userId })) : []),
...(visibleAccts ? visibleAccts.split(',').map(parseAcct) : [])
].map(q => os.api('users/show', q)
.catch(() => console.error(`invalid user query: ${JSON.stringify(q)}`))));
await Promise.all(
[
...(visibleUserIds ? visibleUserIds.split(',').map(userId => ({ userId })) : []),
...(visibleAccts ? visibleAccts.split(',').map(parseAcct) : [])
]
// TypeScript
.map(q => 'username' in q ? { username: q.username, host: q.host === null ? undefined : q.host } : q)
.map(q => os.api('users/show', q)
.then(user => {
this.visibleUsers.push(user);
}, () => {
console.error(`Invalid user query: ${JSON.stringify(q)}`);
})
)
);
}
const localOnly = urlParams.get('localOnly');
@ -131,8 +141,16 @@ export default defineComponent({
//#region Drive files
const fileIds = urlParams.get('fileIds');
if (fileIds) {
const promises = fileIds.split(',').map(fileId => os.api('drive/files/show', { fileId }).catch(() => console.error(`invalid fileId: ${fileId}`)));
await Promise.all(promises).then(files => this.files = files);
await Promise.all(
fileIds.split(',')
.map(fileId => os.api('drive/files/show', { fileId })
.then(file => {
this.files.push(file);
}, () => {
console.error(`Failed to fetch a file ${fileId}`);
})
)
);
}
//#endregion
} catch (e) {

View file

@ -1,13 +1,10 @@
export type Acct = {
username: string;
host: string | null;
};
import * as Misskey from 'misskey-js';
export const getAcct = (user: Acct) => {
export const getAcct = (user: Misskey.Acct) => {
return user.host == null ? user.username : `${user.username}@${user.host}`;
};
export const parseAcct = (acct: string): Acct => {
export const parseAcct = (acct: string): Misskey.Acct => {
if (acct.startsWith('@')) acct = acct.substr(1);
const split = acct.split('@', 2);
return { username: split[0], host: split[1] || null };