summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/aiscript
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-06-18 14:25:04 +0000
committerdakkar <dakkar@thenautilus.net>2024-06-18 14:25:04 +0000
commitb7805adc85653d8d789728dfaaa6a7e80d1440b8 (patch)
tree0109695430a1e604e68ddc2b7137f1fa7e354e4c /packages/frontend/src/scripts/aiscript
parentmerge: feat: add an option to collapse replies (!545) (diff)
parentmerge: merge up to 2024.5.0 (!537) (diff)
downloadsharkey-b7805adc85653d8d789728dfaaa6a7e80d1440b8.tar.gz
sharkey-b7805adc85653d8d789728dfaaa6a7e80d1440b8.tar.bz2
sharkey-b7805adc85653d8d789728dfaaa6a7e80d1440b8.zip
merge: prepare for 2024.5, 2nd try (!554)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/554 Closes #494 Approved-by: Tess K <me@thvxl.se> Approved-by: Marie <marie@kaifa.ch>
Diffstat (limited to 'packages/frontend/src/scripts/aiscript')
-rw-r--r--packages/frontend/src/scripts/aiscript/ui.ts62
1 files changed, 30 insertions, 32 deletions
diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts
index f2493264d3..fa3fcac2e7 100644
--- a/packages/frontend/src/scripts/aiscript/ui.ts
+++ b/packages/frontend/src/scripts/aiscript/ui.ts
@@ -6,6 +6,7 @@
import { utils, values } from '@syuilo/aiscript';
import { v4 as uuid } from 'uuid';
import { ref, Ref } from 'vue';
+import * as Misskey from 'misskey-js';
export type AsUiComponentBase = {
id: string;
@@ -115,23 +116,24 @@ export type AsUiFolder = AsUiComponentBase & {
opened?: boolean;
};
+type PostFormPropsForAsUi = {
+ text: string;
+ cw?: string;
+ visibility?: (typeof Misskey.noteVisibilities)[number];
+ localOnly?: boolean;
+};
+
export type AsUiPostFormButton = AsUiComponentBase & {
type: 'postFormButton';
text?: string;
primary?: boolean;
rounded?: boolean;
- form?: {
- text: string;
- cw?: string;
- };
+ form?: PostFormPropsForAsUi;
};
export type AsUiPostForm = AsUiComponentBase & {
type: 'postForm';
- form?: {
- text: string;
- cw?: string;
- };
+ form?: PostFormPropsForAsUi;
};
export type AsUiComponent = AsUiRoot | AsUiContainer | AsUiText | AsUiMfm | AsUiButton | AsUiButtons | AsUiSwitch | AsUiTextarea | AsUiTextInput | AsUiNumberInput | AsUiSelect | AsUiFolder | AsUiPostFormButton | AsUiPostForm;
@@ -447,6 +449,24 @@ function getFolderOptions(def: values.Value | undefined): Omit<AsUiFolder, 'id'
};
}
+function getPostFormProps(form: values.VObj): PostFormPropsForAsUi {
+ const text = form.value.get('text');
+ utils.assertString(text);
+ const cw = form.value.get('cw');
+ if (cw) utils.assertString(cw);
+ const visibility = form.value.get('visibility');
+ if (visibility) utils.assertString(visibility);
+ const localOnly = form.value.get('localOnly');
+ if (localOnly) utils.assertBoolean(localOnly);
+
+ return {
+ text: text.value,
+ cw: cw?.value,
+ visibility: (visibility?.value && (Misskey.noteVisibilities as readonly string[]).includes(visibility.value)) ? visibility.value as typeof Misskey.noteVisibilities[number] : undefined,
+ localOnly: localOnly?.value,
+ };
+}
+
function getPostFormButtonOptions(def: values.Value | undefined, call: (fn: values.VFn, args: values.Value[]) => Promise<values.Value>): Omit<AsUiPostFormButton, 'id' | 'type'> {
utils.assertObject(def);
@@ -459,22 +479,11 @@ function getPostFormButtonOptions(def: values.Value | undefined, call: (fn: valu
const form = def.value.get('form');
if (form) utils.assertObject(form);
- const getForm = () => {
- const text = form!.value.get('text');
- utils.assertString(text);
- const cw = form!.value.get('cw');
- if (cw) utils.assertString(cw);
- return {
- text: text.value,
- cw: cw?.value,
- };
- };
-
return {
text: text?.value,
primary: primary?.value,
rounded: rounded?.value,
- form: form ? getForm() : {
+ form: form ? getPostFormProps(form) : {
text: '',
},
};
@@ -486,19 +495,8 @@ function getPostFormOptions(def: values.Value | undefined, call: (fn: values.VFn
const form = def.value.get('form');
if (form) utils.assertObject(form);
- const getForm = () => {
- const text = form!.value.get('text');
- utils.assertString(text);
- const cw = form!.value.get('cw');
- if (cw) utils.assertString(cw);
- return {
- text: text.value,
- cw: cw?.value,
- };
- };
-
return {
- form: form ? getForm() : {
+ form: form ? getPostFormProps(form) : {
text: '',
},
};