From 64397708fdd706d28918cee8859c68ab8ed925c8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 6 Jul 2019 18:14:50 +0900 Subject: [PATCH] =?UTF-8?q?MisskeyPages=E3=81=AB=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E9=80=81=E4=BF=A1=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 4 ++ .../page-editor/els/page-editor.el.button.vue | 11 ++++- .../common/views/pages/page/page.button.vue | 10 +++++ .../app/common/views/pages/page/page.vue | 6 ++- src/server/api/endpoints/page-push.ts | 44 +++++++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/server/api/endpoints/page-push.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 15cb30997..9726d49c2 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2030,6 +2030,10 @@ pages: _dialog: content: "内容" resetRandom: "乱数をリセット" + pushEvent: "イベントを送信させる" + _pushEvent: + event: "イベント名" + message: "押したときに表示するメッセージ" script: categories: diff --git a/src/client/app/common/views/pages/page-editor/els/page-editor.el.button.vue b/src/client/app/common/views/pages/page-editor/els/page-editor.el.button.vue index f89279f05..579de6a8f 100644 --- a/src/client/app/common/views/pages/page-editor/els/page-editor.el.button.vue +++ b/src/client/app/common/views/pages/page-editor/els/page-editor.el.button.vue @@ -8,8 +8,15 @@ + - {{ $t('blocks._button._action._dialog.content') }} + + @@ -43,6 +50,8 @@ export default Vue.extend({ if (this.value.text == null) Vue.set(this.value, 'text', ''); if (this.value.action == null) Vue.set(this.value, 'action', 'dialog'); if (this.value.content == null) Vue.set(this.value, 'content', null); + if (this.value.event == null) Vue.set(this.value, 'event', null); + if (this.value.message == null) Vue.set(this.value, 'message', null); }, }); diff --git a/src/client/app/common/views/pages/page/page.button.vue b/src/client/app/common/views/pages/page/page.button.vue index 3747be96c..9f760bf48 100644 --- a/src/client/app/common/views/pages/page/page.button.vue +++ b/src/client/app/common/views/pages/page/page.button.vue @@ -27,6 +27,16 @@ export default Vue.extend({ } else if (this.value.action === 'resetRandom') { this.script.aiScript.updateRandomSeed(Math.random()); this.script.eval(); + } else if (this.value.action === 'pushEvent') { + this.$root.api('page-push', { + pageId: this.script.page.id, + event: this.value.event + }); + + this.$root.dialog({ + type: 'success', + text: this.script.interpolate(this.value.message) + }); } } } diff --git a/src/client/app/common/views/pages/page/page.vue b/src/client/app/common/views/pages/page/page.vue index 96a2cfafb..a93d5316d 100644 --- a/src/client/app/common/views/pages/page/page.vue +++ b/src/client/app/common/views/pages/page/page.vue @@ -35,8 +35,10 @@ class Script { public aiScript: ASEvaluator; private onError: any; public vars: Record; + public page: Record; - constructor(aiScript, onError) { + constructor(page, aiScript, onError) { + this.page = page; this.aiScript = aiScript; this.onError = onError; this.eval(); @@ -113,7 +115,7 @@ export default Vue.extend({ icon: faStickyNote }); const pageVars = this.getPageVars(); - this.script = new Script(new ASEvaluator(this.page.variables, pageVars, { + this.script = new Script(this.page, new ASEvaluator(this.page.variables, pageVars, { randomSeed: Math.random(), user: page.user, visitor: this.$store.state.i, diff --git a/src/server/api/endpoints/page-push.ts b/src/server/api/endpoints/page-push.ts new file mode 100644 index 000000000..300df7c25 --- /dev/null +++ b/src/server/api/endpoints/page-push.ts @@ -0,0 +1,44 @@ +import $ from 'cafy'; +import define from '../define'; +import { ID } from '../../../misc/cafy-id'; +import { publishMainStream } from '../../../services/stream'; +import { Users, Pages } from '../../../models'; +import { ApiError } from '../error'; + +export const meta = { + requireCredential: true, + secure: true, + + params: { + pageId: { + validator: $.type(ID) + }, + + event: { + validator: $.str + } + }, + + errors: { + noSuchPage: { + message: 'No such page.', + code: 'NO_SUCH_PAGE', + id: '4a13ad31-6729-46b4-b9af-e86b265c2e74' + } + } +}; + +export default define(meta, async (ps, user) => { + const page = await Pages.findOne(ps.pageId); + if (page == null) { + throw new ApiError(meta.errors.noSuchPage); + } + + publishMainStream(user.id, 'pageEvent', { + pageId: ps.pageId, + event: ps.event, + user: await Users.pack(user, page.userId, { + detail: true + }) + }); +});