wip
This commit is contained in:
parent
714d3f6977
commit
4e10e94efd
@ -41,65 +41,6 @@ export class UserRepository extends Repository<User> {
|
||||
public validateBirthday = ajv.compile(this.birthdaySchema);
|
||||
//#endregion
|
||||
|
||||
private suspendedUsersCache: Set<User['id']> = new Set();
|
||||
private silencedUsersCache: Set<User['id']> = new Set();
|
||||
private moderatorsCache: Set<User['id']> = new Set();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
const fetchCache = () => {
|
||||
this.find({
|
||||
where: {
|
||||
isSuspended: true,
|
||||
},
|
||||
select: ['id'],
|
||||
}).then(users => {
|
||||
this.suspendedUsersCache = new Set(users.map(user => user.id));
|
||||
});
|
||||
|
||||
this.find({
|
||||
where: {
|
||||
isSilenced: true,
|
||||
},
|
||||
select: ['id'],
|
||||
}).then(users => {
|
||||
this.silencedUsersCache = new Set(users.map(user => user.id));
|
||||
});
|
||||
|
||||
this.find({
|
||||
where: [{
|
||||
isAdmin: true,
|
||||
}, {
|
||||
isModerator: true,
|
||||
}],
|
||||
select: ['id'],
|
||||
}).then(users => {
|
||||
this.moderatorsCache = new Set(users.map(user => user.id));
|
||||
});
|
||||
};
|
||||
|
||||
setImmediate(() => {
|
||||
fetchCache();
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
fetchCache();
|
||||
}, 1000 * 60 * 5);
|
||||
}
|
||||
|
||||
public checkSuspended(userId: User['id']): boolean {
|
||||
return this.suspendedUsersCache.has(userId);
|
||||
}
|
||||
|
||||
public checkSilenced(userId: User['id']): boolean {
|
||||
return this.silencedUsersCache.has(userId);
|
||||
}
|
||||
|
||||
public checkModerator(userId: User['id']): boolean {
|
||||
return this.moderatorsCache.has(userId);
|
||||
}
|
||||
|
||||
public async getRelation(me: User['id'], target: User['id']) {
|
||||
const [following1, following2, followReq1, followReq2, toBlocking, fromBlocked, mute] = await Promise.all([
|
||||
Followings.findOne({
|
||||
|
@ -18,6 +18,10 @@ const logger = apLogger;
|
||||
export default async function(resolver: Resolver, actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
|
||||
const uri = getApId(activity);
|
||||
|
||||
if (actor.isSuspended) {
|
||||
return;
|
||||
}
|
||||
|
||||
// アナウンス先をブロックしてたら中断
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(extractDbHost(uri))) return;
|
||||
|
@ -38,7 +38,7 @@ export async function performActivity(actor: CacheableRemoteUser, activity: IObj
|
||||
}
|
||||
|
||||
async function performOneActivity(actor: CacheableRemoteUser, activity: IObject): Promise<void> {
|
||||
if (Users.checkSuspended(actor.id)) return;
|
||||
if (actor.isSuspended) return;
|
||||
|
||||
if (isCreate(activity)) {
|
||||
await create(actor, activity);
|
||||
|
@ -15,7 +15,7 @@ const logger = apLogger;
|
||||
*/
|
||||
export async function createImage(actor: CacheableRemoteUser, value: any): Promise<DriveFile> {
|
||||
// 投稿者が凍結されていたらスキップ
|
||||
if (Users.checkSuspended(actor.id)) {
|
||||
if (actor.isSuspended) {
|
||||
throw new Error('actor has been suspended');
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||
const actor = await resolvePerson(getOneApId(note.attributedTo), resolver) as CacheableRemoteUser;
|
||||
|
||||
// 投稿者が凍結されていたらスキップ
|
||||
if (Users.checkSuspended(actor.id)) {
|
||||
if (actor.isSuspended) {
|
||||
throw new Error('actor has been suspended');
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ export default async (endpoint: string, user: CacheableLocalUser | null | undefi
|
||||
});
|
||||
}
|
||||
|
||||
if (ep.meta.requireCredential && Users.checkSuspended(user!.id)) {
|
||||
if (ep.meta.requireCredential && user!.isSuspended) {
|
||||
throw new ApiError({
|
||||
message: 'Your account has been suspended.',
|
||||
code: 'YOUR_ACCOUNT_SUSPENDED',
|
||||
|
@ -42,7 +42,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if (!Users.checkModerator(user.id) && (file.userId !== user.id)) {
|
||||
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if (!Users.checkModerator(user.id) && (file.userId !== user.id)) {
|
||||
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
if (!Users.checkModerator(user.id) && (file.userId !== user.id)) {
|
||||
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw e;
|
||||
});
|
||||
|
||||
if (!Users.checkModerator(user.id) && (note.userId !== user.id)) {
|
||||
if ((!user.isAdmin && !user.isModerator) && (note.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ export const paramDef = {
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
if (m.disableGlobalTimeline) {
|
||||
if (user == null || !Users.checkModerator(user.id)) {
|
||||
if (user == null || (!user.isAdmin && !user.isModerator)) {
|
||||
throw new ApiError(meta.errors.gtlDisabled);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export const paramDef = {
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
if (m.disableLocalTimeline && !Users.checkModerator(user.id)) {
|
||||
if (m.disableLocalTimeline && (!user.isAdmin && !user.isModerator)) {
|
||||
throw new ApiError(meta.errors.stlDisabled);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ export const paramDef = {
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
if (m.disableLocalTimeline) {
|
||||
if (user == null || !Users.checkModerator(user.id)) {
|
||||
if (user == null || (!user.isAdmin && !user.isModerator)) {
|
||||
throw new ApiError(meta.errors.ltlDisabled);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export const paramDef = {
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
let user;
|
||||
|
||||
const isAdminOrModerator = me && Users.checkModerator(me.id);
|
||||
const isAdminOrModerator = me && (me.isAdmin || me.isModerator);
|
||||
|
||||
if (ps.userIds) {
|
||||
if (ps.userIds.length === 0) {
|
||||
|
@ -150,7 +150,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
||||
if (data.channel != null) data.localOnly = true;
|
||||
|
||||
// サイレンス
|
||||
if (Users.checkSilenced(user.id) && data.visibility === 'public' && data.channel == null) {
|
||||
if (user.isSilenced && data.visibility === 'public' && data.channel == null) {
|
||||
data.visibility = 'home';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user