GithubHelp home page GithubHelp logo

notif's Introduction

Install

npm install notif

Usage

notif.send(actor, verb [, object]);

Example:

notif.send({ username: 'olalonde' }, 'followed', { username: 'bobby' });

Every notification is internally represented by an object containing the following properties:

notification:

  • time : {Object} Date() object that is automatically assigned when notification is created.
  • actor : {Object} A generic object that identifies the user or entity that performed the activity.
  • verb : {String} A verb that identifies the action of the activity.
  • object : (optional) {Object} The primary object of the activity.

Note: This library follows the Atom Activity Streams nomenclature.

Registering verb handlers

notif.register('followed', function (notification, cb) {
  // we assume that the notification object looks like this 
  // after bob followed oli:
  //
  // {
  //   actor: bob
  //   verb: 'followed'
  //   object: oli
  // }

  // let's notify oli that he just got followed
  // and an activity to bob's activity stream 
  // but not in his notification center

  var activity = new Activity();

  // specify on whose stream we want the notification to show up
  activity._user = notification.object._id;
  activity._actor = notification.actor._id;
  activity._object = notification.object._id;
  activity.createdAt = notification.time; 
  // for example: private, public, notification center
  activity.setPrivacyLevel('followers');  
  //activity.markRead(); 
  activity.save(function (err) {
    if (err) console.error(err);
  });
});

notif.register('logged in', function (notification) {

});

notif.register({ except: ['delete account'] }, function (notification) {
  console.log('good news!');
});

notif.register({ only: ['registered'] }, function (notification) {
  // send email...
});

notify.register(function (notification) {
  console.log(notification.toString());
  //console.log(notification.actor + ' ' + notification.verb + ' ' + notifications.object);
});

References

http://nodejs.org/api/events.html

https://github.com/flatiron/winston

https://github.com/brantyoung/django-notifications

https://github.com/jtauber/django-notification/blob/master/docs/usage.txt

http://activitystrea.ms/

http://stackoverflow.com/questions/5616614/how-would-you-create-a-notification-system-like-on-so-or-facebook-in-ror

notif's People

Contributors

olalonde avatar

Watchers

 avatar

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.