表示済みのカラムから別のチャンネルを選択した時、タイムラインの内容が追従して変更されない問題に対処
This commit is contained in:
parent
a8e976d72f
commit
a01a557046
|
|
@ -43,12 +43,11 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue';
|
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, ref, watch } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { onScrollTop, isTopVisible, getBodyScrollHeight, getScrollContainer, onScrollBottom, scrollToBottom, scroll, isBottomVisible } from '@/scripts/scroll.js';
|
import { onScrollTop, isTopVisible, getBodyScrollHeight, getScrollContainer, onScrollBottom, scrollToBottom, scroll, isBottomVisible } from '@/scripts/scroll.js';
|
||||||
import { useDocumentVisibility } from '@/scripts/use-document-visibility.js';
|
import { useDocumentVisibility } from '@/scripts/use-document-visibility.js';
|
||||||
import MkButton from '@/components/MkButton.vue';
|
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
import { MisskeyEntity } from '@/types/date-separated-list';
|
import { MisskeyEntity } from '@/types/date-separated-list';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
|
|
@ -185,9 +184,8 @@ watch([$$(backed), $$(contentEl)], () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.pagination.params && isRef(props.pagination.params)) {
|
// パラメータに何らかの変更があった際、再読込したい(チャンネル等のIDが変わったなど)
|
||||||
watch(props.pagination.params, init, { deep: true });
|
watch(() => props.pagination.params, init, { deep: true });
|
||||||
}
|
|
||||||
|
|
||||||
watch(queue, (a, b) => {
|
watch(queue, (a, b) => {
|
||||||
if (a.size === 0 && b.size === 0) return;
|
if (a.size === 0 && b.size === 0) return;
|
||||||
|
|
@ -440,8 +438,6 @@ const updateItem = (id: MisskeyEntity['id'], replacer: (old: MisskeyEntity) => M
|
||||||
if (queueItem) queue.value.set(id, replacer(queueItem));
|
if (queueItem) queue.value.set(id, replacer(queueItem));
|
||||||
};
|
};
|
||||||
|
|
||||||
const inited = init();
|
|
||||||
|
|
||||||
onActivated(() => {
|
onActivated(() => {
|
||||||
isBackTop.value = false;
|
isBackTop.value = false;
|
||||||
});
|
});
|
||||||
|
|
@ -454,8 +450,8 @@ function toBottom() {
|
||||||
scrollToBottom(contentEl!);
|
scrollToBottom(contentEl!);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onBeforeMount(() => {
|
||||||
inited.then(() => {
|
init().then(() => {
|
||||||
if (props.pagination.reversed) {
|
if (props.pagination.reversed) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
setTimeout(toBottom, 800);
|
setTimeout(toBottom, 800);
|
||||||
|
|
@ -487,7 +483,6 @@ defineExpose({
|
||||||
queue,
|
queue,
|
||||||
backed,
|
backed,
|
||||||
more,
|
more,
|
||||||
inited,
|
|
||||||
reload,
|
reload,
|
||||||
prepend,
|
prepend,
|
||||||
append: appendItem,
|
append: appendItem,
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,28 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<MkPullToRefresh ref="prComponent" :refresher="() => reloadTimeline()">
|
<MkPullToRefresh ref="prComponent" :refresher="() => reloadTimeline()">
|
||||||
<MkNotes ref="tlComponent" :noGap="!defaultStore.state.showGapBetweenNotesInTimeline" :pagination="pagination" @queue="emit('queue', $event)" @status="prComponent.setDisabled($event)"/>
|
<MkNotes
|
||||||
|
v-if="paginationQuery"
|
||||||
|
ref="tlComponent"
|
||||||
|
:pagination="paginationQuery"
|
||||||
|
:noGap="!defaultStore.state.showGapBetweenNotesInTimeline"
|
||||||
|
@queue="emit('queue', $event)"
|
||||||
|
@status="prComponent.setDisabled($event)"
|
||||||
|
/>
|
||||||
</MkPullToRefresh>
|
</MkPullToRefresh>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, provide, onUnmounted } from 'vue';
|
import { computed, onBeforeMount, onUnmounted, onBeforeUpdate, provide } from 'vue';
|
||||||
|
import { Connection } from 'misskey-js/built/streaming.js';
|
||||||
import MkNotes from '@/components/MkNotes.vue';
|
import MkNotes from '@/components/MkNotes.vue';
|
||||||
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
||||||
import { useStream, reloadStream } from '@/stream.js';
|
import { reloadStream, useStream } from '@/stream.js';
|
||||||
import * as sound from '@/scripts/sound.js';
|
import * as sound from '@/scripts/sound.js';
|
||||||
import { $i } from '@/account.js';
|
import { $i } from '@/account.js';
|
||||||
import { instance } from '@/instance.js';
|
import { instance } from '@/instance.js';
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
|
import { Paging } from '@/components/MkPagination.vue';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
src: string;
|
src: string;
|
||||||
|
|
@ -42,6 +51,17 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
provide('inChannel', computed(() => props.src === 'channel'));
|
provide('inChannel', computed(() => props.src === 'channel'));
|
||||||
|
|
||||||
|
type TimelineQueryType = {
|
||||||
|
antennaId?: string,
|
||||||
|
withRenotes?: boolean,
|
||||||
|
withReplies?: boolean,
|
||||||
|
withFiles?: boolean,
|
||||||
|
visibility?: string,
|
||||||
|
listId?: string,
|
||||||
|
channelId?: string,
|
||||||
|
roleId?: string
|
||||||
|
}
|
||||||
|
|
||||||
const prComponent: InstanceType<typeof MkPullToRefresh> = $ref();
|
const prComponent: InstanceType<typeof MkPullToRefresh> = $ref();
|
||||||
const tlComponent: InstanceType<typeof MkNotes> = $ref();
|
const tlComponent: InstanceType<typeof MkNotes> = $ref();
|
||||||
|
|
||||||
|
|
@ -63,10 +83,9 @@ const prepend = note => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let endpoint;
|
let connection: Connection;
|
||||||
let query;
|
let connection2: Connection;
|
||||||
let connection;
|
let paginationQuery: Paging | null = null;
|
||||||
let connection2;
|
|
||||||
|
|
||||||
const stream = useStream();
|
const stream = useStream();
|
||||||
const connectChannel = () => {
|
const connectChannel = () => {
|
||||||
|
|
@ -125,77 +144,102 @@ const connectChannel = () => {
|
||||||
if (props.src !== 'directs' || props.src !== 'mentions') connection.on('note', prepend);
|
if (props.src !== 'directs' || props.src !== 'mentions') connection.on('note', prepend);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (props.src === 'antenna') {
|
const disconnectChannel = () => {
|
||||||
endpoint = 'antennas/notes';
|
if (connection) connection.dispose();
|
||||||
query = {
|
if (connection2) connection2.dispose();
|
||||||
antennaId: props.antenna,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'home') {
|
|
||||||
endpoint = 'notes/timeline';
|
|
||||||
query = {
|
|
||||||
withRenotes: props.withRenotes,
|
|
||||||
withFiles: props.onlyFiles ? true : undefined,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'local') {
|
|
||||||
endpoint = 'notes/local-timeline';
|
|
||||||
query = {
|
|
||||||
withRenotes: props.withRenotes,
|
|
||||||
withReplies: props.withReplies,
|
|
||||||
withFiles: props.onlyFiles ? true : undefined,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'social') {
|
|
||||||
endpoint = 'notes/hybrid-timeline';
|
|
||||||
query = {
|
|
||||||
withRenotes: props.withRenotes,
|
|
||||||
withReplies: props.withReplies,
|
|
||||||
withFiles: props.onlyFiles ? true : undefined,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'global') {
|
|
||||||
endpoint = 'notes/global-timeline';
|
|
||||||
query = {
|
|
||||||
withRenotes: props.withRenotes,
|
|
||||||
withFiles: props.onlyFiles ? true : undefined,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'mentions') {
|
|
||||||
endpoint = 'notes/mentions';
|
|
||||||
} else if (props.src === 'directs') {
|
|
||||||
endpoint = 'notes/mentions';
|
|
||||||
query = {
|
|
||||||
visibility: 'specified',
|
|
||||||
};
|
|
||||||
} else if (props.src === 'list') {
|
|
||||||
endpoint = 'notes/user-list-timeline';
|
|
||||||
query = {
|
|
||||||
withFiles: props.onlyFiles ? true : undefined,
|
|
||||||
listId: props.list,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'channel') {
|
|
||||||
endpoint = 'channels/timeline';
|
|
||||||
query = {
|
|
||||||
channelId: props.channel,
|
|
||||||
};
|
|
||||||
} else if (props.src === 'role') {
|
|
||||||
endpoint = 'roles/notes';
|
|
||||||
query = {
|
|
||||||
roleId: props.role,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!defaultStore.state.disableStreamingTimeline) {
|
|
||||||
connectChannel();
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
connection.dispose();
|
|
||||||
if (connection2) connection2.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const pagination = {
|
|
||||||
endpoint: endpoint,
|
|
||||||
limit: 10,
|
|
||||||
params: query,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updatePaginationQuery = () => {
|
||||||
|
let endpoint: string | null;
|
||||||
|
let query: TimelineQueryType | null;
|
||||||
|
|
||||||
|
if (props.src === 'antenna') {
|
||||||
|
endpoint = 'antennas/notes';
|
||||||
|
query = {
|
||||||
|
antennaId: props.antenna,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'home') {
|
||||||
|
endpoint = 'notes/timeline';
|
||||||
|
query = {
|
||||||
|
withRenotes: props.withRenotes,
|
||||||
|
withFiles: props.onlyFiles ? true : undefined,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'local') {
|
||||||
|
endpoint = 'notes/local-timeline';
|
||||||
|
query = {
|
||||||
|
withRenotes: props.withRenotes,
|
||||||
|
withReplies: props.withReplies,
|
||||||
|
withFiles: props.onlyFiles ? true : undefined,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'social') {
|
||||||
|
endpoint = 'notes/hybrid-timeline';
|
||||||
|
query = {
|
||||||
|
withRenotes: props.withRenotes,
|
||||||
|
withReplies: props.withReplies,
|
||||||
|
withFiles: props.onlyFiles ? true : undefined,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'global') {
|
||||||
|
endpoint = 'notes/global-timeline';
|
||||||
|
query = {
|
||||||
|
withRenotes: props.withRenotes,
|
||||||
|
withFiles: props.onlyFiles ? true : undefined,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'mentions') {
|
||||||
|
endpoint = 'notes/mentions';
|
||||||
|
query = null;
|
||||||
|
} else if (props.src === 'directs') {
|
||||||
|
endpoint = 'notes/mentions';
|
||||||
|
query = {
|
||||||
|
visibility: 'specified',
|
||||||
|
};
|
||||||
|
} else if (props.src === 'list') {
|
||||||
|
endpoint = 'notes/user-list-timeline';
|
||||||
|
query = {
|
||||||
|
withFiles: props.onlyFiles ? true : undefined,
|
||||||
|
listId: props.list,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'channel') {
|
||||||
|
endpoint = 'channels/timeline';
|
||||||
|
query = {
|
||||||
|
channelId: props.channel,
|
||||||
|
};
|
||||||
|
} else if (props.src === 'role') {
|
||||||
|
endpoint = 'roles/notes';
|
||||||
|
query = {
|
||||||
|
roleId: props.role,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
endpoint = null;
|
||||||
|
query = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endpoint && query) {
|
||||||
|
paginationQuery = {
|
||||||
|
endpoint: endpoint,
|
||||||
|
limit: 10,
|
||||||
|
params: query,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
paginationQuery = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const refreshEndpointAndChannel = () => {
|
||||||
|
if (!defaultStore.state.disableStreamingTimeline) {
|
||||||
|
disconnectChannel();
|
||||||
|
connectChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePaginationQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
disconnectChannel();
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeMount(refreshEndpointAndChannel);
|
||||||
|
onBeforeUpdate(refreshEndpointAndChannel);
|
||||||
|
|
||||||
function reloadTimeline() {
|
function reloadTimeline() {
|
||||||
return new Promise<void>((res) => {
|
return new Promise<void>((res) => {
|
||||||
tlNotesCount = 0;
|
tlNotesCount = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue