merge: upstream

This commit is contained in:
Marie 2023-12-23 02:09:23 +01:00
commit 5db583a3eb
701 changed files with 50809 additions and 13660 deletions

View file

@ -19,7 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:renote="renote"
:initialVisibleUsers="visibleUsers"
class="_panel"
@posted="state = 'posted'"
@posted="onPosted"
/>
<div v-else-if="state === 'posted'" class="_buttonsCenter">
<MkButton primary @click="close">{{ i18n.ts.close }}</MkButton>
@ -30,43 +30,43 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
// SPECIFICATION: https://misskey-hub.net/docs/features/share-form.html
// SPECIFICATION: https://misskey-hub.net/docs/for-users/features/share-form/
import { } from 'vue';
import { ref, computed } from 'vue';
import * as Misskey from 'misskey-js';
import MkButton from '@/components/MkButton.vue';
import MkPostForm from '@/components/MkPostForm.vue';
import * as os from '@/os.js';
import { mainRouter } from '@/router.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { postMessageToParentWindow } from '@/scripts/post-message.js';
import { i18n } from '@/i18n.js';
const urlParams = new URLSearchParams(window.location.search);
const localOnlyQuery = urlParams.get('localOnly');
const visibilityQuery = urlParams.get('visibility') as typeof Misskey.noteVisibilities[number];
let state = $ref('fetching' as 'fetching' | 'writing' | 'posted');
let title = $ref(urlParams.get('title'));
const state = ref<'fetching' | 'writing' | 'posted'>('fetching');
const title = ref(urlParams.get('title'));
const text = urlParams.get('text');
const url = urlParams.get('url');
let initialText = $ref<string | undefined>();
let reply = $ref<Misskey.entities.Note | undefined>();
let renote = $ref<Misskey.entities.Note | undefined>();
let visibility = $ref(Misskey.noteVisibilities.includes(visibilityQuery) ? visibilityQuery : undefined);
let localOnly = $ref(localOnlyQuery === '0' ? false : localOnlyQuery === '1' ? true : undefined);
let files = $ref([] as Misskey.entities.DriveFile[]);
let visibleUsers = $ref([] as Misskey.entities.User[]);
const initialText = ref<string | undefined>();
const reply = ref<Misskey.entities.Note | undefined>();
const renote = ref<Misskey.entities.Note | undefined>();
const visibility = ref(Misskey.noteVisibilities.includes(visibilityQuery) ? visibilityQuery : undefined);
const localOnly = ref(localOnlyQuery === '0' ? false : localOnlyQuery === '1' ? true : undefined);
const files = ref([] as Misskey.entities.DriveFile[]);
const visibleUsers = ref([] as Misskey.entities.User[]);
async function init() {
let noteText = '';
if (title) noteText += `[ ${title} ]\n`;
if (title.value) noteText += `[ ${title.value} ]\n`;
// Google
if (text?.startsWith(`${title}.\n`)) noteText += text.replace(`${title}.\n`, '');
else if (text && title !== text) noteText += `${text}\n`;
if (text?.startsWith(`${title.value}.\n`)) noteText += text.replace(`${title.value}.\n`, '');
else if (text && title.value !== text) noteText += `${text}\n`;
if (url) noteText += `${url}`;
initialText = noteText.trim();
initialText.value = noteText.trim();
if (visibility === 'specified') {
if (visibility.value === 'specified') {
const visibleUserIds = urlParams.get('visibleUserIds');
const visibleAccts = urlParams.get('visibleAccts');
await Promise.all(
@ -78,7 +78,7 @@ async function init() {
.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 => {
visibleUsers.push(user);
visibleUsers.value.push(user);
}, () => {
console.error(`Invalid user query: ${JSON.stringify(q)}`);
}),
@ -91,7 +91,7 @@ async function init() {
const replyId = urlParams.get('replyId');
const replyUri = urlParams.get('replyUri');
if (replyId) {
reply = await os.api('notes/show', {
reply.value = await os.api('notes/show', {
noteId: replyId,
});
} else if (replyUri) {
@ -99,7 +99,7 @@ async function init() {
uri: replyUri,
});
if (obj.type === 'Note') {
reply = obj.object;
reply.value = obj.object;
}
}
//#endregion
@ -108,7 +108,7 @@ async function init() {
const renoteId = urlParams.get('renoteId');
const renoteUri = urlParams.get('renoteUri');
if (renoteId) {
renote = await os.api('notes/show', {
renote.value = await os.api('notes/show', {
noteId: renoteId,
});
} else if (renoteUri) {
@ -116,7 +116,7 @@ async function init() {
uri: renoteUri,
});
if (obj.type === 'Note') {
renote = obj.object;
renote.value = obj.object;
}
}
//#endregion
@ -128,7 +128,7 @@ async function init() {
fileIds.split(',')
.map(fileId => os.api('drive/files/show', { fileId })
.then(file => {
files.push(file);
files.value.push(file);
}, () => {
console.error(`Failed to fetch a file ${fileId}`);
}),
@ -144,7 +144,7 @@ async function init() {
});
}
state = 'writing';
state.value = 'writing';
}
init();
@ -162,9 +162,14 @@ function goToMisskey(): void {
location.href = '/';
}
const headerActions = $computed(() => []);
function onPosted(): void {
state.value = 'posted';
postMessageToParentWindow('misskey:shareForm:shareCompleted');
}
const headerTabs = $computed(() => []);
const headerActions = computed(() => []);
const headerTabs = computed(() => []);
definePageMetadata({
title: i18n.ts.share,