feat(frontend/reactions): リアクションのミュートで通知からもミュートされるように (MisskeyIO#771)

This commit is contained in:
あわわわとーにゅ 2024-10-21 09:34:33 +09:00 committed by hijiki
parent a51e0abc3c
commit c3fe5bd6d7
4 changed files with 29 additions and 2 deletions

View File

@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<MkPullToRefresh :refresher="() => reload()"> <MkPullToRefresh :refresher="() => reload()">
<MkPagination ref="pagingComponent" :pagination="pagination"> <MkPagination ref="pagingComponent" :pagination="pagination" :filter="filterMutedNotification">
<template #empty> <template #empty>
<div class="_fullinfo"> <div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost"/> <img :src="infoImageUrl" class="_ghost"/>
@ -33,6 +33,7 @@ import { i18n } from '@/i18n.js';
import { notificationTypes } from '@/const.js'; import { notificationTypes } from '@/const.js';
import { infoImageUrl } from '@/instance.js'; import { infoImageUrl } from '@/instance.js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
import { filterMutedNotification } from '@/scripts/filter-muted-notification.js';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue'; import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
@ -68,7 +69,7 @@ function onNotification(notification) {
useStream().send('readNotification'); useStream().send('readNotification');
} }
if (!isMuted) { if (!isMuted && filterMutedNotification(notification)) {
pagingComponent.value?.prepend(notification); pagingComponent.value?.prepend(notification);
} }
} }

View File

@ -97,6 +97,7 @@ const props = withDefaults(defineProps<{
pagination: Paging; pagination: Paging;
disableAutoLoad?: boolean; disableAutoLoad?: boolean;
displayLimit?: number; displayLimit?: number;
filter?: (item: MisskeyEntity) => boolean;
}>(), { }>(), {
displayLimit: 20, displayLimit: 20,
}); });
@ -215,6 +216,8 @@ async function init(): Promise<void> {
limit: props.pagination.limit ?? 10, limit: props.pagination.limit ?? 10,
allowPartial: true, allowPartial: true,
}).then(res => { }).then(res => {
res = res.filter(item => !props.filter || props.filter(item));
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const item = res[i]; const item = res[i];
if (i === 3) item._shouldInsertAd_ = true; if (i === 3) item._shouldInsertAd_ = true;
@ -256,6 +259,8 @@ const fetchMore = async (): Promise<void> => {
untilId: Array.from(items.value.keys()).at(-1), untilId: Array.from(items.value.keys()).at(-1),
}), }),
}).then(res => { }).then(res => {
res = res.filter(item => !props.filter || props.filter(item));
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const item = res[i]; const item = res[i];
if (i === 10) item._shouldInsertAd_ = true; if (i === 10) item._shouldInsertAd_ = true;
@ -321,6 +326,8 @@ const fetchMoreAhead = async (): Promise<void> => {
sinceId: Array.from(items.value.keys()).at(-1), sinceId: Array.from(items.value.keys()).at(-1),
}), }),
}).then(res => { }).then(res => {
res = res.filter(item => !props.filter || props.filter(item));
if (res.length === 0) { if (res.length === 0) {
items.value = concatMapWithArray(items.value, res); items.value = concatMapWithArray(items.value, res);
more.value = false; more.value = false;

View File

@ -0,0 +1,16 @@
import * as Misskey from 'misskey-js';
import { defaultStore } from '@/store.js';
export function filterMutedNotification(notification: Misskey.entities.Notification): boolean {
switch (notification.type) {
case 'reaction':
if (defaultStore.state.mutedReactions.includes(notification.reaction.replace('@.', ''))) return false;
break;
case 'reaction:grouped':
notification.reactions = notification.reactions.filter(reaction => !defaultStore.state.mutedReactions.includes(reaction.reaction.replace('@.', '')));
if (notification.reactions.length === 0) return false;
break;
}
return true;
}

View File

@ -53,6 +53,7 @@ import { swInject } from './sw-inject.js';
import XNotification from './notification.vue'; import XNotification from './notification.vue';
import { popups } from '@/os.js'; import { popups } from '@/os.js';
import { pendingApiRequestsCount } from '@/scripts/misskey-api.js'; import { pendingApiRequestsCount } from '@/scripts/misskey-api.js';
import { filterMutedNotification } from '@/scripts/filter-muted-notification.js';
import { uploads } from '@/scripts/upload.js'; import { uploads } from '@/scripts/upload.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';
@ -77,6 +78,8 @@ function onNotification(notification: Misskey.entities.Notification, isClient =
useStream().send('readNotification'); useStream().send('readNotification');
} }
if (!filterMutedNotification(notification)) return;
notifications.value.unshift(notification); notifications.value.unshift(notification);
window.setTimeout(() => { window.setTimeout(() => {
if (notifications.value.length > 3) notifications.value.pop(); if (notifications.value.length > 3) notifications.value.pop();