From dedc6d8154a13a6b8e134e306a25f8989d077b2a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 17 Jun 2014 21:10:21 -0400 Subject: [PATCH] added new hook for notification pushing --- docs/plugins/hooks.rst | 7 +++++++ src/notifications.js | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index bfba67baad..672b0743ed 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -203,6 +203,13 @@ Executed whenever a post is created or edited, after it is saved into the databa ``action:post.restore`` ^^^^^^^^^^^^^^^^^^^^^ +``action:notification.pushed`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +**Argument(s)**: A notification object (javascript Object) + +Executed whenever a notification is pushed to a user. + ``action:config.set`` ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/notifications.js b/src/notifications.js index 8f07dc2cf1..3912d2cd22 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -11,7 +11,8 @@ var async = require('async'), events = require('./events'), User = require('./user'), groups = require('./groups'), - meta = require('./meta'); + meta = require('./meta'), + plugins = require('./plugins'); (function(Notifications) { @@ -125,7 +126,13 @@ var async = require('async'), checkReplace(notif_data.uniqueId, uid, notif_data, function(err, replace) { if (replace) { db.sortedSetAdd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid); + + // Client-side websockets.in('uid_' + uid).emit('event:new_notification', notif_data); + + // Plugins + notif_data.uid = uid; + plugins.fireHook('action:notification.pushed', notif_data); } next(); });