Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/follow.js Secret
Created Nov 8, 2019

Embed
What would you like to do?
// instantiate a new client (server side)
var streamClient = stream.connect(config.stream.key, config.stream.secret);
// instantiate a feed using feed class 'timeline_flat' and the user id from the database
var timeline = streamClient.feed('timeline_flat', data.user_id);
timeline.follow('user_posts', data.follower_id);
// instantiate a feed using feed class 'timeline_aggregated' and the user id from the database
var timelineAggregated = streamClient.feed('timeline_aggregated', data.user_id);
timelineAggregated.follow('user', data.follower_id);
// instantiate a feed using feed class 'user' and the user id from the database
var userFeed = streamClient.feed('user', data.user_id);
// build activity object for stream feed
var activity = {
actor: `user:${data.user_id}`,
verb: 'follow',
object: `user:${data.follower_id}`,
foreign_id: `follow:${result.insertId}`,
time: data['created_at'],
to: [`notification:${data.follower_id}`]
};
// add activity to the feed
userFeed.addActivity(activity)
.then(function(response) {
console.log(response);
})
.catch(function(reason) {
console.log(reason);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.