Skip to content

Commit

Permalink
enhance: フォローしているユーザーなら鍵ノートでもアンテナにひっかかるように
Browse files Browse the repository at this point in the history
Cherry-picked from team-shahu/misskey#38

# Conflicts:
#	packages/backend/src/core/AntennaService.ts

Co-authored-by: mai <[email protected]>
  • Loading branch information
kozakura913 and chan-mai committed Dec 12, 2024
1 parent 869c8cf commit 61560c7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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';
Expand Down Expand Up @@ -41,6 +41,9 @@ export class AntennaService implements OnApplicationShutdown {
@Inject(DI.userListMembershipsRepository)
private userListMembershipsRepository: UserListMembershipsRepository,

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

private utilityService: UtilityService,
private globalEventService: GlobalEventService,
private fanoutTimelineService: FanoutTimelineService,
Expand Down Expand Up @@ -99,8 +102,22 @@ 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 = await this.followingsRepository.count({
where: {
followerId: antenna.userId,
followeeId: note.userId,
},
take: 1,
}).then(n => n > 0);
if (!isFollowing && antenna.userId !== note.userId) return false;
}

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

Expand Down

0 comments on commit 61560c7

Please sign in to comment.