From b7fc5a31b56002b0e5f3545e896b255726dcc6a8 Mon Sep 17 00:00:00 2001 From: Xeltica Date: Sun, 1 Sep 2019 11:26:01 +0900 Subject: [PATCH] resolve #51 and #52 --- locales/en-US.yml | 2 ++ locales/ja-JP.yml | 2 ++ src/client/app/common/scripts/note-mixin.ts | 1 + .../app/common/scripts/note-subscriber.ts | 29 ++++++++++++++----- .../app/common/views/components/note-menu.vue | 29 +++++++++++++++++-- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 934c54b14b..238dcf38f3 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -596,6 +596,8 @@ common/views/components/note-menu.vue: delete-confirm: "Are you sure you want to delete this post?" deleteAsAdmin: "Delete as admin" deleteAsAdmin-confirm: "Are you sure you want to delete using administrator privileges?" + undo-renote: "Undo Renote" + undo-renote-confirm: "Are you sure you want to undo this renote?" delete-and-edit: "Delete and Edit" delete-and-edit-confirm: "Are you sure you want to delete this note and edit it? You will lose all reactions, renotes and replies to it." remote: "Show original note" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index d5c2ebba82..829e42c725 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -637,6 +637,8 @@ common/views/components/note-menu.vue: delete-confirm: "この投稿を削除しますか?" deleteAsAdmin: "管理者として削除" deleteAsAdmin-confirm: "管理者権限を行使してこの投稿を削除しますか?" + undo-renote: "リノートを取り消す" + undo-renote-confirm: "このリノートを取り消しますか?" delete-and-edit: "削除して編集" delete-and-edit-confirm: "この投稿を削除してもう一度編集しますか?この投稿へのリアクション、Renote、返信も全て削除されます。" remote: "投稿元で見る" diff --git a/src/client/app/common/scripts/note-mixin.ts b/src/client/app/common/scripts/note-mixin.ts index 2e4f9a24d0..f507204a9d 100644 --- a/src/client/app/common/scripts/note-mixin.ts +++ b/src/client/app/common/scripts/note-mixin.ts @@ -206,6 +206,7 @@ export default (opts: Opts = {}) => ({ const w = this.$root.new(MkNoteMenu, { source: this.$refs.menuButton, note: this.appearNote, + actualNote: this.note animation: !viaKeyboard }).$once('closed', () => { this.openingMenu = false; diff --git a/src/client/app/common/scripts/note-subscriber.ts b/src/client/app/common/scripts/note-subscriber.ts index ec1f71aadf..f5ca54c764 100644 --- a/src/client/app/common/scripts/note-subscriber.ts +++ b/src/client/app/common/scripts/note-subscriber.ts @@ -61,6 +61,13 @@ export default prop => ({ } this.connection.send('sn', data); + + if (this.$_ns_isRenote) { + this.connection.send('sn', { + id: this.$_ns_note_.id, + }); + } + if (withHandler) this.connection.on('noteUpdated', this.onStreamNoteUpdated); } }, @@ -70,6 +77,11 @@ export default prop => ({ this.connection.send('un', { id: this.$_ns_target.id }); + if (this.$_ns_isRenote) { + this.connection.send('un', { + id: this.$_ns_note_.id, + }); + } if (withHandler) this.connection.off('noteUpdated', this.onStreamNoteUpdated); } }, @@ -81,7 +93,7 @@ export default prop => ({ onStreamNoteUpdated(data) { const { type, id, body } = data; - if (id !== this.$_ns_target.id) return; + if (id !== this.$_ns_target.id && id !== this.$_ns_note_.id) return; switch (type) { case 'reacted': { @@ -142,13 +154,14 @@ export default prop => ({ } case 'deleted': { - Vue.set(this.$_ns_target, 'deletedAt', body.deletedAt); - Vue.set(this.$_ns_target, 'renote', null); - this.$_ns_target.text = null; - this.$_ns_target.fileIds = []; - this.$_ns_target.poll = null; - this.$_ns_target.geo = null; - this.$_ns_target.cw = null; + const target = id === this.$_ns_target.id ? this.$_ns_target : this.$_ns_note_; + Vue.set(target, 'deletedAt', body.deletedAt); + Vue.set(target, 'renote', null); + target.text = null; + target.fileIds = []; + target.poll = null; + target.geo = null; + target.cw = null; break; } } diff --git a/src/client/app/common/views/components/note-menu.vue b/src/client/app/common/views/components/note-menu.vue index 04d891c1ed..ff3300ee7f 100644 --- a/src/client/app/common/views/components/note-menu.vue +++ b/src/client/app/common/views/components/note-menu.vue @@ -10,10 +10,11 @@ import i18n from '../../../i18n'; import { url } from '../../../config'; import copyToClipboard from '../../../common/scripts/copy-to-clipboard'; import { faCopy, faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons'; +import { faEdit } from '@fortawesome/free-solid-svg-icons'; export default Vue.extend({ i18n: i18n('common/views/components/note-menu.vue'), - props: ['note', 'source'], + props: ['note', 'source', 'actualNote'], data() { return { isFavorited: false, @@ -77,7 +78,7 @@ export default Vue.extend({ ...(this.note.userId == this.$store.state.i.id || this.$store.state.i.isAdmin || this.$store.state.i.isModerator ? [ null, this.note.userId == this.$store.state.i.id ? { - icon: 'undo-alt', + icon: faEdit, text: this.$t('delete-and-edit'), action: this.deleteAndEdit } : undefined, @@ -87,7 +88,13 @@ export default Vue.extend({ action: this.del }] : [] - )] + ), + ...(this.actualNote && this.actualNote.renote ? [{ + icon: 'undo-alt', + text: this.$t('undo-renote'), + action: this.undoRenote + }] : []), + ] .filter(x => x !== undefined); } else { return [{ @@ -202,6 +209,22 @@ export default Vue.extend({ }); }, + undoRenote() { + this.$root.dialog({ + type: 'warning', + text: this.$t('undo-renote-confirm'), + showCancelButton: true + }).then(({ canceled }) => { + if (canceled) return; + + this.$root.api('notes/delete', { + noteId: this.actualNote.id + }).then(() => { + this.destroyDom(); + }); + }); + } + toggleFavorite(favorite: boolean) { this.$root.api(favorite ? 'notes/favorites/create' : 'notes/favorites/delete', { noteId: this.note.id