unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at angular21 58 lines 1.9 kB view raw
1import { activityPubObject } from "../../../interfaces/fediverse/activityPubObject.js"; 2import { Bites } from "../../../models/bites.js"; 3import { User } from "../../../models/user.js"; 4import { UserBitesPostRelation } from "../../../models/userBitesPostRelation.js"; 5import { getDeletedUser } from "../../cacheGetters/getDeletedUser.js"; 6import { createNotification } from "../../pushNotifications.js"; 7import { getPostThreadRecursive } from "../getPostThreadRecursive.js"; 8import { getRemoteActor } from "../getRemoteActor.js"; 9 10async function biteActivity(apObject: activityPubObject, remoteUser: User, user: User) { 11 if (apObject.target) { 12 const deletedUser = await getDeletedUser() 13 const userToBeBitten = await getRemoteActor(apObject.target, user) 14 15 if (userToBeBitten && userToBeBitten.id != deletedUser?.id) { 16 await Bites.create({ 17 biterId: remoteUser.id, 18 bittenId: userToBeBitten.id, 19 remoteId: apObject.id 20 }) 21 22 await createNotification( 23 { 24 notificationType: 'USERBITE', 25 userId: remoteUser.id, 26 notifiedUserId: userToBeBitten.id 27 }, 28 { 29 userUrl: remoteUser.url 30 } 31 ) 32 } else { 33 const postToBeBitten = await getPostThreadRecursive(user, apObject.target) 34 if (postToBeBitten) { 35 await UserBitesPostRelation.create({ 36 userId: remoteUser.id, 37 postId: postToBeBitten.id, 38 remoteId: apObject.id 39 }) 40 41 await createNotification( 42 { 43 notificationType: 'POSTBITE', 44 userId: remoteUser.id, 45 notifiedUserId: postToBeBitten.userId, 46 postId: postToBeBitten.id 47 }, 48 { 49 postContent: postToBeBitten.content, 50 userUrl: remoteUser.url 51 } 52 ) 53 } 54 } 55 } 56} 57 58export { biteActivity }