mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 10:03:09 +02:00
d071d18dd7
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { User } from '@/models/entities/user.js';
|
|
import { Followings } from '@/models/index.js';
|
|
import { Brackets, SelectQueryBuilder } from 'typeorm';
|
|
|
|
export function generateVisibilityQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null) {
|
|
if (me == null) {
|
|
q.andWhere(new Brackets(qb => { qb
|
|
.where(`note.visibility = 'public'`)
|
|
.orWhere(`note.visibility = 'home'`);
|
|
}));
|
|
} else {
|
|
const followingQuery = Followings.createQueryBuilder('following')
|
|
.select('following.followeeId')
|
|
.where('following.followerId = :followerId', { followerId: me.id });
|
|
|
|
q.andWhere(new Brackets(qb => { qb
|
|
// 公開投稿である
|
|
.where(new Brackets(qb => { qb
|
|
.where(`note.visibility = 'public'`)
|
|
.orWhere(`note.visibility = 'home'`);
|
|
}))
|
|
// または 自分自身
|
|
.orWhere('note.userId = :userId1', { userId1: me.id })
|
|
// または 自分宛て
|
|
.orWhere(`'{"${me.id}"}' <@ note.visibleUserIds`)
|
|
.orWhere(new Brackets(qb => { qb
|
|
// または フォロワー宛ての投稿であり、
|
|
.where('note.visibility = \'followers\'')
|
|
.andWhere(new Brackets(qb => { qb
|
|
// 自分がフォロワーである
|
|
.where(`note.userId IN (${ followingQuery.getQuery() })`)
|
|
// または 自分の投稿へのリプライ
|
|
.orWhere('note.replyUserId = :userId3', { userId3: me.id });
|
|
}));
|
|
}));
|
|
}));
|
|
|
|
q.setParameters(followingQuery.getParameters());
|
|
}
|
|
}
|