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

View File

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