merge: Support following feed in Deck UI (resolves #789) (!724)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/724

Closes #789

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
dakkar 2024-11-22 23:02:31 +00:00
commit 59afb56b5b
14 changed files with 589 additions and 243 deletions

8
locales/index.d.ts vendored
View File

@ -9661,6 +9661,10 @@ export interface Locale extends ILocale {
*
*/
"roleTimeline": string;
/**
* Following
*/
"following": string;
};
};
"_dialog": {
@ -11374,6 +11378,10 @@ export interface Locale extends ILocale {
* Remote followers may have incomplete or outdated activity
*/
"remoteFollowersWarning": string;
/**
* Select a follow relationship...
*/
"selectFollowRelationship": string;
}
declare const locales: {
[lang: string]: Locale;

View File

@ -0,0 +1,144 @@
<!--
SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkPullToRefresh :refresher="() => reload()">
<MkPagination ref="latestNotesPaging" :pagination="latestNotesPagination" @init="onListReady">
<template #empty>
<div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost" :alt="i18n.ts.noNotes" aria-hidden="true"/>
<div>{{ i18n.ts.noNotes }}</div>
</div>
</template>
<template #default="{ items: notes }">
<MkDateSeparatedList v-slot="{ item: note }" :items="notes" :class="$style.panel" :noGap="true">
<SkFollowingFeedEntry v-if="!isHardMuted(note)" :isMuted="isSoftMuted(note)" :note="note" :class="props.selectedUserId == note.userId && $style.selected" @select="u => selectUser(u.id)"/>
</MkDateSeparatedList>
</template>
</MkPagination>
</MkPullToRefresh>
</template>
<script setup lang="ts">
import * as Misskey from 'misskey-js';
import { computed, shallowRef } from 'vue';
import { infoImageUrl } from '@/instance.js';
import { i18n } from '@/i18n.js';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import SkFollowingFeedEntry from '@/components/SkFollowingFeedEntry.vue';
import { $i } from '@/account.js';
import { checkWordMute } from '@/scripts/check-word-mute.js';
import { FollowingFeedTab } from '@/scripts/following-feed-utils.js';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
const props = defineProps<{
userList: FollowingFeedTab;
withNonPublic: boolean;
withQuotes: boolean;
withReplies: boolean;
withBots: boolean;
onlyFiles: boolean;
selectedUserId?: string | null;
}>();
const emit = defineEmits<{
(event: 'loaded', initialUserId?: string): void;
(event: 'userSelected', userId: string): void;
}>();
defineExpose({ reload });
async function reload() {
await latestNotesPaging.value?.reload();
}
function selectUser(userId: string) {
emit('userSelected', userId);
}
async function onListReady(): Promise<void> {
// This looks complicated, but it's really just a trick to get the first user ID from the pagination.
const initialUserId = latestNotesPaging.value?.items.size
? latestNotesPaging.value.items.values().next().value?.userId
: undefined;
emit('loaded', initialUserId);
}
const latestNotesPagination: Paging<'notes/following'> = {
endpoint: 'notes/following' as const,
limit: 20,
params: computed(() => ({
list: props.userList,
filesOnly: props.onlyFiles,
includeNonPublic: props.withNonPublic,
includeReplies: props.withReplies,
includeQuotes: props.withQuotes,
includeBots: props.withBots,
})),
};
const latestNotesPaging = shallowRef<InstanceType<typeof MkPagination>>();
function isSoftMuted(note: Misskey.entities.Note): boolean {
return isMuted(note, $i?.mutedWords);
}
function isHardMuted(note: Misskey.entities.Note): boolean {
return isMuted(note, $i?.hardMutedWords);
}
// Match the typing used by Misskey
type Mutes = (string | string[])[] | null | undefined;
// Adapted from MkNote.ts
function isMuted(note: Misskey.entities.Note, mutes: Mutes): boolean {
return checkMute(note, mutes)
|| checkMute(note.reply, mutes)
|| checkMute(note.renote, mutes);
}
// Adapted from check-word-mute.ts
function checkMute(note: Misskey.entities.Note | undefined | null, mutes: Mutes): boolean {
if (!note) {
return false;
}
if (!mutes || mutes.length < 1) {
return false;
}
return checkWordMute(note, $i, mutes);
}
</script>
<style module lang="scss">
.panel {
background: var(--panel);
}
@keyframes border {
from {
border-left: 0 solid var(--accent);
}
to {
border-left: 6px solid var(--accent);
}
}
.selected {
animation: border 0.2s ease-out 0s 1 forwards;
&:first-child {
border-top-left-radius: 5px;
}
&:last-child {
border-bottom-left-radius: 5px;
}
}
</style>

View File

@ -0,0 +1,32 @@
<!--
SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkInfo v-if="showRemoteWarning" warn closable @close="close">
{{ i18n.ts.remoteFollowersWarning }}
</MkInfo>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { i18n } from '@/i18n.js';
import MkInfo from '@/components/MkInfo.vue';
import { followersTab, FollowingFeedModel } from '@/scripts/following-feed-utils.js';
const props = defineProps<{
model: FollowingFeedModel,
}>();
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
const { model: { userList, remoteWarningDismissed } } = props;
const showRemoteWarning = computed(
() => userList.value === followersTab && !remoteWarningDismissed.value,
);
function close() {
remoteWarningDismissed.value = true;
}
</script>

View File

@ -101,7 +101,7 @@ onMounted(async () => {
margin-bottom: 12px;
}
@container (min-width: 451px) {
@container (min-width: 750px) {
.userInfo {
margin-bottom: 24px;
}

View File

@ -0,0 +1,57 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<!-- Based on MkLazy.vue -->
<template>
<div ref="rootEl" :class="$style.root">
<slot v-if="showing"></slot>
<div v-else :class="$style.placeholder"></div>
</div>
</template>
<script lang="ts" setup>
import { nextTick, onMounted, onActivated, onBeforeUnmount, ref, shallowRef } from 'vue';
const rootEl = shallowRef<HTMLDivElement>();
const showing = ref(false);
defineExpose({ rootEl, showing });
const observer = new IntersectionObserver(entries =>
showing.value = entries.some((entry) => entry.isIntersecting),
);
onMounted(() => {
nextTick(() => {
if (rootEl.value) {
observer.observe(rootEl.value);
}
});
});
onActivated(() => {
nextTick(() => {
if (rootEl.value) {
observer.observe(rootEl.value);
}
});
});
onBeforeUnmount(() => {
observer.disconnect();
});
</script>
<style lang="scss" module>
.root {
display: block;
}
.placeholder {
display: block;
min-height: 150px;
}
</style>

View File

@ -7,61 +7,41 @@ SPDX-License-Identifier: AGPL-3.0-only
<div :class="$style.root">
<div :class="$style.header">
<MkPageHeader v-model:tab="userList" :tabs="headerTabs" :actions="headerActions" :displayBackButton="true" @update:tab="onChangeTab"/>
<MkInfo v-if="showRemoteWarning" :class="$style.remoteWarning" warn closable @close="remoteWarningDismissed = true">{{ i18n.ts.remoteFollowersWarning }}</MkInfo>
<SkRemoteFollowersWarning :class="$style.remoteWarning" :model="model"/>
</div>
<div ref="noteScroll" :class="$style.notes">
<MkHorizontalSwipe v-model:tab="userList" :tabs="headerTabs">
<MkPullToRefresh :refresher="() => reloadLatestNotes()">
<MkPagination ref="latestNotesPaging" :pagination="latestNotesPagination" @init="onListReady">
<template #empty>
<div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost" :alt="i18n.ts.noNotes" aria-hidden="true"/>
<div>{{ i18n.ts.noNotes }}</div>
</div>
</template>
<template #default="{ items: notes }">
<MkDateSeparatedList v-slot="{ item: note }" :items="notes" :class="$style.panel" :noGap="true">
<SkFollowingFeedEntry v-if="!isHardMuted(note)" :isMuted="isSoftMuted(note)" :note="note" :class="selectedUserId == note.userId && $style.selected" @select="userSelected"/>
</MkDateSeparatedList>
</template>
</MkPagination>
</MkPullToRefresh>
<SkFollowingRecentNotes ref="followingRecentNotes" :selectedUserId="selectedUserId" :userList="userList" :withNonPublic="withNonPublic" :withQuotes="withQuotes" :withBots="withBots" :withReplies="withReplies" :onlyFiles="onlyFiles" @userSelected="userSelected" @loaded="listReady"/>
</MkHorizontalSwipe>
</div>
<div v-if="isWideViewport" ref="userScroll" :class="$style.user">
<SkLazy ref="userScroll" :class="$style.user">
<MkHorizontalSwipe v-if="selectedUserId" v-model:tab="userList" :tabs="headerTabs">
<SkUserRecentNotes ref="userRecentNotes" :userId="selectedUserId" :withNonPublic="withNonPublic" :withQuotes="withQuotes" :withBots="withBots" :withReplies="withReplies" :onlyFiles="onlyFiles"/>
</MkHorizontalSwipe>
</div>
</SkLazy>
</div>
</template>
<script lang="ts" setup>
import { computed, Ref, ref, shallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import { computed, ComputedRef, Ref, ref, shallowRef } from 'vue';
import { getScrollContainer } from '@@/js/scroll.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import { infoImageUrl } from '@/instance.js';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
import { Tab } from '@/components/global/MkPageHeader.tabs.vue';
import { PageHeaderItem } from '@/types/page-header.js';
import SkFollowingFeedEntry from '@/components/SkFollowingFeedEntry.vue';
import { useRouter } from '@/router/supplier.js';
import MkPageHeader from '@/components/global/MkPageHeader.vue';
import { $i } from '@/account.js';
import { checkWordMute } from '@/scripts/check-word-mute.js';
import SkUserRecentNotes from '@/components/SkUserRecentNotes.vue';
import { useScrollPositionManager } from '@/nirax.js';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkInfo from '@/components/MkInfo.vue';
import { createModel, createOptions, followersTab, followingTab, mutualsTab } from '@/scripts/following-feed-utils.js';
import { createModel, createHeaderItem, followingFeedTabs, followingTabIcon, followingTabName, followingTab } from '@/scripts/following-feed-utils.js';
import SkLazy from '@/components/global/SkLazy.vue';
import SkFollowingRecentNotes from '@/components/SkFollowingRecentNotes.vue';
import SkRemoteFollowersWarning from '@/components/SkRemoteFollowersWarning.vue';
const model = createModel();
const {
userList,
withNonPublic,
@ -69,141 +49,62 @@ const {
withBots,
withReplies,
onlyFiles,
remoteWarningDismissed,
} = createModel();
} = model;
const router = useRouter();
const userRecentNotes = shallowRef<InstanceType<typeof SkUserRecentNotes>>();
const userScroll = shallowRef<HTMLElement>();
const followingRecentNotes = shallowRef<InstanceType<typeof SkFollowingRecentNotes>>();
const userScroll = shallowRef<InstanceType<typeof SkLazy>>();
const noteScroll = shallowRef<HTMLElement>();
const showRemoteWarning = computed(() => userList.value === 'followers' && !remoteWarningDismissed.value);
// We have to disable the per-user feed on small displays, and it must be done through JS instead of CSS.
// Otherwise, the second column will waste resources in the background.
const wideViewportQuery = window.matchMedia('(min-width: 750px)');
const isWideViewport: Ref<boolean> = ref(wideViewportQuery.matches);
wideViewportQuery.addEventListener('change', () => isWideViewport.value = wideViewportQuery.matches);
const selectedUserId: Ref<string | null> = ref(null);
function userSelected(user: Misskey.entities.UserLite): void {
if (isWideViewport.value) {
selectedUserId.value = user.id;
} else {
router.push(`/following-feed/${user.id}`);
function listReady(initialUserId?: string): void {
if (initialUserId && !selectedUserId.value) {
selectedUserId.value = initialUserId;
}
}
async function reloadLatestNotes() {
await latestNotesPaging.value?.reload();
}
function userSelected(userId: string): void {
selectedUserId.value = userId;
async function reloadUserNotes() {
await userRecentNotes.value?.reload();
if (!userScroll.value?.showing) {
router.push(`/following-feed/${userId}`);
}
}
async function reload() {
await Promise.all([
reloadLatestNotes(),
reloadUserNotes(),
followingRecentNotes.value?.reload(),
userRecentNotes.value?.reload(),
]);
}
async function onListReady(): Promise<void> {
if (!selectedUserId.value && latestNotesPaging.value?.items.size) {
// This looks messy, but actually just gets the first user ID.
const selectedNote = latestNotesPaging.value.items.values().next().value;
// We know this to be non-null because of the size check above.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
selectedUserId.value = selectedNote!.userId;
}
}
async function onChangeTab(): Promise<void> {
selectedUserId.value = null;
}
function isSoftMuted(note: Misskey.entities.Note): boolean {
return isMuted(note, $i?.mutedWords);
}
function isHardMuted(note: Misskey.entities.Note): boolean {
return isMuted(note, $i?.hardMutedWords);
}
// Match the typing used by Misskey
type Mutes = (string | string[])[] | null | undefined;
// Adapted from MkNote.ts
function isMuted(note: Misskey.entities.Note, mutes: Mutes): boolean {
return checkMute(note, mutes)
|| checkMute(note.reply, mutes)
|| checkMute(note.renote, mutes);
}
// Adapted from check-word-mute.ts
function checkMute(note: Misskey.entities.Note | undefined | null, mutes: Mutes): boolean {
if (!note) {
return false;
}
if (!mutes || mutes.length < 1) {
return false;
}
return checkWordMute(note, $i, mutes);
}
const latestNotesPaging = shallowRef<InstanceType<typeof MkPagination>>();
const latestNotesPagination: Paging<'notes/following'> = {
endpoint: 'notes/following' as const,
limit: 20,
params: computed(() => ({
list: userList.value,
filesOnly: onlyFiles.value,
includeNonPublic: withNonPublic.value,
includeReplies: withReplies.value,
includeQuotes: withQuotes.value,
includeBots: withBots.value,
})),
};
const headerActions: PageHeaderItem[] = [
{
icon: 'ti ti-refresh',
text: i18n.ts.reload,
handler: () => reload(),
},
createOptions(),
createHeaderItem(),
];
const headerTabs = computed(() => [
{
key: followingTab,
icon: 'ph-user-check ph-bold ph-lg',
title: i18n.ts.following,
} satisfies Tab,
{
key: mutualsTab,
icon: 'ph-user-switch ph-bold ph-lg',
title: i18n.ts.mutuals,
} satisfies Tab,
{
key: followersTab,
icon: 'ph-user ph-bold ph-lg',
title: i18n.ts.followers,
} satisfies Tab,
]);
const headerTabs: ComputedRef<Tab[]> = computed(() => followingFeedTabs.map(t => ({
key: t,
icon: followingTabIcon(t),
title: followingTabName(t),
})));
useScrollPositionManager(() => getScrollContainer(userScroll.value ?? null), router);
useScrollPositionManager(() => getScrollContainer(userScroll.value?.rootEl ?? null), router);
useScrollPositionManager(() => getScrollContainer(noteScroll.value ?? null), router);
definePageMetadata(() => ({
title: i18n.ts.following,
icon: 'ph-user-check ph-bold ph-lg',
icon: followingTabIcon(followingTab),
}));
</script>
@ -257,22 +158,13 @@ definePageMetadata(() => ({
margin-bottom: 12px;
}
@keyframes border {
from {border-left: 0px solid var(--accent);}
to {border-left: 6px solid var(--accent);}
}
.selected {
animation: border 0.2s ease-out 0s 1 forwards;
&:first-child {
border-top-left-radius: 5px;
}
&:last-child {
border-bottom-left-radius: 5px;
@container (max-width: 749px) {
.user {
display: none;
}
}
@media (min-width: 750px) {
@container (min-width: 750px) {
.root {
grid-template-columns: min-content 4fr 6fr min-content;
grid-template-rows: min-content 1fr;
@ -290,8 +182,4 @@ definePageMetadata(() => ({
margin-bottom: 24px;
}
}
.panel {
background: var(--panel);
}
</style>

View File

@ -4,16 +4,15 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkStickyContainer ref="userScroll">
<MkStickyContainer>
<template #header>
<MkPageHeader :actions="headerActions" :displayBackButton="true"/>
</template>
<SkUserRecentNotes ref="userRecentNotes" :userId="userId" :withNonPublic="withNonPublic" :withQuotes="withQuotes" :withBots="withBots" :withReplies="withReplies" :onlyFiles="onlyFiles"/>
<SkUserRecentNotes ref="userRecentNotes" :class="$style.notes" :userId="userId" :withNonPublic="withNonPublic" :withQuotes="withQuotes" :withBots="withBots" :withReplies="withReplies" :onlyFiles="onlyFiles"/>
</MkStickyContainer>
</template>
<script setup lang="ts">
import { computed, shallowRef } from 'vue';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
@ -21,7 +20,7 @@ import { PageHeaderItem } from '@/types/page-header.js';
import MkPageHeader from '@/components/global/MkPageHeader.vue';
import SkUserRecentNotes from '@/components/SkUserRecentNotes.vue';
import { acct } from '@/filters/user.js';
import { createModel, createOptions } from '@/scripts/following-feed-utils.js';
import { createModel, createHeaderItem } from '@/scripts/following-feed-utils.js';
import MkStickyContainer from '@/components/global/MkStickyContainer.vue';
defineProps<{
@ -45,7 +44,7 @@ const headerActions: PageHeaderItem[] = [
text: i18n.ts.reload,
handler: () => userRecentNotes.value?.reload(),
},
createOptions(),
createHeaderItem(),
];
// Based on user/index.vue
@ -64,3 +63,17 @@ definePageMetadata(() => ({
} : {},
}));
</script>
<style lang="scss" module>
@container (min-width: 451px) {
.notes {
padding: 12px;
}
}
@container (min-width: 750px) {
.notes {
padding: 24px;
}
}
</style>

View File

@ -3,19 +3,75 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { computed } from 'vue';
import { computed, Ref, WritableComputedRef } from 'vue';
import { defaultStore } from '@/store.js';
import { deepMerge } from '@/scripts/merge.js';
import { PageHeaderItem } from '@/types/page-header.js';
import { i18n } from '@/i18n.js';
import { popupMenu } from '@/os.js';
import { MenuItem } from '@/types/menu.js';
export const followingTab = 'following' as const;
export const mutualsTab = 'mutuals' as const;
export const followersTab = 'followers' as const;
export type FollowingFeedTab = typeof followingTab | typeof mutualsTab | typeof followersTab;
export const followingFeedTabs = [followingTab, mutualsTab, followersTab] as const;
export type FollowingFeedTab = typeof followingFeedTabs[number];
export function createOptions(): PageHeaderItem {
export function followingTabName(tab: FollowingFeedTab): string;
export function followingTabName(tab: FollowingFeedTab | null | undefined): null;
export function followingTabName(tab: FollowingFeedTab | null | undefined): string | null {
if (tab === followingTab) return i18n.ts.following;
if (tab === followersTab) return i18n.ts.followers;
if (tab === mutualsTab) return i18n.ts.mutuals;
return null;
}
export function followingTabIcon(tab: FollowingFeedTab | null | undefined): string {
if (tab === followersTab) return 'ph-user ph-bold ph-lg';
if (tab === mutualsTab) return 'ph-user-switch ph-bold ph-lg';
return 'ph-user-check ph-bold ph-lg';
}
export type FollowingFeedModel = {
[Key in keyof FollowingFeedState]: WritableComputedRef<FollowingFeedState[Key]>;
}
export interface FollowingFeedState {
withNonPublic: boolean,
withQuotes: boolean,
withBots: boolean,
withReplies: boolean,
onlyFiles: boolean,
userList: FollowingFeedTab,
remoteWarningDismissed: boolean,
}
export const defaultFollowingFeedState: FollowingFeedState = {
withNonPublic: false,
withQuotes: false,
withBots: true,
withReplies: false,
onlyFiles: false,
userList: followingTab,
remoteWarningDismissed: false,
};
interface StorageInterface<T extends Partial<FollowingFeedState> = Partial<FollowingFeedState>> {
readonly state: Partial<T>;
readonly reactiveState: Ref<Partial<T>>;
save(updated: T): void;
}
export function createHeaderItem(storage?: Ref<StorageInterface>): PageHeaderItem {
const menu = createOptionsMenu(storage);
return {
icon: 'ti ti-dots',
text: i18n.ts.options,
handler: ev => popupMenu(menu, ev.currentTarget ?? ev.target),
};
}
export function createOptionsMenu(storage?: Ref<StorageInterface>): MenuItem[] {
const {
userList,
withNonPublic,
@ -23,80 +79,83 @@ export function createOptions(): PageHeaderItem {
withBots,
withReplies,
onlyFiles,
} = createModel();
} = createModel(storage);
return {
icon: 'ti ti-dots',
text: i18n.ts.options,
handler: ev =>
popupMenu([
{
type: 'switch',
text: i18n.ts.showNonPublicNotes,
ref: withNonPublic,
disabled: userList.value === 'followers',
},
{
type: 'switch',
text: i18n.ts.showQuotes,
ref: withQuotes,
},
{
type: 'switch',
text: i18n.ts.showBots,
ref: withBots,
},
{
type: 'switch',
text: i18n.ts.showReplies,
ref: withReplies,
disabled: onlyFiles,
},
{
type: 'divider',
},
{
type: 'switch',
text: i18n.ts.fileAttachedOnly,
ref: onlyFiles,
disabled: withReplies,
},
], ev.currentTarget ?? ev.target),
};
return [
{
type: 'switch',
text: i18n.ts.showNonPublicNotes,
ref: withNonPublic,
disabled: computed(() => userList.value === followersTab),
},
{
type: 'switch',
text: i18n.ts.showQuotes,
ref: withQuotes,
},
{
type: 'switch',
text: i18n.ts.showBots,
ref: withBots,
},
{
type: 'switch',
text: i18n.ts.showReplies,
ref: withReplies,
disabled: onlyFiles,
},
{
type: 'divider',
},
{
type: 'switch',
text: i18n.ts.fileAttachedOnly,
ref: onlyFiles,
disabled: withReplies,
},
];
}
export function createModel() {
const userList = computed({
get: () => defaultStore.reactiveState.followingFeed.value.userList,
export function createModel(storage?: Ref<StorageInterface>): FollowingFeedModel {
// eslint-disable-next-line no-param-reassign
storage ??= createDefaultStorage();
// Based on timeline.saveTlFilter()
const saveFollowingFilter = <K extends keyof FollowingFeedState>(key: K, value: FollowingFeedState[K]) => {
const state = deepMerge(storage.value.state, defaultFollowingFeedState);
const out = deepMerge({ [key]: value }, state);
storage.value.save(out);
};
const userList: WritableComputedRef<FollowingFeedTab> = computed({
get: () => storage.value.reactiveState.value.userList ?? defaultFollowingFeedState.userList,
set: value => saveFollowingFilter('userList', value),
});
const withNonPublic = computed({
const withNonPublic: WritableComputedRef<boolean> = computed({
get: () => {
if (userList.value === 'followers') return false;
return defaultStore.reactiveState.followingFeed.value.withNonPublic;
return storage.value.reactiveState.value.withNonPublic ?? defaultFollowingFeedState.withNonPublic;
},
set: value => saveFollowingFilter('withNonPublic', value),
});
const withQuotes = computed({
get: () => defaultStore.reactiveState.followingFeed.value.withQuotes,
const withQuotes: WritableComputedRef<boolean> = computed({
get: () => storage.value.reactiveState.value.withQuotes ?? defaultFollowingFeedState.withQuotes,
set: value => saveFollowingFilter('withQuotes', value),
});
const withBots = computed({
get: () => defaultStore.reactiveState.followingFeed.value.withBots,
const withBots: WritableComputedRef<boolean> = computed({
get: () => storage.value.reactiveState.value.withBots ?? defaultFollowingFeedState.withBots,
set: value => saveFollowingFilter('withBots', value),
});
const withReplies = computed({
get: () => defaultStore.reactiveState.followingFeed.value.withReplies,
const withReplies: WritableComputedRef<boolean> = computed({
get: () => storage.value.reactiveState.value.withReplies ?? defaultFollowingFeedState.withReplies,
set: value => saveFollowingFilter('withReplies', value),
});
const onlyFiles = computed({
get: () => defaultStore.reactiveState.followingFeed.value.onlyFiles,
const onlyFiles: WritableComputedRef<boolean> = computed({
get: () => storage.value.reactiveState.value.onlyFiles ?? defaultFollowingFeedState.onlyFiles,
set: value => saveFollowingFilter('onlyFiles', value),
});
const remoteWarningDismissed = computed({
get: () => defaultStore.reactiveState.followingFeed.value.remoteWarningDismissed,
const remoteWarningDismissed: WritableComputedRef<boolean> = computed({
get: () => storage.value.reactiveState.value.remoteWarningDismissed ?? defaultFollowingFeedState.remoteWarningDismissed,
set: value => saveFollowingFilter('remoteWarningDismissed', value),
});
@ -111,8 +170,12 @@ export function createModel() {
};
}
// Based on timeline.saveTlFilter()
function saveFollowingFilter<Key extends keyof typeof defaultStore.state.followingFeed>(key: Key, value: (typeof defaultStore.state.followingFeed)[Key]) {
const out = deepMerge({ [key]: value }, defaultStore.state.followingFeed);
return defaultStore.set('followingFeed', out);
function createDefaultStorage() {
return computed(() => ({
state: defaultStore.state.followingFeed,
reactiveState: defaultStore.reactiveState.followingFeed,
save(updated: typeof defaultStore.state.followingFeed) {
return defaultStore.set('followingFeed', updated);
},
}));
}

View File

@ -18,7 +18,7 @@ function isPureObject(value: unknown): value is Record<string | number | symbol,
* valueにないキーをdefからもらう\
* nullはそのままundefinedはdefの値
**/
export function deepMerge<X extends Record<string | number | symbol, unknown>>(value: DeepPartial<X>, def: X): X {
export function deepMerge<X extends object>(value: DeepPartial<X>, def: X): X {
if (isPureObject(value) && isPureObject(def)) {
const result = deepClone(value as Cloneable) as X;
for (const [k, v] of Object.entries(def) as [keyof X, X[keyof X]][]) {

View File

@ -11,7 +11,7 @@ import darkTheme from '@@/themes/d-ice.json5';
import { miLocalStorage } from './local-storage.js';
import { searchEngineMap } from './scripts/search-engine-map.js';
import type { SoundType } from '@/scripts/sound.js';
import type { FollowingFeedTab } from '@/scripts/following-feed-utils.js';
import { defaultFollowingFeedState } from '@/scripts/following-feed-utils.js';
import { Storage } from '@/pizzax.js';
interface PostFormAction {
@ -244,15 +244,7 @@ export const defaultStore = markRaw(new Storage('base', {
},
followingFeed: {
where: 'account',
default: {
withNonPublic: false,
withQuotes: false,
withBots: true,
withReplies: false,
onlyFiles: false,
userList: 'following' as FollowingFeedTab,
remoteWarningDismissed: false,
},
default: defaultFollowingFeedState,
},
overridedDeviceKind: {

View File

@ -18,16 +18,21 @@ SPDX-License-Identifier: AGPL-3.0-only
:style="columns.filter(c => ids.includes(c.id)).some(c => c.flexible) ? { flex: 1, minWidth: '350px' } : { width: Math.max(...columns.filter(c => ids.includes(c.id)).map(c => c.width)) + 'px' }"
@wheel.self="onWheel"
>
<component
:is="columnComponents[columns.find(c => c.id === id)!.type] ?? XTlColumn"
v-for="id in ids"
:ref="id"
:key="id"
:class="$style.column"
:column="columns.find(c => c.id === id)!"
:isStacked="ids.length > 1"
@headerWheel="onWheel"
/>
<Suspense>
<component
:is="columnComponents[columns.find(c => c.id === id)!.type] ?? XTlColumn"
v-for="id in ids"
:ref="id"
:key="id"
:class="$style.column"
:column="columns.find(c => c.id === id)!"
:isStacked="ids.length > 1"
@headerWheel="onWheel"
/>
<template #fallback>
<MkLoading/>
</template>
</Suspense>
</section>
<div v-if="layout.length === 0" class="_panel" :class="$style.onboarding">
<div>{{ i18n.ts._deck.introduction }}</div>
@ -117,6 +122,7 @@ import XWidgetsColumn from '@/ui/deck/widgets-column.vue';
import XMentionsColumn from '@/ui/deck/mentions-column.vue';
import XDirectColumn from '@/ui/deck/direct-column.vue';
import XRoleTimelineColumn from '@/ui/deck/role-timeline-column.vue';
import XFollowingColumn from '@/ui/deck/following-column.vue';
import { mainRouter } from '@/router/main.js';
import type { MenuItem } from '@/types/menu.js';
const XStatusBars = defineAsyncComponent(() => import('@/ui/_common_/statusbars.vue'));
@ -133,6 +139,7 @@ const columnComponents = {
mentions: XMentionsColumn,
direct: XDirectColumn,
roleTimeline: XRoleTimelineColumn,
following: XFollowingColumn,
};
mainRouter.navHook = (path, flag): boolean => {

View File

@ -4,7 +4,7 @@
*/
import { throttle } from 'throttle-debounce';
import { markRaw } from 'vue';
import { computed, markRaw, Ref } from 'vue';
import { notificationTypes } from 'misskey-js';
import type { BasicTimelineType } from '@/timelines.js';
import { Storage } from '@/pizzax.js';
@ -29,6 +29,7 @@ export const columnTypes = [
'mentions',
'direct',
'roleTimeline',
'following',
] as const;
export type ColumnType = typeof columnTypes[number];
@ -112,8 +113,8 @@ export const loadDeck = async () => {
};
// TODO: deckがloadされていない状態でsaveすると意図せず上書きが発生するので対策する
export const saveDeck = throttle(1000, () => {
misskeyApi('i/registry/set', {
export const saveDeck = throttle(1000, async () => {
await misskeyApi('i/registry/set', {
scope: ['client', 'deck', 'profiles'],
key: deckStore.state.profile,
value: {
@ -313,7 +314,7 @@ export function updateColumnWidget(id: Column['id'], widgetId: string, widgetDat
saveDeck();
}
export function updateColumn(id: Column['id'], column: Partial<Column>) {
export async function updateColumn<TColumn>(id: Column['id'], column: Partial<TColumn>) {
const columns = deepClone(deckStore.state.columns);
const columnIndex = deckStore.state.columns.findIndex(c => c.id === id);
const currentColumn = deepClone(deckStore.state.columns[columnIndex]);
@ -322,6 +323,18 @@ export function updateColumn(id: Column['id'], column: Partial<Column>) {
currentColumn[k] = v;
}
columns[columnIndex] = currentColumn;
deckStore.set('columns', columns);
saveDeck();
await Promise.all([
deckStore.set('columns', columns),
saveDeck(),
]);
}
export function getColumn<TColumn extends Column>(id: Column['id']): TColumn {
return deckStore.state.columns.find(c => c.id === id) as TColumn;
}
export function getReactiveColumn<TColumn extends Column>(id: Column['id']): Ref<TColumn> {
return computed(() => {
return deckStore.reactiveState.columns.value.find(c => c.id === id) as TColumn;
});
}

View File

@ -0,0 +1,124 @@
<!--
SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<!-- based on list-column.vue -->
<template>
<XColumn :menu="menu" :column="column" :isStacked="isStacked" :refresher="reload">
<template #header>
<i :class="columnIcon" aria-hidden="true"/><span style="margin-left: 8px;">{{ column.name }}</span>
</template>
<SkRemoteFollowersWarning :class="$style.followersWarning" :model="model"/>
<SkFollowingRecentNotes ref="latestNotes" :userList="userList" :withNonPublic="withNonPublic" :withQuotes="withQuotes" :withReplies="withReplies" :withBots="withBots" :onlyFiles="onlyFiles" @userSelected="userSelected"/>
</XColumn>
</template>
<script lang="ts">
import { computed, shallowRef } from 'vue';
import type { Column } from '@/ui/deck/deck-store.js';
import type { FollowingFeedState } from '@/scripts/following-feed-utils.js';
export type FollowingColumn = Column & Partial<FollowingFeedState>;
</script>
<script setup lang="ts">
import { getColumn, getReactiveColumn, updateColumn } from '@/ui/deck/deck-store.js';
import XColumn from '@/ui/deck/column.vue';
import SkFollowingRecentNotes from '@/components/SkFollowingRecentNotes.vue';
import SkRemoteFollowersWarning from '@/components/SkRemoteFollowersWarning.vue';
import { createModel, createOptionsMenu, FollowingFeedTab, followingTab, followingTabName, followingTabIcon, followingFeedTabs } from '@/scripts/following-feed-utils.js';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { MenuItem } from '@/types/menu.js';
import { useRouter } from '@/router/supplier.js';
const props = defineProps<{
column: FollowingColumn;
isStacked: boolean;
}>();
const columnIcon = computed(() => followingTabIcon(props.column.userList));
async function selectList(): Promise<void> {
const { canceled, result: newList } = await os.select<FollowingFeedTab>({
title: i18n.ts.selectFollowRelationship,
items: followingFeedTabs.map(t => ({
value: t,
text: followingTabName(t),
})),
default: props.column.userList ?? followingTab,
});
if (canceled) return;
await updateColumn(props.column.id, {
name: getNewColumnName(newList),
userList: newList,
});
}
function getNewColumnName(newList: FollowingFeedTab) {
// If the user has renamed the column, then we need to keep that name.
// If no list is specified, then the column is newly created and the user *can't* have renamed it.
if (props.column.userList && props.column.name === followingTabName(props.column.userList)) {
return props.column.name;
}
// Otherwise, we should match the name to the selected list.
return followingTabName(newList);
}
if (!props.column.userList) {
await selectList();
}
// Redirects the Following Feed logic into column-specific storage.
// This allows multiple columns to exist with different settings.
const columnStorage = computed(() => ({
state: getColumn<FollowingColumn>(props.column.id),
reactiveState: getReactiveColumn<FollowingColumn>(props.column.id),
save(updated: FollowingColumn) {
updateColumn(props.column.id, updated);
},
}));
const model = createModel(columnStorage);
const {
userList,
withNonPublic,
withQuotes,
withReplies,
withBots,
onlyFiles,
} = model;
const menu: MenuItem[] = [
{
icon: columnIcon.value,
text: i18n.ts.selectFollowRelationship,
action: selectList,
},
...createOptionsMenu(columnStorage),
];
const latestNotes = shallowRef<InstanceType<typeof SkFollowingRecentNotes>>();
async function reload() {
await latestNotes.value?.reload();
}
const router = useRouter();
function userSelected(userId: string) {
router.push(`/following-feed/${userId}`);
}
</script>
<style lang="scss" module>
.followersWarning {
margin-bottom: 8px;
border-radius: 0;
}
</style>

View File

@ -397,3 +397,8 @@ _auth:
allowed: "Allowed"
_announcement:
new: "New"
_deck:
_columns:
following: "Following"
selectFollowRelationship: "Select a follow relationship..."