monkeeShark/src/server/api/common/get-hide-users.ts

26 lines
640 B
TypeScript
Raw Normal View History

2019-02-01 00:57:51 +00:00
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 await getHideUserIdsById(me ? me._id : null);
2019-02-01 00:57:51 +00:00
}
2019-02-01 01:00:36 +00:00
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([])
]);
2019-02-01 00:57:51 +00:00
2019-02-01 01:00:36 +00:00
return unique(suspended.map(user => user._id).concat(muted.map(mute => mute.muteeId)));
2019-02-01 00:57:51 +00:00
}