summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2020-07-29 01:15:02 +0900
committersyuilo <syuilotan@yahoo.co.jp>2020-07-29 01:15:02 +0900
commit30df8ea1213013072f139aa26a635330457cf2bc (patch)
tree3edeeed1f53475f0ebc9e181295c6c91a90c9ca4 /src/client
parentfeat(client): プラグインを無効にできるように (diff)
downloadsharkey-30df8ea1213013072f139aa26a635330457cf2bc.tar.gz
sharkey-30df8ea1213013072f139aa26a635330457cf2bc.tar.bz2
sharkey-30df8ea1213013072f139aa26a635330457cf2bc.zip
feat(client): AiScript: ノート書き換えAPI
Diffstat (limited to 'src/client')
-rw-r--r--src/client/components/note.vue16
-rw-r--r--src/client/scripts/aiscript/api.ts3
-rw-r--r--src/client/store.ts9
3 files changed, 25 insertions, 3 deletions
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 @@
</div>
</div>
<article class="article">
- <mk-avatar class="avatar" :user="appearNote.user" v-once/>
+ <mk-avatar class="avatar" :user="appearNote.user"/>
<div class="main">
<x-note-header class="header" :note="appearNote" :mini="true"/>
<div class="body" ref="noteBody">
<p v-if="appearNote.cw != null" class="cw">
- <mfm v-if="appearNote.cw != ''" class="text" :text="appearNote.cw" :author="appearNote.user" :i="$store.state.i" :custom-emojis="appearNote.emojis" v-once/>
+ <mfm v-if="appearNote.cw != ''" class="text" :text="appearNote.cw" :author="appearNote.user" :i="$store.state.i" :custom-emojis="appearNote.emojis"/>
<x-cw-button v-model="showContent" :note="appearNote"/>
</p>
<div class="content" v-show="appearNote.cw == null || showContent">
<div class="text">
<span v-if="appearNote.isHidden" style="opacity: 0.5">({{ $t('private') }})</span>
<router-link class="reply" v-if="appearNote.replyId" :to="`/notes/${appearNote.replyId}`"><fa :icon="faReply"/></router-link>
- <mfm v-if="appearNote.text" :text="appearNote.text" :author="appearNote.user" :i="$store.state.i" :custom-emojis="appearNote.emojis" v-once/>
+ <mfm v-if="appearNote.text" :text="appearNote.text" :author="appearNote.user" :i="$store.state.i" :custom-emojis="appearNote.emojis"/>
<a class="rp" v-if="appearNote.renote != null">RN:</a>
</div>
<div class="files" v-if="appearNote.files.length > 0">
@@ -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: {