Node.js based forum software built for the modern web
passing in a picture into notifications now
Julian Lam9e64f4e303ec
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.jsindex b5b4226c58..c3ec88e9b1 100644--- a/public/src/modules/notifications.js+++ b/public/src/modules/notifications.js@@ -20,12 +20,23 @@ define(function() {notifList.html('');if (!err && (data.read.length + data.unread.length) > 0) {+ var image = '';for (x = 0; x < numUnread; x++) {- notifList.append($('<li class="' + data.unread[x].readClass + '"><a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a></li>'));+ if (data.unread[x].image) {+ image = '<img src="' + data.unread[x].image + '" />';+ } else {+ image = '';+ }+ notifList.append($('<li class="' + data.unread[x].readClass + '"><a href="' + data.unread[x].path + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(data.unread[x].datetime, true) + '</span><span class="text">' + data.unread[x].text + '</span></a></li>'));}for (x = 0; x < numRead; x++) {- notifList.append($('<li class="' + data.read[x].readClass + '"><a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a></li>'));+ if (data.read[x].image) {+ image = '<img src="' + data.read[x].image + '" />';+ } else {+ image = '';+ }+ notifList.append($('<li class="' + data.read[x].readClass + '"><a href="' + data.read[x].path + '">' + image + '<span class="pull-right relTime">' + utils.relativeTime(data.read[x].datetime, true) + '</span><span class="text">' + data.read[x].text + '</span></a></li>'));}} else {diff --git a/src/notifications.js b/src/notifications.jsindex 1310ff8f35..06d20223dd 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -4,7 +4,8 @@ var async = require('async'),db = require('./database'),utils = require('../public/src/utils'),- events = require('./events');+ events = require('./events'),+ User = require('./user');(function(Notifications) {"use strict";@@ -27,10 +28,17 @@ var async = require('async'),if (exists) {db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {- db.getObjectFields('notifications:' + nid, ['nid', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {-+ db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {notification.read = rank !== null ? true:false;- callback(notification);++ if (notification.from) {+ User.getUserField(notification.from, 'picture', function(err, picture) {+ notification.image = picture;+ callback(notification);+ });+ } else {+ callback(notification);+ }});});} else {diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex f7e2b57369..a222f51d93 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -106,7 +106,8 @@ SocketModules.chats.send = function(socket, data) {notifications.create({text: notifText,path: 'javascript:app.openChat('' + username + '', ' + socket.uid + ');',- uniqueId: 'notification_' + socket.uid + '_' + touid+ uniqueId: 'notification_' + socket.uid + '_' + touid,+ from: socket.uid}, function(nid) {notifications.push(nid, [touid], function(success) {diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex 87f94c195f..7ad8c7c088 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -263,7 +263,8 @@ SocketPosts.flag = function(socket, pid, callback) {notifications.create({text: message,path: path,- uniqueId: 'post_flag:' + pid+ uniqueId: 'post_flag:' + pid,+ from: socket.uid}, function(nid) {notifications.push(nid, adminGroup.members, function() {next(null);diff --git a/src/threadTools.js b/src/threadTools.jsindex da80168473..047e1e6228 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -271,7 +271,8 @@ var winston = require('winston'),notifications.create({text: '<strong>' + username + '</strong> has posted a reply to: "<strong>' + topicData.title + '</strong>"',path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,- uniqueId: 'topic:' + tid+ uniqueId: 'topic:' + tid,+ from: exceptUid}, function(nid) {next(null, nid);});diff --git a/src/user.js b/src/user.jsindex d3105325d5..1cfab798d9 100644--- a/src/user.js+++ b/src/user.js@@ -717,7 +717,8 @@ var bcrypt = require('bcryptjs'),notifications.create({text: message,path: nconf.get('relative_path') + '/topic/' + slug + '#' + pid,- uniqueId: 'topic:' + tid+ uniqueId: 'topic:' + tid,+ from: uid}, function(nid) {notifications.push(nid, followers);});@@ -1029,6 +1030,7 @@ var bcrypt = require('bcryptjs'),getNotifications('uid:' + uid + ':notifications:read', 0, 9, null, next);}}, function(err, notifications) {+ console.log(notifications);if(err) {return calback(err);}