Skip to content

Commit

Permalink
フォローしているユーザーなら鍵ノートでもアンテナにひっかかるように (#568)
Browse files Browse the repository at this point in the history
Co-authored-by: mai <[email protected]>
  • Loading branch information
kozakura913 and chan-mai authored Dec 26, 2024
1 parent 84f0f47 commit 29bd161
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.3.0

### Release Date

### General

### Client

### Server
- Feat: フォローしているユーザーなら鍵ノートでもアンテナにひっかかるように [#568](https://github.com/yojo-art/cherrypick/pull/568)
- based-on https://github.com/team-shahu/misskey/pull/38

## 1.2.2
Cherrypick 4.13.0
Misskey 2024.10.1
Expand Down
19 changes: 16 additions & 3 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
import * as Acct from '@/misc/acct.js';
import type { Packed } from '@/misc/json-schema.js';
import { DI } from '@/di-symbols.js';
import type { AntennasRepository, UserGroupJoiningsRepository, UserListMembershipsRepository } from '@/models/_.js';
import type { AntennasRepository, UserGroupJoiningsRepository, UserListMembershipsRepository, FollowingsRepository } from '@/models/_.js';
import { UtilityService } from '@/core/UtilityService.js';
import { bindThis } from '@/decorators.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { CacheService } from '@/core/CacheService.js';
import { deserializeAntenna } from './deserializeAntenna.js';
import type { OnApplicationShutdown } from '@nestjs/common';

Expand All @@ -41,6 +42,10 @@ export class AntennaService implements OnApplicationShutdown {
@Inject(DI.userListMembershipsRepository)
private userListMembershipsRepository: UserListMembershipsRepository,

@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,

private cacheService: CacheService,
private utilityService: UtilityService,
private globalEventService: GlobalEventService,
private fanoutTimelineService: FanoutTimelineService,
Expand Down Expand Up @@ -99,8 +104,16 @@ export class AntennaService implements OnApplicationShutdown {

@bindThis
public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; isBot: boolean; }): Promise<boolean> {
if (note.visibility === 'specified') return false;
if (note.visibility === 'followers') return false;
if (note.visibility === 'specified') {
if (note.userId !== antenna.userId) {
if (note.visibleUserIds == null) return false;
if (!note.visibleUserIds.includes(antenna.userId)) return false;
}
}
if (note.visibility === 'followers') {
const isFollowing = Object.hasOwn(await this.cacheService.userFollowingsCache.fetch(antenna.userId), note.userId);
if (!isFollowing && antenna.userId !== note.userId) return false;
}

if (antenna.excludeBots && noteUser.isBot) return false;

Expand Down
19 changes: 16 additions & 3 deletions packages/backend/test/e2e/antennas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,26 @@ describe('アンテナ', () => {
},
{
// https://github.com/misskey-dev/misskey/issues/9025
label: 'ただし、フォロワー限定投稿とDM投稿を含まない。フォロワーであっても。',
// https://github.com/yojo-art/cherrypick/pull/568
label: 'フォロワー限定投稿とDM投稿を含む',
parameters: () => ({}),
posts: [
{ note: (): Promise<Note> => post(userFollowedByAlice, { text: `${keyword}`, visibility: 'public' }), included: true },
{ note: (): Promise<Note> => post(userFollowedByAlice, { text: `${keyword}`, visibility: 'home' }), included: true },
{ note: (): Promise<Note> => post(userFollowedByAlice, { text: `${keyword}`, visibility: 'followers' }) },
{ note: (): Promise<Note> => post(userFollowedByAlice, { text: `${keyword}`, visibility: 'specified', visibleUserIds: [alice.id] }) },
{ note: (): Promise<Note> => post(userFollowedByAlice, { text: `${keyword}`, visibility: 'followers' }), included: true },
{ note: (): Promise<Note> => post(bob, { text: `${keyword}`, visibility: 'specified', visibleUserIds: [alice.id] }), included: true },
],
},
{
// https://github.com/misskey-dev/misskey/issues/9025
// https://github.com/yojo-art/cherrypick/pull/568
label: 'フォロワー限定投稿とDM投稿を含まない',
parameters: () => ({}),
posts: [
{ note: (): Promise<Note> => post(bob, { text: `${keyword}`, visibility: 'public' }), included: true },
{ note: (): Promise<Note> => post(bob, { text: `${keyword}`, visibility: 'home' }), included: true },
{ note: (): Promise<Note> => post(bob, { text: `${keyword}`, visibility: 'followers' }) },
{ note: (): Promise<Note> => post(bob, { text: `${keyword}`, visibility: 'specified', visibleUserIds: [carol.id] }) },
],
},
{
Expand Down

0 comments on commit 29bd161

Please sign in to comment.