From f71bd41408e739451094ebe1ea93e121fee476db Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 28 Jul 2014 17:50:49 -0400 Subject: [PATCH] more fixes --- public/src/modules/notifications.js | 7 ++----- src/notifications.js | 7 +++++-- src/routes/debug.js | 2 +- src/socket.io/posts.js | 12 ++++++------ src/topics/follow.js | 3 ++- src/user/notifications.js | 8 +++++--- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 3a5afe053d..ce591b1b76 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -69,7 +69,6 @@ define('notifications', ['sounds'], function(sound) { notifIcon.attr('data-content', count > 20 ? '20+' : count); Tinycon.setBubble(count); - localStorage.setItem('notifications:count', count); }; socket.emit('notifications.getCount', function(err, count) { @@ -80,8 +79,7 @@ define('notifications', ['sounds'], function(sound) { } }); - socket.on('event:new_notification', function() { - + socket.on('event:new_notification', function(notifData, notifCount) { app.alert({ alert_id: 'new_notif', title: '[[notifications:new_notification]]', @@ -95,8 +93,7 @@ define('notifications', ['sounds'], function(sound) { ajaxify.refresh(); } - var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0; - updateNotifCount(savedCount + 1); + updateNotifCount(notifCount); sound.play('notification'); }); diff --git a/src/notifications.js b/src/notifications.js index 95376de345..d243796bf9 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -142,8 +142,11 @@ var async = require('async'), return next(err); } - // Client-side - websockets.in('uid_' + uid).emit('event:new_notification', notif_data); + User.notifications.getUnreadCount(uid, function(err, count) { + if (!err) { + websockets.in('uid_' + uid).emit('event:new_notification', notif_data, count); + } + }); // Plugins notif_data.uid = uid; diff --git a/src/routes/debug.js b/src/routes/debug.js index 414df20dbd..7f264d0d01 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -71,7 +71,7 @@ module.exports = function(app, middleware, controllers) { bodyShort: '[[notifications:user_posted_to, ' + username + ', ' + topicTitle + ']]', bodyLong: 'asdasd khajsdhakhdakj hdkash dakhdakjdhakjs', path: nconf.get('relative_path') + '/topic/' + topicSlug + '/' + postIndex, - uniqueId: 'topic:' + tid, + uniqueId: 'topic:' + tid + ':uid:' + fromUid, tid: tid, from: fromUid }, function(err, nid) { diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 7756f2e28e..a5344d0f2a 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -90,19 +90,19 @@ function favouriteCommand(command, eventName, socket, data, callback) { } } -function sendNotificationToPostOwner(data, uid, notification) { - if(data && data.pid && uid) { +function sendNotificationToPostOwner(data, fromuid, notification) { + if(data && data.pid && fromuid) { posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) { if (err) { return; } - if (uid === parseInt(postData.uid, 10)) { + if (fromuid === parseInt(postData.uid, 10)) { return; } async.parallel({ - username: async.apply(user.getUserField, uid, 'username'), + username: async.apply(user.getUserField, fromuid, 'username'), slug: async.apply(topics.getTopicField, postData.tid, 'slug'), index: async.apply(posts.getPidIndex, data.pid), postContent: function(next) { @@ -122,8 +122,8 @@ function sendNotificationToPostOwner(data, uid, notification) { bodyShort: '[[' + notification + ', ' + results.username + ']]', bodyLong: results.postContent, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index, - uniqueId: 'post:' + data.pid, - from: uid + uniqueId: 'post:' + data.pid + ':uid:' + fromuid, + from: fromuid }, function(err, nid) { if (!err) { notifications.push(nid, [postData.uid]); diff --git a/src/topics/follow.js b/src/topics/follow.js index ae20fc70bc..e16cf99b9a 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -45,7 +45,8 @@ module.exports = function(Topics) { bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', bodyLong: results.postContent, path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex, - uniqueId: 'topic:' + tid, + uniqueId: 'topic:' + tid + ':uid:' + exceptUid, + tid: tid, from: exceptUid }, next); }); diff --git a/src/user/notifications.js b/src/user/notifications.js index b4720c1fee..7f1bb54b5e 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -39,11 +39,13 @@ var async = require('async'), } var nidsToUniqueIds = {}; - Object.keys(uniqueIdToNids).forEach(function(uniqueId) { + var nids = []; + uniqueIds.forEach(function(uniqueId) { nidsToUniqueIds[uniqueIdToNids[uniqueId]] = uniqueId; + nids.push(uniqueIdToNids[uniqueId]); }); - async.map(Object.keys(nidsToUniqueIds), function(nid, next) { + async.map(nids, function(nid, next) { notifications.get(nid, function(err, notif_data) { if (err) { return next(err); @@ -261,7 +263,7 @@ var async = require('async'), bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]', bodyLong: results.postContent, path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex, - uniqueId: 'topic:' + tid, + uniqueId: 'topic:' + tid + ':uid:' + uid, from: uid }, function(err, nid) { if (err) {