This commit is contained in:
mattyatea 2023-11-26 18:21:16 +09:00
parent 072b228568
commit 5fe20bbe96
2 changed files with 227 additions and 228 deletions

View file

@ -4,125 +4,125 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<div class="_gaps_m"> <div class="_gaps_m">
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-message-off"></i></template> <template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.wordMute }}</template> <template #label>{{ i18n.ts.wordMute }}</template>
<XWordMute :muted="$i!.mutedWords" @save="saveMutedWords"/> <XWordMute :muted="$i!.mutedWords" @save="saveMutedWords"/>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-message-off"></i></template> <template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.hardWordMute }}</template> <template #label>{{ i18n.ts.hardWordMute }}</template>
<XWordMute :muted="$i!.hardMutedWords" @save="saveHardMutedWords"/> <XWordMute :muted="$i!.hardMutedWords" @save="saveHardMutedWords"/>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-planet-off"></i></template> <template #icon><i class="ti ti-planet-off"></i></template>
<template #label>{{ i18n.ts.instanceMute }}</template> <template #label>{{ i18n.ts.instanceMute }}</template>
<XInstanceMute/> <XInstanceMute/>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-repeat-off"></i></template> <template #icon><i class="ti ti-repeat-off"></i></template>
<template #label>{{ i18n.ts.mutedUsers }} ({{ i18n.ts.renote }})</template> <template #label>{{ i18n.ts.mutedUsers }} ({{ i18n.ts.renote }})</template>
<MkPagination :pagination="renoteMutingPagination"> <MkPagination :pagination="renoteMutingPagination">
<template #empty> <template #empty>
<div class="_fullinfo"> <div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost"/> <img :src="infoImageUrl" class="_ghost"/>
<div>{{ i18n.ts.noUsers }}</div> <div>{{ i18n.ts.noUsers }}</div>
</div> </div>
</template> </template>
<template #default="{ items }"> <template #default="{ items }">
<div class="_gaps_s"> <div class="_gaps_s">
<div v-for="item in items" :key="item.mutee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedRenoteMuteItems.includes(item.id) }]"> <div v-for="item in items" :key="item.mutee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedRenoteMuteItems.includes(item.id) }]">
<div :class="$style.userItemMain"> <div :class="$style.userItemMain">
<MkA :class="$style.userItemMainBody" :to="userPage(item.mutee)"> <MkA :class="$style.userItemMainBody" :to="userPage(item.mutee)">
<MkUserCardMini :user="item.mutee"/> <MkUserCardMini :user="item.mutee"/>
</MkA> </MkA>
<button class="_button" :class="$style.userToggle" @click="toggleRenoteMuteItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button> <button class="_button" :class="$style.userToggle" @click="toggleRenoteMuteItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button>
<button class="_button" :class="$style.remove" @click="unrenoteMute(item.mutee, $event)"><i class="ti ti-x"></i></button> <button class="_button" :class="$style.remove" @click="unrenoteMute(item.mutee, $event)"><i class="ti ti-x"></i></button>
</div> </div>
<div v-if="expandedRenoteMuteItems.includes(item.id)" :class="$style.userItemSub"> <div v-if="expandedRenoteMuteItems.includes(item.id)" :class="$style.userItemSub">
<div>Muted at: <MkTime :time="item.createdAt" mode="detail"/></div> <div>Muted at: <MkTime :time="item.createdAt" mode="detail"/></div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
</MkPagination> </MkPagination>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-eye-off"></i></template> <template #icon><i class="ti ti-eye-off"></i></template>
<template #label>{{ i18n.ts.mutedUsers }}</template> <template #label>{{ i18n.ts.mutedUsers }}</template>
<MkPagination :pagination="mutingPagination"> <MkPagination :pagination="mutingPagination">
<template #empty> <template #empty>
<div class="_fullinfo"> <div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost"/> <img :src="infoImageUrl" class="_ghost"/>
<div>{{ i18n.ts.noUsers }}</div> <div>{{ i18n.ts.noUsers }}</div>
</div> </div>
</template> </template>
<template #default="{ items }"> <template #default="{ items }">
<div class="_gaps_s"> <div class="_gaps_s">
<div v-for="item in items" :key="item.mutee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedMuteItems.includes(item.id) }]"> <div v-for="item in items" :key="item.mutee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedMuteItems.includes(item.id) }]">
<div :class="$style.userItemMain"> <div :class="$style.userItemMain">
<MkA :class="$style.userItemMainBody" :to="userPage(item.mutee)"> <MkA :class="$style.userItemMainBody" :to="userPage(item.mutee)">
<MkUserCardMini :user="item.mutee"/> <MkUserCardMini :user="item.mutee"/>
</MkA> </MkA>
<button class="_button" :class="$style.userToggle" @click="toggleMuteItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button> <button class="_button" :class="$style.userToggle" @click="toggleMuteItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button>
<button class="_button" :class="$style.remove" @click="unmute(item.mutee, $event)"><i class="ti ti-x"></i></button> <button class="_button" :class="$style.remove" @click="unmute(item.mutee, $event)"><i class="ti ti-x"></i></button>
</div> </div>
<div v-if="expandedMuteItems.includes(item.id)" :class="$style.userItemSub"> <div v-if="expandedMuteItems.includes(item.id)" :class="$style.userItemSub">
<div>Muted at: <MkTime :time="item.createdAt" mode="detail"/></div> <div>Muted at: <MkTime :time="item.createdAt" mode="detail"/></div>
<div v-if="item.expiresAt">Period: {{ new Date(item.expiresAt).toLocaleString() }}</div> <div v-if="item.expiresAt">Period: {{ new Date(item.expiresAt).toLocaleString() }}</div>
<div v-else>Period: {{ i18n.ts.indefinitely }}</div> <div v-else>Period: {{ i18n.ts.indefinitely }}</div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
</MkPagination> </MkPagination>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-ban"></i></template> <template #icon><i class="ti ti-ban"></i></template>
<template #label>{{ i18n.ts.blockedUsers }}</template> <template #label>{{ i18n.ts.blockedUsers }}</template>
<MkPagination :pagination="blockingPagination"> <MkPagination :pagination="blockingPagination">
<template #empty> <template #empty>
<div class="_fullinfo"> <div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost"/> <img :src="infoImageUrl" class="_ghost"/>
<div>{{ i18n.ts.noUsers }}</div> <div>{{ i18n.ts.noUsers }}</div>
</div> </div>
</template> </template>
<template #default="{ items }"> <template #default="{ items }">
<div class="_gaps_s"> <div class="_gaps_s">
<div v-for="item in items" :key="item.blockee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedBlockItems.includes(item.id) }]"> <div v-for="item in items" :key="item.blockee.id" :class="[$style.userItem, { [$style.userItemOpend]: expandedBlockItems.includes(item.id) }]">
<div :class="$style.userItemMain"> <div :class="$style.userItemMain">
<MkA :class="$style.userItemMainBody" :to="userPage(item.blockee)"> <MkA :class="$style.userItemMainBody" :to="userPage(item.blockee)">
<MkUserCardMini :user="item.blockee"/> <MkUserCardMini :user="item.blockee"/>
</MkA> </MkA>
<button class="_button" :class="$style.userToggle" @click="toggleBlockItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button> <button class="_button" :class="$style.userToggle" @click="toggleBlockItem(item)"><i :class="$style.chevron" class="ti ti-chevron-down"></i></button>
<button class="_button" :class="$style.remove" @click="unblock(item.blockee, $event)"><i class="ti ti-x"></i></button> <button class="_button" :class="$style.remove" @click="unblock(item.blockee, $event)"><i class="ti ti-x"></i></button>
</div> </div>
<div v-if="expandedBlockItems.includes(item.id)" :class="$style.userItemSub"> <div v-if="expandedBlockItems.includes(item.id)" :class="$style.userItemSub">
<div>Blocked at: <MkTime :time="item.createdAt" mode="detail"/></div> <div>Blocked at: <MkTime :time="item.createdAt" mode="detail"/></div>
<div v-if="item.expiresAt">Period: {{ new Date(item.expiresAt).toLocaleString() }}</div> <div v-if="item.expiresAt">Period: {{ new Date(item.expiresAt).toLocaleString() }}</div>
<div v-else>Period: {{ i18n.ts.indefinitely }}</div> <div v-else>Period: {{ i18n.ts.indefinitely }}</div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
</MkPagination> </MkPagination>
</MkFolder> </MkFolder>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -140,18 +140,18 @@ import { $i } from '@/account.js';
import MkFolder from '@/components/MkFolder.vue'; import MkFolder from '@/components/MkFolder.vue';
const renoteMutingPagination = { const renoteMutingPagination = {
endpoint: 'renote-mute/list' as const, endpoint: 'renote-mute/list' as const,
limit: 10, limit: 10,
}; };
const mutingPagination = { const mutingPagination = {
endpoint: 'mute/list' as const, endpoint: 'mute/list' as const,
limit: 10, limit: 10,
}; };
const blockingPagination = { const blockingPagination = {
endpoint: 'blocking/list' as const, endpoint: 'blocking/list' as const,
limit: 10, limit: 10,
}; };
let expandedRenoteMuteItems = $ref([]); let expandedRenoteMuteItems = $ref([]);
@ -159,68 +159,68 @@ let expandedMuteItems = $ref([]);
let expandedBlockItems = $ref([]); let expandedBlockItems = $ref([]);
async function unrenoteMute(user, ev) { async function unrenoteMute(user, ev) {
os.popupMenu([{ os.popupMenu([{
text: i18n.ts.renoteUnmute, text: i18n.ts.renoteUnmute,
icon: 'ti ti-x', icon: 'ti ti-x',
action: async () => { action: async () => {
await os.apiWithDialog('renote-mute/delete', { userId: user.id }); await os.apiWithDialog('renote-mute/delete', { userId: user.id });
//role.users = role.users.filter(u => u.id !== user.id); //role.users = role.users.filter(u => u.id !== user.id);
}, },
}], ev.currentTarget ?? ev.target); }], ev.currentTarget ?? ev.target);
} }
async function unmute(user, ev) { async function unmute(user, ev) {
os.popupMenu([{ os.popupMenu([{
text: i18n.ts.unmute, text: i18n.ts.unmute,
icon: 'ti ti-x', icon: 'ti ti-x',
action: async () => { action: async () => {
await os.apiWithDialog('mute/delete', { userId: user.id }); await os.apiWithDialog('mute/delete', { userId: user.id });
//role.users = role.users.filter(u => u.id !== user.id); //role.users = role.users.filter(u => u.id !== user.id);
}, },
}], ev.currentTarget ?? ev.target); }], ev.currentTarget ?? ev.target);
} }
async function unblock(user, ev) { async function unblock(user, ev) {
os.popupMenu([{ os.popupMenu([{
text: i18n.ts.unblock, text: i18n.ts.unblock,
icon: 'ti ti-x', icon: 'ti ti-x',
action: async () => { action: async () => {
await os.apiWithDialog('blocking/delete', { userId: user.id }); await os.apiWithDialog('blocking/delete', { userId: user.id });
//role.users = role.users.filter(u => u.id !== user.id); //role.users = role.users.filter(u => u.id !== user.id);
}, },
}], ev.currentTarget ?? ev.target); }], ev.currentTarget ?? ev.target);
} }
async function toggleRenoteMuteItem(item) { async function toggleRenoteMuteItem(item) {
if (expandedRenoteMuteItems.includes(item.id)) { if (expandedRenoteMuteItems.includes(item.id)) {
expandedRenoteMuteItems = expandedRenoteMuteItems.filter(x => x !== item.id); expandedRenoteMuteItems = expandedRenoteMuteItems.filter(x => x !== item.id);
} else { } else {
expandedRenoteMuteItems.push(item.id); expandedRenoteMuteItems.push(item.id);
} }
} }
async function toggleMuteItem(item) { async function toggleMuteItem(item) {
if (expandedMuteItems.includes(item.id)) { if (expandedMuteItems.includes(item.id)) {
expandedMuteItems = expandedMuteItems.filter(x => x !== item.id); expandedMuteItems = expandedMuteItems.filter(x => x !== item.id);
} else { } else {
expandedMuteItems.push(item.id); expandedMuteItems.push(item.id);
} }
} }
async function toggleBlockItem(item) { async function toggleBlockItem(item) {
if (expandedBlockItems.includes(item.id)) { if (expandedBlockItems.includes(item.id)) {
expandedBlockItems = expandedBlockItems.filter(x => x !== item.id); expandedBlockItems = expandedBlockItems.filter(x => x !== item.id);
} else { } else {
expandedBlockItems.push(item.id); expandedBlockItems.push(item.id);
} }
} }
async function saveMutedWords(mutedWords: (string | string[])[]) { async function saveMutedWords(mutedWords: (string | string[])[]) {
await os.api('i/update', { mutedWords }); await os.api('i/update', { mutedWords });
} }
async function saveHardMutedWords(hardMutedWords: (string | string[])[]) { async function saveHardMutedWords(hardMutedWords: (string | string[])[]) {
await os.api('i/update', { hardMutedWords }); await os.api('i/update', { hardMutedWords });
} }
const headerActions = $computed(() => []); const headerActions = $computed(() => []);
@ -228,47 +228,47 @@ const headerActions = $computed(() => []);
const headerTabs = $computed(() => []); const headerTabs = $computed(() => []);
definePageMetadata({ definePageMetadata({
title: i18n.ts.muteAndBlock, title: i18n.ts.muteAndBlock,
icon: 'ti ti-ban', icon: 'ti ti-ban',
}); });
</script> </script>
<style lang="scss" module> <style lang="scss" module>
.userItemMain { .userItemMain {
display: flex; display: flex;
} }
.userItemSub { .userItemSub {
padding: 6px 12px; padding: 6px 12px;
font-size: 85%; font-size: 85%;
color: var(--fgTransparentWeak); color: var(--fgTransparentWeak);
} }
.userItemMainBody { .userItemMainBody {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
margin-right: 8px; margin-right: 8px;
&:hover { &:hover {
text-decoration: none; text-decoration: none;
} }
} }
.userToggle, .userToggle,
.remove { .remove {
width: 32px; width: 32px;
height: 32px; height: 32px;
align-self: center; align-self: center;
} }
.chevron { .chevron {
display: block; display: block;
transition: transform 0.1s ease-out; transition: transform 0.1s ease-out;
} }
.userItem.userItemOpend { .userItem.userItemOpend {
.chevron { .chevron {
transform: rotateX(180deg); transform: rotateX(180deg);
} }
} }
</style> </style>

