enhance(frontend): チャットのホームの表示を定期的に更新するように

This commit is contained in:
syuilo 2025-03-25 12:19:59 +09:00
parent 023ab02e59
commit 9f4fa6d3f5
1 changed files with 33 additions and 4 deletions

View File

@ -56,17 +56,18 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
</MkA> </MkA>
</div> </div>
<div v-if="!fetching && history.length == 0" class="_fullinfo"> <div v-if="!initializing && history.length == 0" class="_fullinfo">
<div>{{ i18n.ts._chat.noHistory }}</div> <div>{{ i18n.ts._chat.noHistory }}</div>
</div> </div>
<MkLoading v-if="fetching"/> <MkLoading v-if="initializing"/>
</MkFoldableSection> </MkFoldableSection>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'; import { computed, onActivated, onDeactivated, onMounted, ref } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { useInterval } from '@@/js/use-interval.js';
import XMessage from './XMessage.vue'; import XMessage from './XMessage.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
@ -82,7 +83,8 @@ const $i = ensureSignin();
const router = useRouter(); const router = useRouter();
const fetching = ref(true); const initializing = ref(true);
const fetching = ref(false);
const history = ref<{ const history = ref<{
id: string; id: string;
message: Misskey.entities.ChatMessage; message: Misskey.entities.ChatMessage;
@ -143,6 +145,8 @@ async function search() {
} }
async function fetchHistory() { async function fetchHistory() {
if (fetching.value) return;
fetching.value = true; fetching.value = true;
const [userMessages, roomMessages] = await Promise.all([ const [userMessages, roomMessages] = await Promise.all([
@ -160,10 +164,35 @@ async function fetchHistory() {
})); }));
fetching.value = false; fetching.value = false;
initializing.value = false;
updateCurrentAccountPartial({ hasUnreadChatMessages: false }); updateCurrentAccountPartial({ hasUnreadChatMessages: false });
} }
let isActivated = true;
onActivated(() => {
isActivated = true;
});
onDeactivated(() => {
isActivated = false;
});
useInterval(() => {
// TODO: DOM
if (!window.document.hidden && isActivated) {
fetchHistory();
}
}, 1000 * 10, {
immediate: false,
afterMounted: true,
});
onActivated(() => {
fetchHistory();
});
onMounted(() => { onMounted(() => {
fetchHistory(); fetchHistory();
}); });