summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2020-07-29 23:37:50 +0900
committersyuilo <syuilotan@yahoo.co.jp>2020-07-29 23:37:50 +0900
commite7de5f60513774e9c599a2e3aac0fbeefb88236f (patch)
tree3412fa4ac5af01ed242febbc904bebe1744fffaf /src/client
parentfeat(client): AiScript: Plugin:open_url function (diff)
downloadmisskey-e7de5f60513774e9c599a2e3aac0fbeefb88236f.tar.gz
misskey-e7de5f60513774e9c599a2e3aac0fbeefb88236f.tar.bz2
misskey-e7de5f60513774e9c599a2e3aac0fbeefb88236f.zip
feat(client): Plugin:register_note_post_interruptor API
Diffstat (limited to 'src/client')
-rw-r--r--src/client/components/post-form.vue18
-rw-r--r--src/client/scripts/aiscript/api.ts3
-rw-r--r--src/client/store.ts9
3 files changed, 26 insertions, 4 deletions
diff --git a/src/client/components/post-form.vue b/src/client/components/post-form.vue
index f0de602c29..307501b78a 100644
--- a/src/client/components/post-form.vue
+++ b/src/client/components/post-form.vue
@@ -69,6 +69,7 @@ import getAcct from '../../misc/acct/render';
import { formatTimeString } from '../../misc/format-time-string';
import { selectDriveFile } from '../scripts/select-drive-file';
import { noteVisibilities } from '../../types';
+import { utils } from '@syuilo/aiscript';
export default Vue.extend({
components: {
@@ -533,9 +534,8 @@ export default Vue.extend({
localStorage.setItem('drafts', JSON.stringify(data));
},
- post() {
- this.posting = true;
- this.$root.api('notes/create', {
+ async post() {
+ let data = {
text: this.text == '' ? undefined : this.text,
fileIds: this.files.length > 0 ? this.files.map(f => f.id) : undefined,
replyId: this.reply ? this.reply.id : undefined,
@@ -546,7 +546,17 @@ export default Vue.extend({
visibility: this.visibility,
visibleUserIds: this.visibility == 'specified' ? this.visibleUsers.map(u => u.id) : undefined,
viaMobile: this.$root.isMobile
- }).then(data => {
+ };
+
+ // plugin
+ if (this.$store.state.notePostInterruptors.length > 0) {
+ for (const interruptor of this.$store.state.notePostInterruptors) {
+ data = utils.valToJs(await interruptor.handler(JSON.parse(JSON.stringify(data))));
+ }
+ }
+
+ this.posting = true;
+ this.$root.api('notes/create', data).then(() => {
this.clear();
this.deleteDraft();
this.$emit('posted');
diff --git a/src/client/scripts/aiscript/api.ts b/src/client/scripts/aiscript/api.ts
index f3ab6c372a..d9f311bde3 100644
--- a/src/client/scripts/aiscript/api.ts
+++ b/src/client/scripts/aiscript/api.ts
@@ -73,6 +73,9 @@ export function createPluginEnv(vm, opts) {
'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => {
vm.$store.commit('registerNoteViewInterruptor', { pluginId: opts.plugin.id, handler });
}),
+ 'Plugin:register_note_post_interruptor': values.FN_NATIVE(([handler]) => {
+ vm.$store.commit('registerNotePostInterruptor', { pluginId: opts.plugin.id, handler });
+ }),
'Plugin:open_url': values.FN_NATIVE(([url]) => {
window.open(url.value, '_blank');
}),
diff --git a/src/client/store.ts b/src/client/store.ts
index 7046e10f98..0e16115903 100644
--- a/src/client/store.ts
+++ b/src/client/store.ts
@@ -112,6 +112,7 @@ export default () => new Vuex.Store({
userActions: [],
noteActions: [],
noteViewInterruptors: [],
+ notePostInterruptors: [],
},
getters: {
@@ -283,6 +284,14 @@ export default () => new Vuex.Store({
}
});
},
+
+ registerNotePostInterruptor(state, { pluginId, handler }) {
+ state.notePostInterruptors.push({
+ handler: (note) => {
+ return state.pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(note)]);
+ }
+ });
+ },
},
actions: {