more fixes

v1.18.x
barisusakli 11 years ago
parent dfb6606432
commit f71bd41408

@ -69,7 +69,6 @@ define('notifications', ['sounds'], function(sound) {
notifIcon.attr('data-content', count > 20 ? '20+' : count); notifIcon.attr('data-content', count > 20 ? '20+' : count);
Tinycon.setBubble(count); Tinycon.setBubble(count);
localStorage.setItem('notifications:count', count);
}; };
socket.emit('notifications.getCount', function(err, 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({ app.alert({
alert_id: 'new_notif', alert_id: 'new_notif',
title: '[[notifications:new_notification]]', title: '[[notifications:new_notification]]',
@ -95,8 +93,7 @@ define('notifications', ['sounds'], function(sound) {
ajaxify.refresh(); ajaxify.refresh();
} }
var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0; updateNotifCount(notifCount);
updateNotifCount(savedCount + 1);
sound.play('notification'); sound.play('notification');
}); });

@ -142,8 +142,11 @@ var async = require('async'),
return next(err); return next(err);
} }
// Client-side User.notifications.getUnreadCount(uid, function(err, count) {
websockets.in('uid_' + uid).emit('event:new_notification', notif_data); if (!err) {
websockets.in('uid_' + uid).emit('event:new_notification', notif_data, count);
}
});
// Plugins // Plugins
notif_data.uid = uid; notif_data.uid = uid;

@ -71,7 +71,7 @@ module.exports = function(app, middleware, controllers) {
bodyShort: '[[notifications:user_posted_to, ' + username + ', ' + topicTitle + ']]', bodyShort: '[[notifications:user_posted_to, ' + username + ', ' + topicTitle + ']]',
bodyLong: 'asdasd khajsdhakhdakj hdkash dakhdakjdhakjs', bodyLong: 'asdasd khajsdhakhdakj hdkash dakhdakjdhakjs',
path: nconf.get('relative_path') + '/topic/' + topicSlug + '/' + postIndex, path: nconf.get('relative_path') + '/topic/' + topicSlug + '/' + postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid + ':uid:' + fromUid,
tid: tid, tid: tid,
from: fromUid from: fromUid
}, function(err, nid) { }, function(err, nid) {

@ -90,19 +90,19 @@ function favouriteCommand(command, eventName, socket, data, callback) {
} }
} }
function sendNotificationToPostOwner(data, uid, notification) { function sendNotificationToPostOwner(data, fromuid, notification) {
if(data && data.pid && uid) { if(data && data.pid && fromuid) {
posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) { posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) {
if (err) { if (err) {
return; return;
} }
if (uid === parseInt(postData.uid, 10)) { if (fromuid === parseInt(postData.uid, 10)) {
return; return;
} }
async.parallel({ async.parallel({
username: async.apply(user.getUserField, uid, 'username'), username: async.apply(user.getUserField, fromuid, 'username'),
slug: async.apply(topics.getTopicField, postData.tid, 'slug'), slug: async.apply(topics.getTopicField, postData.tid, 'slug'),
index: async.apply(posts.getPidIndex, data.pid), index: async.apply(posts.getPidIndex, data.pid),
postContent: function(next) { postContent: function(next) {
@ -122,8 +122,8 @@ function sendNotificationToPostOwner(data, uid, notification) {
bodyShort: '[[' + notification + ', ' + results.username + ']]', bodyShort: '[[' + notification + ', ' + results.username + ']]',
bodyLong: results.postContent, bodyLong: results.postContent,
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
uniqueId: 'post:' + data.pid, uniqueId: 'post:' + data.pid + ':uid:' + fromuid,
from: uid from: fromuid
}, function(err, nid) { }, function(err, nid) {
if (!err) { if (!err) {
notifications.push(nid, [postData.uid]); notifications.push(nid, [postData.uid]);

@ -45,7 +45,8 @@ module.exports = function(Topics) {
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
bodyLong: results.postContent, bodyLong: results.postContent,
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex, path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
tid: tid,
from: exceptUid from: exceptUid
}, next); }, next);
}); });

@ -39,11 +39,13 @@ var async = require('async'),
} }
var nidsToUniqueIds = {}; var nidsToUniqueIds = {};
Object.keys(uniqueIdToNids).forEach(function(uniqueId) { var nids = [];
uniqueIds.forEach(function(uniqueId) {
nidsToUniqueIds[uniqueIdToNids[uniqueId]] = 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) { notifications.get(nid, function(err, notif_data) {
if (err) { if (err) {
return next(err); return next(err);
@ -261,7 +263,7 @@ var async = require('async'),
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]', bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]',
bodyLong: results.postContent, bodyLong: results.postContent,
path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex, path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid + ':uid:' + uid,
from: uid from: uid
}, function(err, nid) { }, function(err, nid) {
if (err) { if (err) {

Loading…
Cancel
Save