import { Op } from 'sequelize' import getFollowedsIds from './getFollowedsIds.js' import getBlockedIds from './getBlockedIds.js' import { User } from '../../models/index.js' export default async function getNonFollowedLocalUsersIds(userId: string): Promise { // TODO If we wanted to add cache to this, we would need to CLEAR LOCAL CACHE when registering a new user. try { const followedLocalUsers = getFollowedsIds(userId, true) const blockedUsers = getBlockedIds(userId) Promise.all([followedLocalUsers, blockedUsers]) const nonFollowedUsers = await User.findAll({ attributes: ['id'], where: { id: { [Op.notIn]: (await followedLocalUsers).concat(await blockedUsers) }, email: { [Op.ne]: null }, url: { [Op.notLike]: '@%' }, banned: { [Op.ne]: true } } }) const result = nonFollowedUsers.map((notFollowed: any) => notFollowed.id) return result as string[] } catch (error) { return [] } }