Repository: cloudflare/wildebeest
File: backend/src/activitypub/activities/handle.ts (TypeScript)

Code before:
			} else {
				// Object already exists locally, we can just use it.
				obj = localObject
			}

			const fromActor = await actors.getAndCache(actorId, db)

			// notify the user
			const targetActor = await actors.getPersonById(db, new URL(obj.originalActorId))
			if (targetActor === null) {
				console.warn('object actor not found')
				break
			}

			const notifId = await createNotification(db, 'reblog', targetActor, fromActor, obj)

			await createReblog(db, fromActor, obj, {
				target: targetActor,
				notifId,
				adminEmail,
				vapidKeys,
			})
			break
		}

		// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like
		case 'Like': {
			const actorId = getActorAsId()
			const objectId = getObjectAsId()

			const obj = await objects.getObjectById(db, objectId)
			if (obj === null || !obj.originalActorId) {
				console.warn('unknown object')
				break
			}

			const fromActor = await actors.getAndCache(actorId, db)
			const targetActor = await actors.getPersonById(db, new URL(obj.originalActorId))
			if (targetActor === null) {
				console.warn('object actor not found')
				break
			}

			const [notifId] = await Promise.all([
				// Notify the user
				createNotification(db, 'favourite', targetActor, fromActor, obj),
				// Store the like for counting
				insertLike(db, fromActor, obj),
			])

			await sendLikeNotification(db, fromActor, targetActor, notifId, adminEmail, vapidKeys)

Review comment (suggestion):
I think I would keep this function call separate. E.g.

```ts
await Promise.all([createReblog(...), sendReblogNotification(...)])
```

Sending a notification is not necessarily part of creating a reblog, hence the fact you had to make it optional.

Code after:
				}
			} else {
				// Object already exists locally, we can just use it.
				obj = localObject
			}

			const fromActor = await actors.getAndCache(actorId, db)

			// notify the user
			const targetActor = await actors.getPersonById(db, new URL(obj.originalActorId))
			if (targetActor === null) {
				console.warn('object actor not found')
				break
			}

			const notifId = await createNotification(db, 'reblog', targetActor, fromActor, obj)

			await Promise.all([
				createReblog(db, fromActor, obj),
				sendReblogNotification(db, fromActor, targetActor, notifId, adminEmail, vapidKeys),
			])

			break
		}

		// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like
		case 'Like': {
			const actorId = getActorAsId()
			const objectId = getObjectAsId()

			const obj = await objects.getObjectById(db, objectId)
			if (obj === null || !obj.originalActorId) {
				console.warn('unknown object')
				break
			}

			const fromActor = await actors.getAndCache(actorId, db)
			const targetActor = await actors.getPersonById(db, new URL(obj.originalActorId))
			if (targetActor === null) {
				console.warn('object actor not found')
				break
			}

			const [notifId] = await Promise.all([
				// Notify the user
				createNotification(db, 'favourite', targetActor, fromActor, obj),
				// Store the like for counting
				insertLike(db, fromActor, obj),
			])

			await sendLikeNotification(db, fromActor, targetActor, notifId, adminEmail, vapidKeys)