diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-11-11 21:17:51 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-11-11 21:17:51 +0900 |
| commit | 71d42f64dc840e744e757cb5edae32276d83a7f4 (patch) | |
| tree | 32ccae355b74a00cf47066a862961d8cb33fd642 /src/client | |
| parent | [Client] Fix i18n (diff) | |
| download | sharkey-71d42f64dc840e744e757cb5edae32276d83a7f4.tar.gz sharkey-71d42f64dc840e744e757cb5edae32276d83a7f4.tar.bz2 sharkey-71d42f64dc840e744e757cb5edae32276d83a7f4.zip | |
[Client] Implement word mute
Closes #1739
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/app/common/scripts/note-mixin.ts | 8 | ||||
| -rw-r--r-- | src/client/app/common/scripts/should-mute-note.ts | 28 | ||||
| -rw-r--r-- | src/client/app/common/views/components/mute-and-block.vue | 27 | ||||
| -rw-r--r-- | src/client/app/desktop/views/components/note.vue | 2 | ||||
| -rw-r--r-- | src/client/app/desktop/views/components/notes.vue | 26 | ||||
| -rw-r--r-- | src/client/app/desktop/views/pages/deck/deck.notes.vue | 25 | ||||
| -rw-r--r-- | src/client/app/mobile/views/components/note.vue | 2 | ||||
| -rw-r--r-- | src/client/app/mobile/views/components/notes.vue | 25 | ||||
| -rw-r--r-- | src/client/app/store.ts | 1 |
9 files changed, 73 insertions, 71 deletions
diff --git a/src/client/app/common/scripts/note-mixin.ts b/src/client/app/common/scripts/note-mixin.ts index dd5098f4cd..9f1a4c6eea 100644 --- a/src/client/app/common/scripts/note-mixin.ts +++ b/src/client/app/common/scripts/note-mixin.ts @@ -1,5 +1,6 @@ import parse from '../../../../mfm/parse'; import { sum } from '../../../../prelude/array'; +import shouldMuteNote from './should-mute-note'; import MkNoteMenu from '../views/components/note-menu.vue'; import MkReactionPicker from '../views/components/reaction-picker.vue'; import Ok from '../views/components/ok.vue'; @@ -22,7 +23,8 @@ type Opts = { export default (opts: Opts = {}) => ({ data() { return { - showContent: false + showContent: false, + hideThisNote: false }; }, @@ -86,6 +88,10 @@ export default (opts: Opts = {}) => ({ } }, + created() { + this.hideThisNote = shouldMuteNote(this.$store.state.i, this.$store.state.settings, this.appearNote); + }, + methods: { reply(viaKeyboard = false) { this.$root.$post({ diff --git a/src/client/app/common/scripts/should-mute-note.ts b/src/client/app/common/scripts/should-mute-note.ts new file mode 100644 index 0000000000..a849135763 --- /dev/null +++ b/src/client/app/common/scripts/should-mute-note.ts @@ -0,0 +1,28 @@ +export default function(me, settings, note) { + const isMyNote = note.userId == me.id; + const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null; + + if (settings.showMyRenotes === false) { + if (isMyNote && isPureRenote) { + return true; + } + } + + if (settings.showRenotedMyNotes === false) { + if (isPureRenote && (note.renote.userId == me.id)) { + return true; + } + } + + if (settings.showLocalRenotes === false) { + if (isPureRenote && (note.renote.user.host == null)) { + return true; + } + } + + if (!isMyNote && note.text && settings.mutedWords.some(q => !q.some(word => !note.text.includes(word)))) { + return true; + } + + return false; +} diff --git a/src/client/app/common/views/components/mute-and-block.vue b/src/client/app/common/views/components/mute-and-block.vue index 3ed02e644c..fdeaa97eb4 100644 --- a/src/client/app/common/views/components/mute-and-block.vue +++ b/src/client/app/common/views/components/mute-and-block.vue @@ -21,6 +21,14 @@ </div> </div> </section> + + <section> + <header>{{ $t('word-mute') }}</header> + <ui-textarea v-model="mutedWords"> + {{ $t('muted-words') }}<span slot="desc">{{ $t('muted-words-description') }}</span> + </ui-textarea> + <ui-button @click="save">{{ $t('save') }}</ui-button> + </section> </ui-card> </template> @@ -30,16 +38,27 @@ import i18n from '../../../i18n'; export default Vue.extend({ i18n: i18n('common/views/components/mute-and-block.vue'), + data() { return { muteFetching: true, blockFetching: true, mute: [], - block: [] + block: [], + mutedWords: '' }; }, + computed: { + _mutedWords: { + get() { return this.$store.state.settings.mutedWords; }, + set(value) { this.$store.dispatch('settings/set', { key: 'mutedWords', value }); } + }, + }, + mounted() { + this.mutedWords = this._mutedWords.map(words => words.join(' ')).join('\n'); + this.$root.api('mute/list').then(mute => { this.mute = mute.map(x => x.mutee); this.muteFetching = false; @@ -49,6 +68,12 @@ export default Vue.extend({ this.block = blocking.map(x => x.blockee); this.blockFetching = false; }); + }, + + methods: { + save() { + this._mutedWords = this.mutedWords.split('\n').map(line => line.split(' ')); + } } }); </script> diff --git a/src/client/app/desktop/views/components/note.vue b/src/client/app/desktop/views/components/note.vue index 2b164687eb..e2b67c150f 100644 --- a/src/client/app/desktop/views/components/note.vue +++ b/src/client/app/desktop/views/components/note.vue @@ -2,7 +2,7 @@ <div class="note" :class="{ mini }" - v-show="appearNote.deletedAt == null" + v-show="appearNote.deletedAt == null && !hideThisNote" :tabindex="appearNote.deletedAt == null ? '-1' : null" v-hotkey="keymap" :title="title" diff --git a/src/client/app/desktop/views/components/notes.vue b/src/client/app/desktop/views/components/notes.vue index 47f7919d72..6991f13545 100644 --- a/src/client/app/desktop/views/components/notes.vue +++ b/src/client/app/desktop/views/components/notes.vue @@ -36,7 +36,7 @@ import Vue from 'vue'; import i18n from '../../../i18n'; import * as config from '../../../config'; - +import shouldMuteNote from '../../../common/scripts/should-mute-note'; import XNote from './note.vue'; const displayLimit = 30; @@ -119,28 +119,8 @@ export default Vue.extend({ }, prepend(note, silent = false) { - //#region 弾く - const isMyNote = note.userId == this.$store.state.i.id; - const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null; - - if (this.$store.state.settings.showMyRenotes === false) { - if (isMyNote && isPureRenote) { - return; - } - } - - if (this.$store.state.settings.showRenotedMyNotes === false) { - if (isPureRenote && (note.renote.userId == this.$store.state.i.id)) { - return; - } - } - - if (this.$store.state.settings.showLocalRenotes === false) { - if (isPureRenote && (note.renote.user.host == null)) { - return; - } - } - //#endregion + // 弾く + if (shouldMuteNote(this.$store.state.i, this.$store.state.settings, note)) return; // タブが非表示またはスクロール位置が最上部ではないならタイトルで通知 if (document.hidden || !this.isScrollTop()) { diff --git a/src/client/app/desktop/views/pages/deck/deck.notes.vue b/src/client/app/desktop/views/pages/deck/deck.notes.vue index 611b28ffc0..7282e6a3f2 100644 --- a/src/client/app/desktop/views/pages/deck/deck.notes.vue +++ b/src/client/app/desktop/views/pages/deck/deck.notes.vue @@ -40,6 +40,7 @@ <script lang="ts"> import Vue from 'vue'; import i18n from '../../../../i18n'; +import shouldMuteNote from '../../../../common/scripts/should-mute-note'; import XNote from '../../components/note.vue'; @@ -135,28 +136,8 @@ export default Vue.extend({ }, prepend(note, silent = false) { - //#region 弾く - const isMyNote = note.userId == this.$store.state.i.id; - const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null; - - if (this.$store.state.settings.showMyRenotes === false) { - if (isMyNote && isPureRenote) { - return; - } - } - - if (this.$store.state.settings.showRenotedMyNotes === false) { - if (isPureRenote && (note.renote.userId == this.$store.state.i.id)) { - return; - } - } - - if (this.$store.state.settings.showLocalRenotes === false) { - if (isPureRenote && (note.renote.user.host == null)) { - return; - } - } - //#endregion + // 弾く + if (shouldMuteNote(this.$store.state.i, this.$store.state.settings, note)) return; // タブが非表示ならタイトルで通知 if (document.hidden) { diff --git a/src/client/app/mobile/views/components/note.vue b/src/client/app/mobile/views/components/note.vue index f6b7d39b83..d42efbf344 100644 --- a/src/client/app/mobile/views/components/note.vue +++ b/src/client/app/mobile/views/components/note.vue @@ -1,7 +1,7 @@ <template> <div class="note" - v-show="appearNote.deletedAt == null" + v-show="appearNote.deletedAt == null && !hideThisNote" :tabindex="appearNote.deletedAt == null ? '-1' : null" :class="{ renote: isRenote, smart: $store.state.device.postStyle == 'smart' }" v-hotkey="keymap" diff --git a/src/client/app/mobile/views/components/notes.vue b/src/client/app/mobile/views/components/notes.vue index e363d219a6..e239f8957d 100644 --- a/src/client/app/mobile/views/components/notes.vue +++ b/src/client/app/mobile/views/components/notes.vue @@ -35,6 +35,7 @@ <script lang="ts"> import Vue from 'vue'; import i18n from '../../../i18n'; +import shouldMuteNote from '../../../common/scripts/should-mute-note'; const displayLimit = 30; @@ -118,28 +119,8 @@ export default Vue.extend({ }, prepend(note, silent = false) { - //#region 弾く - const isMyNote = note.userId == this.$store.state.i.id; - const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null; - - if (this.$store.state.settings.showMyRenotes === false) { - if (isMyNote && isPureRenote) { - return; - } - } - - if (this.$store.state.settings.showRenotedMyNotes === false) { - if (isPureRenote && (note.renote.userId == this.$store.state.i.id)) { - return; - } - } - - if (this.$store.state.settings.showLocalRenotes === false) { - if (isPureRenote && (note.renote.user.host == null)) { - return; - } - } - //#endregion + // 弾く + if (shouldMuteNote(this.$store.state.i, this.$store.state.settings, note)) return; // タブが非表示またはスクロール位置が最上部ではないならタイトルで通知 if (document.hidden || !this.isScrollTop()) { diff --git a/src/client/app/store.ts b/src/client/app/store.ts index 08d5c9b127..065015b3db 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -34,6 +34,7 @@ const defaultSettings = { iLikeSushi: false, rememberNoteVisibility: false, defaultNoteVisibility: 'public', + mutedWords: [], games: { reversi: { showBoardLabels: false, |