From 30df8ea1213013072f139aa26a635330457cf2bc Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 29 Jul 2020 01:15:02 +0900 Subject: feat(client): AiScript: ノート書き換えAPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/components/note.vue | 16 +++++++++++++--- src/client/scripts/aiscript/api.ts | 3 +++ src/client/store.ts | 9 +++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/client') diff --git a/src/client/components/note.vue b/src/client/components/note.vue index c3a199a805..a359287b41 100644 --- a/src/client/components/note.vue +++ b/src/client/components/note.vue @@ -35,19 +35,19 @@
- +

- +

({{ $t('private') }}) - + RN:
@@ -114,6 +114,7 @@ import { focusPrev, focusNext } from '../scripts/focus'; import { url } from '../config'; import copyToClipboard from '../scripts/copy-to-clipboard'; import { checkWordMute } from '../scripts/check-word-mute'; +import { utils } from '@syuilo/aiscript'; export default Vue.extend({ model: { @@ -246,6 +247,15 @@ export default Vue.extend({ this.connection = this.$root.stream; } + // plugin + if (this.$store.state.noteViewInterruptors.length > 0) { + let result = this.note; + for (const interruptor of this.$store.state.noteViewInterruptors) { + result = utils.valToJs(await interruptor.handler(JSON.parse(JSON.stringify(result)))); + } + this.$emit('updated', Object.freeze(result)); + } + this.muted = await checkWordMute(this.appearNote, this.$store.state.i, this.$store.state.settings.mutedWords); if (this.detail) { diff --git a/src/client/scripts/aiscript/api.ts b/src/client/scripts/aiscript/api.ts index bfbfe8d59d..90418fc5ca 100644 --- a/src/client/scripts/aiscript/api.ts +++ b/src/client/scripts/aiscript/api.ts @@ -70,6 +70,9 @@ export function createPluginEnv(vm, opts) { 'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => { vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler }); }), + 'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => { + vm.$store.commit('registerNoteViewInterruptor', { pluginId: opts.plugin.id, handler }); + }), 'Plugin:config': values.OBJ(config), }; } diff --git a/src/client/store.ts b/src/client/store.ts index 67dd6ea06a..7046e10f98 100644 --- a/src/client/store.ts +++ b/src/client/store.ts @@ -111,6 +111,7 @@ export default () => new Vuex.Store({ postFormActions: [], userActions: [], noteActions: [], + noteViewInterruptors: [], }, getters: { @@ -274,6 +275,14 @@ export default () => new Vuex.Store({ } }); }, + + registerNoteViewInterruptor(state, { pluginId, handler }) { + state.noteViewInterruptors.push({ + handler: (note) => { + return state.pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(note)]); + } + }); + }, }, actions: { -- cgit v1.2.3-freya