sharkey/src/server/api/common/get-hide-users.ts
2019-02-01 10:00:36 +09:00

26 lines
638 B
TypeScript

import * as mongo from 'mongodb';
import Mute from '../../../models/mute';
import User, { IUser } from '../../../models/user';
import { unique } from '../../../prelude/array';
export async function getHideUserIds(me: IUser) {
return me ? await getHideUserIdsById(me._id) : [];
}
export async function getHideUserIdsById(meId?: mongo.ObjectID) {
const [suspended, muted] = await Promise.all([
User.find({
isSuspended: true
}, {
fields: {
_id: true
}
}),
meId ? Mute.find({
muterId: meId
}) : Promise.resolve([])
]);
return unique(suspended.map(user => user._id).concat(muted.map(mute => mute.muteeId)));
}