unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at angular21 47 lines 1.2 kB view raw
1import { Op } from 'sequelize' 2import { Post, User } from '../models/index.js' 3import { logger } from './logger.js' 4 5export default async function getReblogs(user: any) { 6 const userId = user.id 7 const userPostsWithReblogs = await Post.findAll({ 8 include: [ 9 { 10 model: Post, 11 as: 'descendents', 12 where: { 13 createdAt: { 14 [Op.gt]: new Date(user.lastTimeNotificationsCheck) 15 } 16 }, 17 include: [ 18 { 19 model: User, 20 attributes: ['avatar', 'url', 'description', 'id'] 21 } 22 ] 23 }, 24 { 25 model: User, 26 attributes: ['avatar', 'url', 'description'] 27 } 28 ], 29 where: { 30 userId 31 } 32 }) 33 const result: any[] = [] 34 userPostsWithReblogs.forEach((postWithReblogs: any) => { 35 try { 36 postWithReblogs.descendents.forEach((elem: any) => { 37 // TODO fix dirty hack 38 const elemProcessed: any = JSON.parse(JSON.stringify(elem)) 39 elemProcessed.createdAt = elem.createdAt.getTime() 40 result.push(elemProcessed) 41 }) 42 } catch (error) { 43 logger.error(error) 44 } 45 }) 46 return result 47}