View file

@ -4,15 +4,15 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<div class="_gaps_m"> <div class="_gaps_m">
<div> <div>
<MkTextarea v-model="mutedWords"> <MkTextarea v-model="mutedWords">
<span>{{ i18n.ts._wordMute.muteWords }}</span> <span>{{ i18n.ts._wordMute.muteWords }}</span>
<template #caption>{{ i18n.ts._wordMute.muteWordsDescription }}<br>{{ i18n.ts._wordMute.muteWordsDescription2 }}</template> <template #caption>{{ i18n.ts._wordMute.muteWordsDescription }}<br>{{ i18n.ts._wordMute.muteWordsDescription2 }}</template>
</MkTextarea> </MkTextarea>
</div> </div>
<MkButton primary inline :disabled="!changed" @click="save()"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton> <MkButton primary inline :disabled="!changed" @click="save()"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -23,71 +23,70 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
const props = defineProps<{ const props = defineProps<{
muted: (string[] | string)[]; muted: (string[] | string)[];
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(ev: 'save', value: (string[] | string)[]): void; (ev: 'save', value: (string[] | string)[]): void;
}>(); }>();
const render = (mutedWords) => mutedWords.map(x => { const render = (mutedWords) => mutedWords.map(x => {
if (Array.isArray(x)) { if (Array.isArray(x)) {
return x.join(' '); return x.join(' ');
} else { } else {
return x; return x;
} }
}).join('\n'); }).join('\n');
const tab = ref('soft'); const mutedWords = ref(render(props.muted));
const mutedWords = ref(render($i!.mutedWords));
const changed = ref(false); const changed = ref(false);
watch(mutedWords, () => { watch(mutedWords, () => {
changed.value = true; changed.value = true;
}); });
async function save() { async function save() {
const parseMutes = (mutes) => { const parseMutes = (mutes) => {
// split into lines, remove empty lines and unnecessary whitespace // split into lines, remove empty lines and unnecessary whitespace
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== ''); let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '');
// check each line if it is a RegExp or not // check each line if it is a RegExp or not
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
const line = lines[i]; const line = lines[i];
const regexp = line.match(/^\/(.+)\/(.*)$/); const regexp = line.match(/^\/(.+)\/(.*)$/);
if (regexp) { if (regexp) {
// check that the RegExp is valid // check that the RegExp is valid
try { try {
new RegExp(regexp[1], regexp[2]); new RegExp(regexp[1], regexp[2]);
// note that regex lines will not be split by spaces! // note that regex lines will not be split by spaces!
} catch (err: any) { } catch (err: any) {
// invalid syntax: do not save, do not reset changed flag // invalid syntax: do not save, do not reset changed flag
os.alert({ os.alert({
type: 'error', type: 'error',
title: i18n.ts.regexpError, title: i18n.ts.regexpError,
text: i18n.t('regexpErrorDescription', { tab: 'word mute', line: i + 1 }) + '\n' + err.toString(), text: i18n.t('regexpErrorDescription', { tab: 'word mute', line: i + 1 }) + '\n' + err.toString(),
}); });
// re-throw error so these invalid settings are not saved // re-throw error so these invalid settings are not saved
throw err; throw err;
} }
} else { } else {
lines[i] = line.split(' '); lines[i] = line.split(' ');
} }
} }
return lines; return lines;
}; };
let parsed; let parsed;
try { try {
parsed = parseMutes(mutedWords.value); parsed = parseMutes(mutedWords.value);
} catch (err) { } catch (err) {
// already displayed error message in parseMutes // already displayed error message in parseMutes
return; return;
} }
emit('save', parsed); emit('save', parsed);
changed.value = false; changed.value = false;
} }
</script> </script>