diff --git a/public/language/en_GB/notifications.json b/public/language/en_GB/notifications.json
index 748c89bfb7..d480d39a2e 100644
--- a/public/language/en_GB/notifications.json
+++ b/public/language/en_GB/notifications.json
@@ -9,5 +9,13 @@
"continue_to": "Continue to",
"return_to": "Return to ",
"new_notification": "New Notification",
- "you_have_unread_notifications": "You have unread notifications."
+ "you_have_unread_notifications": "You have unread notifications.",
+
+ "user_made_post": "%1 made a new post",
+ "new_message_from": "New message from %1",
+ "upvoted_your_post": "%1 has upvoted your post.",
+ "favourited_your_post": "%1 has favourited your post.",
+ "user_flagged_post": "%1 flagged a post.",
+ "user_posted_to" : "%1 has posted a reply to: %2"
+
}
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index 9987a5cedd..2d4120b903 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -1,3 +1,8 @@
+'use strict';
+
+/* globals define, socket, translator, utils, config, app, ajaxify, Tinycon*/
+
+
define(['sounds'], function(sound) {
var Notifications = {};
@@ -13,50 +18,44 @@ define(['sounds'], function(sound) {
socket.emit('notifications.get', null, function(err, data) {
- var numRead = data.read.length,
- numUnread = data.unread.length,
- x;
+ function createNotification(notification, callback) {
+ if (notification.image) {
+ image = '
';
+ } else {
+ image = '';
+ }
- var html = '';
+ return '
' + image + '' + utils.relativeTime(notification.datetime, true) + '' + notification.text + '';
+ }
+
+ var x, html = '';
if (!err && (data.read.length + data.unread.length) > 0) {
var image = '';
- for (x = 0; x < numUnread; x++) {
- if (data.unread[x].image) {
- image = '
';
- } else {
- image = '';
- }
- html += '' + image + '' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + '';
+ for (x = 0; x < data.unread.length; x++) {
+ html += createNotification(data.unread[x]);
}
- for (x = 0; x < numRead; x++) {
- if (data.read[x].image) {
- image = '
';
- } else {
- image = '';
- }
- html += '' + image + '' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + '';
+ for (x = 0; x < data.read.length; x++) {
+ html += createNotification(data.read[x]);
}
- addSeeAllLink(replaceHtml);
+
+ addSeeAllLink();
} else {
- translator.translate('[[notifications:no_notifs]]', function(translated) {
- html += translated;
- addSeeAllLink(replaceHtml);
- });
+ html += '[[notifications:no_notifs]]';
+ addSeeAllLink();
}
- function addSeeAllLink(callback) {
- translator.translate('[[notifications:see_all]]', function(translated) {
- html += translated;
- callback();
- });
+ function addSeeAllLink() {
+ html += '[[notifications:see_all]]';
}
- function replaceHtml() {
- notifList.html(html);
- }
+
+ translator.translate(html, function(translated) {
+ notifList.html(translated);
+ });
+
updateNotifCount(data.unread.length);
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 401d09a8e9..9d8d233c64 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -194,7 +194,7 @@ SocketModules.chats.send = function(socket, data, callback) {
function sendChatNotification(fromuid, touid, username) {
if (!module.parent.exports.isUserOnline(touid)) {
- var notifText = 'New message from ' + username + '';
+ var notifText = '[[notifications:new_message_from,' + username + ']]';
notifications.create({
text: notifText,
path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');',
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index f2144896cd..05507f4660 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -49,7 +49,7 @@ SocketPosts.reply = function(socket, data, callback) {
SocketPosts.upvote = function(socket, data, callback) {
favouriteCommand('upvote', 'voted', socket, data, callback);
- sendNotificationToPostOwner(data, socket.uid, 'has upvoted your post');
+ sendNotificationToPostOwner(data, socket.uid, 'notifications:upvoted_your_post');
};
SocketPosts.downvote = function(socket, data, callback) {
@@ -62,7 +62,7 @@ SocketPosts.unvote = function(socket, data, callback) {
SocketPosts.favourite = function(socket, data, callback) {
favouriteCommand('favourite', 'favourited', socket, data, callback);
- sendNotificationToPostOwner(data, socket.uid, 'has favourited your post');
+ sendNotificationToPostOwner(data, socket.uid, 'notifications:favourited_your_post');
};
SocketPosts.unfavourite = function(socket, data, callback) {
@@ -87,7 +87,7 @@ function favouriteCommand(command, eventName, socket, data, callback) {
}
}
-function sendNotificationToPostOwner(data, uid, message) {
+function sendNotificationToPostOwner(data, uid, notification) {
if(data && data.pid && uid) {
posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) {
if (err) {
@@ -109,8 +109,9 @@ function sendNotificationToPostOwner(data, uid, message) {
if (err) {
return;
}
+
notifications.create({
- text: '' + results.username + ' ' + message,
+ text: '[[' + notification + ', ' + results.username + ']]',
path: nconf.get('relative_path') + '/topic/' + results.slug + '#' + data.pid,
uniqueId: 'post:' + data.pid,
from: uid
@@ -258,7 +259,7 @@ SocketPosts.flag = function(socket, pid, callback) {
user.getUserField(socket.uid, 'username', next);
},
function(username, next) {
- message = '' + username + ' flagged a post.';
+ message = '[[notifications:user_flagged_post, ' + username + ']]';
posts.getPostField(pid, 'tid', next);
},
function(tid, next) {
diff --git a/src/threadTools.js b/src/threadTools.js
index 565bf93ec6..d2de95bb3f 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -229,7 +229,7 @@ var winston = require('winston'),
}
notifications.create({
- text: '' + username + ' has posted a reply to: "' + topicData.title + '"',
+ text: '[[notifications:user_posted_to, ' + username + ', ' + topicData.title + ']]',
path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,
uniqueId: 'topic:' + tid,
from: exceptUid
diff --git a/src/user/create.js b/src/user/create.js
index 87c90e4076..37cff32d72 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -49,7 +49,6 @@ module.exports = function(User) {
}
if (exists) {
async.forever(function(next) {
- // Append a random number to the username
var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
User.exists(newUsername, function(err, exists) {
if (!exists) {
@@ -87,10 +86,11 @@ module.exports = function(User) {
if (err) {
return callback(err);
}
- userData = results[results.length - 1];
+ userData = results[results.length - 1];
+ var userNameChanged = !!results[3];
// If a new username was picked...
- if (results[3]) {
+ if (userNameChanged) {
userData.username = results[3];
userData.userslug = utils.slugify(results[3]);
}
@@ -149,16 +149,13 @@ module.exports = function(User) {
groups.join('registered-users', uid);
- // If their username was automatically changed...
- if (results[3]) {
- translator.translate('[[user:username_taken_workaround, ' + userData.username + ']]', function(notifText) {
- notifications.create({
- text: notifText,
- picture: 'brand:logo',
- datetime: Date.now()
- }, function(nid) {
- notifications.push(nid, uid);
- });
+ if (userNameChanged) {
+ notifications.create({
+ text: '[[user:username_taken_workaround, ' + userData.username + ']]',
+ picture: 'brand:logo',
+ datetime: Date.now()
+ }, function(nid) {
+ notifications.push(nid, uid);
});
}
diff --git a/src/user/notifications.js b/src/user/notifications.js
index 9ac5b820c6..fd6c0dab72 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -153,7 +153,7 @@ var async = require('async'),
db.getSetMembers('followers:' + uid, function(err, followers) {
if (followers && followers.length) {
topics.getTopicField(tid, 'slug', function(err, slug) {
- var message = '' + username + ' made a new post';
+ var message = '[[notifications:user_made_post, ' + username + ']]';
notifications.create({
text: message,