Created
July 25, 2019 07:34
-
-
Save camwhite/c4d895a7b849252f038523e73468ef62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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