unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at angular21 35 lines 1.1 kB view raw
1import { Op } from 'sequelize' 2import getFollowedsIds from './getFollowedsIds.js' 3import getBlockedIds from './getBlockedIds.js' 4import { User } from '../../models/index.js' 5 6export default async function getNonFollowedLocalUsersIds(userId: string): Promise<string[]> { 7 // TODO If we wanted to add cache to this, we would need to CLEAR LOCAL CACHE when registering a new user. 8 try { 9 const followedLocalUsers = getFollowedsIds(userId, true) 10 const blockedUsers = getBlockedIds(userId) 11 Promise.all([followedLocalUsers, blockedUsers]) 12 const nonFollowedUsers = await User.findAll({ 13 attributes: ['id'], 14 where: { 15 id: { 16 [Op.notIn]: (await followedLocalUsers).concat(await blockedUsers) 17 }, 18 email: { 19 [Op.ne]: null 20 }, 21 url: { 22 [Op.notLike]: '@%' 23 }, 24 25 banned: { 26 [Op.ne]: true 27 } 28 } 29 }) 30 const result = nonFollowedUsers.map((notFollowed: any) => notFollowed.id) 31 return result as string[] 32 } catch (error) { 33 return [] 34 } 35}