Skip to content

Instantly share code, notes, and snippets.

@camwhite
Created July 25, 2019 07:34
Show Gist options
  • Save camwhite/c4d895a7b849252f038523e73468ef62 to your computer and use it in GitHub Desktop.
Save camwhite/c4d895a7b849252f038523e73468ef62 to your computer and use it in GitHub Desktop.
knex.addHook('after', 'insert', 'follows', async (when, method, table, params) => {
try {
const { follower_id, follow_id, id } = params.result[0]
const follower = client.feed('timeline', follower_id)
await follower.follow('user', follow_id)
const activity = {
actor: `users:${follower_id}`,
verb: 'follow',
object: `users:${follow_id}`,
foreign_id: `follows:${id}`,
time: new Date().toISOString()
}
const user = await client.feed('user', follower_id)
await user.addActivity(activity)
const notifications = await client.feed('notification', follow_id)
await notifications.addActivity(activity)
} catch (err) {
throw err
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment