Skip to content

Commit

Permalink
feat(timeline): no blocking user on my timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
SWREI committed Aug 27, 2024
1 parent 3891ea6 commit c513c85
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/backend/src/core/FanoutTimelineEndpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@ export class FanoutTimelineEndpointService {
const [
userIdsWhoMeMuting,
userIdsWhoMeMutingRenotes,
userIdsMeBlocking,
userIdsWhoBlockingMe,
userMutedInstances,
] = await Promise.all([
this.cacheService.userMutingsCache.fetch(ps.me.id),
this.cacheService.renoteMutingsCache.fetch(ps.me.id),
this.cacheService.userBlockingCache.fetch(ps.me.id),
this.cacheService.userBlockedCache.fetch(ps.me.id),
this.cacheService.userProfileCache.fetch(me.id).then(p => new Set(p.mutedInstances)),
]);

const parentFilter = filter;
filter = (note) => {
if (isUserRelated(note, userIdsWhoBlockingMe, ps.ignoreAuthorFromBlock)) return false;
if (isUserRelated(note, userIdsMeBlocking, ps.ignoreAuthorFromMute || ps.ignoreAuthorFromBlock)) return false;
if (isUserRelated(note, userIdsWhoMeMuting, ps.ignoreAuthorFromMute)) return false;
if (!ps.ignoreAuthorFromMute && isRenote(note) && !isQuote(note) && userIdsWhoMeMutingRenotes.has(note.userId)) return false;
if (isInstanceMuted(note, userMutedInstances)) return false;
Expand Down
38 changes: 32 additions & 6 deletions packages/backend/src/core/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ export class QueryService {
q.setParameters(blockingQuery.getParameters());
}

// ここでいうBlockedは被Blockedの意
@bindThis
public generateBlockingUserQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockeeId')
.where('blocking.blockerId = :blockerId', { blockerId: me.id });

// 投稿の作者にブロックされていない かつ
// 投稿の返信先の作者にブロックされていない かつ
// 投稿の引用元の作者にブロックされていない
q
.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`)
.andWhere(new Brackets(qb => {
qb
.where('note.replyUserId IS NULL')
.orWhere(`note.replyUserId NOT IN (${ blockingQuery.getQuery() })`);
}))
.andWhere(new Brackets(qb => {
qb
.where('note.renoteUserId IS NULL')
.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
}));

q.setParameters(blockingQuery.getParameters());
}

@bindThis
public generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
Expand Down Expand Up @@ -203,26 +229,26 @@ export class QueryService {

q.andWhere(new Brackets(qb => {
qb
// 公開投稿である
// 公開投稿である
.where(new Brackets(qb => {
qb
.where('note.visibility = \'public\'')
.orWhere('note.visibility = \'home\'');
}))
// または 自分自身
// または 自分自身
.orWhere('note.userId = :meId')
// または 自分宛て
// または 自分宛て
.orWhere(':meIdAsList <@ note.visibleUserIds')
.orWhere(':meIdAsList <@ note.mentions')
.orWhere(new Brackets(qb => {
qb
// または フォロワー宛ての投稿であり、
// または フォロワー宛ての投稿であり、
.where('note.visibility = \'followers\'')
.andWhere(new Brackets(qb => {
qb
// 自分がフォロワーである
// 自分がフォロワーである
.where(`note.userId IN (${ followingQuery.getQuery() })`)
// または 自分の投稿へのリプライ
// または 自分の投稿へのリプライ
.orWhere('note.replyUserId = :meId');
}));
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

if (me) {
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
}
//#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

if (me) {
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
this.queryService.generateMutedUserRenotesQueryForNotes(query, me);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

this.queryService.generateVisibilityQuery(query, me);
if (me) this.queryService.generateMutedUserQuery(query, me);
if (me) this.queryService.generateBlockingUserQuery(query, me);
if (me) this.queryService.generateBlockedUserQuery(query, me);
if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateMutedUserRenotesQueryForNotes(query, me);

if (ps.includeMyRenotes === false) {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateVisibilityQuery(query, me);
if (me) {
this.queryService.generateMutedUserQuery(query, me, { id: ps.userId });
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
}

Expand Down

0 comments on commit c513c85

Please sign in to comment.