enhance(frontend): 時刻表示を常に絶対時刻にできるように

This commit is contained in:
kakkokari-gtyih 2024-10-20 18:18:37 +09:00
parent d6caa4d9c4
commit 0f2ceafea1
5 changed files with 30 additions and 5 deletions

4
locales/index.d.ts vendored
View File

@ -5190,6 +5190,10 @@ export interface Locale extends ILocale {
* 使 * 使
*/ */
"yourNameContainsProhibitedWordsDescription": string; "yourNameContainsProhibitedWordsDescription": string;
/**
*
*/
"alwaysUseAbsoluteTime": string;
"_abuseUserReport": { "_abuseUserReport": {
/** /**
* *

View File

@ -1293,6 +1293,7 @@ prohibitedWordsForNameOfUser: "禁止ワード(ユーザーの名前)"
prohibitedWordsForNameOfUserDescription: "このリストに含まれる文字列がユーザーの名前に含まれる場合、ユーザーの名前の変更を拒否します。モデレーター権限を持つユーザーはこの制限の影響を受けません。" prohibitedWordsForNameOfUserDescription: "このリストに含まれる文字列がユーザーの名前に含まれる場合、ユーザーの名前の変更を拒否します。モデレーター権限を持つユーザーはこの制限の影響を受けません。"
yourNameContainsProhibitedWords: "変更しようとした名前に禁止された文字列が含まれています" yourNameContainsProhibitedWords: "変更しようとした名前に禁止された文字列が含まれています"
yourNameContainsProhibitedWordsDescription: "名前に禁止されている文字列が含まれています。この名前を使用したい場合は、サーバー管理者にお問い合わせください。" yourNameContainsProhibitedWordsDescription: "名前に禁止されている文字列が含まれています。この名前を使用したい場合は、サーバー管理者にお問い合わせください。"
alwaysUseAbsoluteTime: "常に絶対時刻で表示する"
_abuseUserReport: _abuseUserReport:
forward: "転送" forward: "転送"

View File

@ -6,9 +6,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<time :title="absolute" :class="{ [$style.old1]: colored && (ago > 60 * 60 * 24 * 90), [$style.old2]: colored && (ago > 60 * 60 * 24 * 180) }"> <time :title="absolute" :class="{ [$style.old1]: colored && (ago > 60 * 60 * 24 * 90), [$style.old2]: colored && (ago > 60 * 60 * 24 * 180) }">
<template v-if="invalid">{{ i18n.ts._ago.invalid }}</template> <template v-if="invalid">{{ i18n.ts._ago.invalid }}</template>
<template v-else-if="mode === 'relative'">{{ relative }}</template> <template v-else-if="_mode === 'relative'">{{ relative }}</template>
<template v-else-if="mode === 'absolute'">{{ absolute }}</template> <template v-else-if="_mode === 'absolute'">{{ absolute }}</template>
<template v-else-if="mode === 'detail'">{{ absolute }} ({{ relative }})</template> <template v-else-if="_mode === 'detail'">{{ absolute }} ({{ relative }})</template>
</time> </time>
</template> </template>
@ -16,6 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-only
import isChromatic from 'chromatic/isChromatic'; import isChromatic from 'chromatic/isChromatic';
import { onMounted, onUnmounted, ref, computed } from 'vue'; import { onMounted, onUnmounted, ref, computed } from 'vue';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { defaultStore } from '@/store.js';
import { dateTimeFormat } from '@@/js/intl-const.js'; import { dateTimeFormat } from '@@/js/intl-const.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
@ -23,9 +24,21 @@ const props = withDefaults(defineProps<{
origin?: Date | null; origin?: Date | null;
mode?: 'relative' | 'absolute' | 'detail'; mode?: 'relative' | 'absolute' | 'detail';
colored?: boolean; colored?: boolean;
allowOverrideByUser?: boolean;
}>(), { }>(), {
origin: isChromatic() ? () => new Date('2023-04-01T00:00:00Z') : null, origin: isChromatic() ? () => new Date('2023-04-01T00:00:00Z') : null,
mode: 'relative', mode: 'relative',
allowOverrideByUser: true,
});
const _mode = computed(() => {
if (props.mode === 'detail') return 'detail';
if (props.allowOverrideByUser && defaultStore.state.alwaysUseAbsoluteTime) {
return 'absolute';
} else {
return props.mode;
}
}); });
function getDateSafe(n: Date | string | number) { function getDateSafe(n: Date | string | number) {
@ -51,7 +64,7 @@ const now = ref(props.origin?.getTime() ?? Date.now());
const ago = computed(() => (now.value - _time) / 1000/*ms*/); const ago = computed(() => (now.value - _time) / 1000/*ms*/);
const relative = computed<string>(() => { const relative = computed<string>(() => {
if (props.mode === 'absolute') return ''; // absoluterelative使 if (_mode.value === 'absolute') return ''; // absoluterelative使
if (invalid) return i18n.ts._ago.invalid; if (invalid) return i18n.ts._ago.invalid;
return ( return (
@ -87,7 +100,7 @@ function tick() {
} }
} }
if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) { if (!invalid && props.origin === null && (_mode.value === 'relative' || _mode.value === 'detail')) {
onMounted(() => { onMounted(() => {
tick(); tick();
}); });

View File

@ -170,6 +170,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="enableHorizontalSwipe">{{ i18n.ts.enableHorizontalSwipe }}</MkSwitch> <MkSwitch v-model="enableHorizontalSwipe">{{ i18n.ts.enableHorizontalSwipe }}</MkSwitch>
<MkSwitch v-model="alwaysConfirmFollow">{{ i18n.ts.alwaysConfirmFollow }}</MkSwitch> <MkSwitch v-model="alwaysConfirmFollow">{{ i18n.ts.alwaysConfirmFollow }}</MkSwitch>
<MkSwitch v-model="confirmWhenRevealingSensitiveMedia">{{ i18n.ts.confirmWhenRevealingSensitiveMedia }}</MkSwitch> <MkSwitch v-model="confirmWhenRevealingSensitiveMedia">{{ i18n.ts.confirmWhenRevealingSensitiveMedia }}</MkSwitch>
<MkSwitch v-model="alwaysUseAbsoluteTime">{{ i18n.ts.alwaysUseAbsoluteTime }}</MkSwitch>
</div> </div>
<MkSelect v-model="serverDisconnectedBehavior"> <MkSelect v-model="serverDisconnectedBehavior">
<template #label>{{ i18n.ts.whenServerDisconnected }}</template> <template #label>{{ i18n.ts.whenServerDisconnected }}</template>
@ -319,6 +320,7 @@ const enableHorizontalSwipe = computed(defaultStore.makeGetterSetter('enableHori
const useNativeUIForVideoAudioPlayer = computed(defaultStore.makeGetterSetter('useNativeUIForVideoAudioPlayer')); const useNativeUIForVideoAudioPlayer = computed(defaultStore.makeGetterSetter('useNativeUIForVideoAudioPlayer'));
const alwaysConfirmFollow = computed(defaultStore.makeGetterSetter('alwaysConfirmFollow')); const alwaysConfirmFollow = computed(defaultStore.makeGetterSetter('alwaysConfirmFollow'));
const confirmWhenRevealingSensitiveMedia = computed(defaultStore.makeGetterSetter('confirmWhenRevealingSensitiveMedia')); const confirmWhenRevealingSensitiveMedia = computed(defaultStore.makeGetterSetter('confirmWhenRevealingSensitiveMedia'));
const alwaysUseAbsoluteTime = computed(defaultStore.makeGetterSetter('alwaysUseAbsoluteTime'));
const contextMenu = computed(defaultStore.makeGetterSetter('contextMenu')); const contextMenu = computed(defaultStore.makeGetterSetter('contextMenu'));
watch(lang, () => { watch(lang, () => {
@ -363,6 +365,7 @@ watch([
enableSeasonalScreenEffect, enableSeasonalScreenEffect,
alwaysConfirmFollow, alwaysConfirmFollow,
confirmWhenRevealingSensitiveMedia, confirmWhenRevealingSensitiveMedia,
alwaysUseAbsoluteTime,
contextMenu, contextMenu,
], async () => { ], async () => {
await reloadAsk({ reason: i18n.ts.reloadToApplySetting, unison: true }); await reloadAsk({ reason: i18n.ts.reloadToApplySetting, unison: true });

View File

@ -472,6 +472,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device', where: 'device',
default: true, default: true,
}, },
alwaysUseAbsoluteTime: {
where: 'device',
default: false,
},
sound_masterVolume: { sound_masterVolume: {
where: 'device', where: 'device',