Skip to content

Commit

Permalink
Merge pull request #23 from team-shahu/feat/muted-reaction
Browse files Browse the repository at this point in the history
feat: リアクションした人一覧がブロック・ミュートを考慮するようにする設定
  • Loading branch information
chan-mai authored Sep 11, 2024
2 parents 2bbef4d + 9d5fdb9 commit 9c5f216
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- アバターデコレーションをmisskeyUI上から登録できるように https://github.com/team-shahu/misskey/pull/12
- TL上のサーバー情報をアイコン表示に切り替えられるように https://github.com/team-shahu/misskey/pull/13
- 特定のロールにのみお知らせを発行する機能 https://github.com/team-shahu/misskey/pull/18
- リアクションした人一覧がブロック・ミュートを考慮するようにする設定 https://github.com/team-shahu/misskey/pull/23

## Special Thanks
- [Misskey](https://github.com/misskey-dev/misskey)
Expand Down
3 changes: 3 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2663,3 +2663,6 @@ _contextMenu:
app: "Application"
appWithShift: "Application with shift key"
native: "Native"
_reactionChecksMuting:
title: "Check mutings when get reactions"
caption: "Check mutings when get reactions, but cache does not work and may increase traffic"
10 changes: 10 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10285,6 +10285,16 @@ export interface Locale extends ILocale {
*/
"native": string;
};
"_reactionChecksMuting": {
/**
* リアクションでミュートを考慮する
*/
"title": string;
/**
* リアクションがミュートを考慮しますが、キャッシュが効かず通信量が増えることがあります。
*/
"caption": string;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
4 changes: 4 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2741,3 +2741,7 @@ _contextMenu:
app: "アプリケーション"
appWithShift: "Shiftキーでアプリケーション"
native: "ブラウザのUI"

_reactionChecksMuting:
title: "リアクションでミュートを考慮する"
caption: "リアクションがミュートを考慮しますが、キャッシュが効かず通信量が増えることがあります。"
13 changes: 11 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/reactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
*/

import { Inject, Injectable } from '@nestjs/common';
import { Brackets, type FindOptionsWhere } from 'typeorm';
import type { NoteReactionsRepository } from '@/models/_.js';
import type { MiNoteReaction } from '@/models/NoteReaction.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteReactionEntityService } from '@/core/entities/NoteReactionEntityService.js';
import { DI } from '@/di-symbols.js';
import { QueryService } from '@/core/QueryService.js';
import { CacheService } from '@/core/CacheService.js';

export const meta = {
tags: ['notes', 'reactions'],
Expand Down Expand Up @@ -59,13 +58,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

private noteReactionEntityService: NoteReactionEntityService,
private queryService: QueryService,
private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.noteReactionsRepository.createQueryBuilder('reaction'), ps.sinceId, ps.untilId)
.andWhere('reaction.noteId = :noteId', { noteId: ps.noteId })
.leftJoinAndSelect('reaction.user', 'user')
.leftJoinAndSelect('reaction.note', 'note');

if (me != null) {
const [userIdsWhoMeMuting, userIdsWhoBlockingMe] = await Promise.all([
this.cacheService.userMutingsCache.get(me.id),
this.cacheService.userBlockedCache.get(me.id),
]);

query.andWhere('reaction.userId NOT IN (:...userIds)', { userIds: Array.from(userIdsWhoMeMuting ?? []).concat(Array.from(userIdsWhoBlockingMe ?? [])) });
}

if (ps.type) {
// ローカルリアクションはホスト名が . とされているが
// DB 上ではそうではないので、必要に応じて変換
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkAvatar :class="$style.avatar" :user="u"/>
<MkUserName :user="u" :nowrap="true"/>
</div>
<div v-if="count <= 0" :class="$style.user"> {{ i18n.ts.noUsers }} </div>
<div v-if="count > 10" :class="$style.more">+{{ count - 10 }}</div>
</div>
</div>
Expand All @@ -26,6 +27,7 @@ import { } from 'vue';
import MkTooltip from './MkTooltip.vue';
import MkReactionIcon from '@/components/MkReactionIcon.vue';
import { getEmojiName } from '@/scripts/emojilist.js';
import { i18n } from '@/i18n';

defineProps<{
showing: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { checkReactionPermissions } from '@/scripts/check-reaction-permissions.j
import { customEmojisMap } from '@/custom-emojis.js';
import { getUnicodeEmoji } from '@/scripts/emojilist.js';

const reactionChecksMuting = computed(defaultStore.makeGetterSetter('reactionChecksMuting'));

const props = defineProps<{
reaction: string;
count: number;
Expand Down Expand Up @@ -146,20 +148,23 @@ onMounted(() => {

if (!mock) {
useTooltip(buttonEl, async (showing) => {
const reactions = await misskeyApiGet('notes/reactions', {
const useGet = !reactionChecksMuting.value;
const apiCall = useGet ? misskeyApiGet : misskeyApi;
const reactions = await apiCall('notes/reactions', {
noteId: props.note.id,
type: props.reaction,
limit: 10,
_cacheKey_: props.count,
});

const users = reactions.map(x => x.user);
const count = users.length;

const { dispose } = os.popup(XDetails, {
showing,
reaction: props.reaction,
users,
count: props.count,
count,
targetElement: buttonEl.value,
}, {
closed: () => dispose(),
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/pages/settings/general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="enableHorizontalSwipe">{{ i18n.ts.enableHorizontalSwipe }}</MkSwitch>
<MkSwitch v-model="alwaysConfirmFollow">{{ i18n.ts.alwaysConfirmFollow }}</MkSwitch>
<MkSwitch v-model="confirmWhenRevealingSensitiveMedia">{{ i18n.ts.confirmWhenRevealingSensitiveMedia }}</MkSwitch>

<MkSwitch v-model="reactionChecksMuting">
{{ i18n.ts._reactionChecksMuting.title }}<span class="_beta">{{ i18n.ts.nadesskey }}</span>
<template #caption>{{ i18n.ts._reactionChecksMuting.caption }}</template>
</MkSwitch>
</div>
<MkSelect v-model="serverDisconnectedBehavior">
<template #label>{{ i18n.ts.whenServerDisconnected }}</template>
Expand Down Expand Up @@ -336,6 +341,7 @@ const useNativeUIForVideoAudioPlayer = computed(defaultStore.makeGetterSetter('u
const alwaysConfirmFollow = computed(defaultStore.makeGetterSetter('alwaysConfirmFollow'));
const confirmWhenRevealingSensitiveMedia = computed(defaultStore.makeGetterSetter('confirmWhenRevealingSensitiveMedia'));
const contextMenu = computed(defaultStore.makeGetterSetter('contextMenu'));
const reactionChecksMuting = computed(defaultStore.makeGetterSetter('reactionChecksMuting'));

watch(lang, () => {
miLocalStorage.setItem('lang', lang.value as string);
Expand Down
8 changes: 6 additions & 2 deletions packages/frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device',
default: false,
},
contextMenu: {
contextMenu: {
where: 'device',
default: 'app' as 'app' | 'appWithShift' | 'native',
},
},

sound_masterVolume: {
where: 'device',
Expand Down Expand Up @@ -517,6 +517,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device',
default: { type: 'syuilo/bubble2', volume: 1 } as SoundStore,
},
reactionChecksMuting: {
where: 'device',
default: true,
},
}));

// TODO: 他のタブと永続化されたstateを同期
Expand Down

0 comments on commit 9c5f216

Please sign in to comment.