Node.js based forum software built for the modern web
send notification to all followers when a user makes a post
Baris Usaklib7e2bfff3d69
diff --git a/src/posts.js b/src/posts.jsindex 206ea03fd1..44d90ce251 100644--- a/src/posts.js+++ b/src/posts.js@@ -284,6 +284,8 @@ marked.setOptions({user.incrementUserFieldBy(uid, 'postcount', 1);user.setUserField(uid, 'lastposttime', timestamp);+ user.sendPostNotificationToFollowers(uid, tid, pid);+if (callback)callback(pid);});diff --git a/src/user.js b/src/user.jsindex f33a1832a3..f6cab56944 100644--- a/src/user.js+++ b/src/user.js@@ -462,6 +462,18 @@ var utils = require('./../public/src/utils.js'),}}+ User.sendPostNotificationToFollowers = function(uid, tid, pid) {++ User.getUserField(uid, 'username', function(username) {+ User.getFollowers(uid, function(followers) {+ var message = username + ' made a new post';+ notifications.create(message, 5, 'topic/' + tid + '/' + pid, 'notification_'+new Date().getTime(), function(nid) {+ notifications.push(nid, followers);+ });+ });+ });++ }User.isFollowing = function(uid, theirid, callback) {RDB.sismember('user:'+uid+':following', theirid, function(err, data) {diff --git a/src/websockets.js b/src/websockets.jsindex 1a18bb316f..0f67153762 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -286,7 +286,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),userSockets[touid][x].emit('chatMessage', {fromuid:uid, username:username, message:finalMessage});}- notifications.create(finalMessage, 5, null, 'notification_'+new Date().getTime(), function(nid) {+ notifications.create(finalMessage, 5, '', 'notification_'+new Date().getTime(), function(nid) {notifications.push(nid, [touid], function(success) {});