Git Product home page Git Product logo

activitystreams's Introduction

ActivityStrea.ms in Node.js on MongoDB.

Stability: Very unstable, incomplete, work-in-progress.

Connect to the database.

ActivityStreams.connect('mongodb://localhost:27017/my_db')
  .then(client => { /* do stuff */ })
  .catch(err => { /* ... */ })

Or initialise with a connection you already hold.

ActivityStreams.init(conn)
  .then(client => { /* do stuff */ })
  .catch(err => { /* ... */ })

Create some flat feed stores. Flat feeds can be "followed". Each feed in the store is size-limited. Once the size is exceeded older activities drop out as newer activities are added. The default size limit for flat feeds is 1000.

client.createFlatFeedStore('user', {feed_size_limit:20000})
  .then(store => { /* add activities and so on */ })
  .catch(err => { /* handle appropriately */ })

client.createFlatFeedStore('timeline', {feed_size_limit:500})
  .then(store => { /* ... */ })
  .catch(err => { /* ... */ })

Prepare to add activities to a particular feed in the 'user' store:

const stevesStream = client.feed('user', 'steves-user-id')

Add activities to the feed. A basic activity contains at least actor, verb, and object.

stevesStream.add({
  actor: 'steves-user-id',
  verb: 'like',
  object: 'a-photo-id'
})

Get newest 5 activities from the feed.

stevesStream.get({limit:5}) // default limit is 20
  .then(activities => { /* do stuff */ })
  .catch(err => { /* handle nicely */ })

Get the next 5 activities from the feed.

stevesStream.get({limit:5, id_lt:'abc123'})
  .then(activities -> { /* do more stuff */ })
  .catch(err => { /* handle sweetly */ })

Follow a feed, copying the 10 most recent activities into the follower's feed.

const joesTimeline = client.feed('timeline', 'joes-user-id')
joesTimeline.follow('user', 'steves-user-id', {limit:10}) // default limit is 20

Create an aggregate feed store. Aggregate feeds are used to group activities, for example to enable a news-feed containing "Joe and 6 others like your comment", or "Steve followed you and 3 others". Aggregate feeds are size limited, the default being 200. When activities are grouped, the newest N (group_size) activities are stored in the group.

client.createAggregateFeedStore('newsfeed', {
  feed_size_limit: 500,
  group_size: 3, // default 5
  // todo: grouping function
})
  .then(store => { /* ... */ })
  .catch(err => { /* ... */ })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.