diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 363fd8dfe0..45ba58259a 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -663,20 +663,26 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
}, duration !== undefined ? duration : 400, function() {
scrollingToPost = false;
updateHeader();
- if (highlight) {
- scrollTo.parent().find('.topic-item').addClass('highlight');
- setTimeout(function() {
- scrollTo.parent().find('.topic-item').removeClass('highlight');
- }, 5000);
- }
+ highlightPost();
});
}
+ function highlightPost() {
+ if (highlight) {
+ scrollTo.parent().find('.topic-item').addClass('highlight');
+ setTimeout(function() {
+ scrollTo.parent().find('.topic-item').removeClass('highlight');
+ }, 5000);
+ }
+ }
+
+
if (tid && scrollTo.length) {
if($('#post-container li.post-row[data-pid="' + pid + '"]').attr('data-index') !== '0') {
animateScroll();
} else {
updateHeader();
+ highlightPost();
}
}
}
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 22539b0d4b..3a11a5b659 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -80,6 +80,7 @@ SocketPosts.reply = function(socket, data, callback) {
SocketPosts.upvote = function(socket, data) {
favouriteCommand('upvote', socket, data);
+ sendNotificationToPostOwner(data, socket.uid, 'has upvoted your post');
};
SocketPosts.downvote = function(socket, data) {
@@ -92,6 +93,7 @@ SocketPosts.unvote = function(socket, data) {
SocketPosts.favourite = function(socket, data) {
favouriteCommand('favourite', socket, data);
+ sendNotificationToPostOwner(data, socket.uid, 'has favourited your post');
};
SocketPosts.unfavourite = function(socket, data) {
@@ -104,6 +106,37 @@ function favouriteCommand(command, socket, data) {
}
}
+function sendNotificationToPostOwner(data, uid, message) {
+ if(data && data.pid && uid) {
+ posts.getPostFields(data.pid, ['tid', 'uid'], function(err, postData) {
+ if (err) {
+ return;
+ }
+
+ async.parallel({
+ username: function(next) {
+ user.getUserField(uid, 'username', next);
+ },
+ slug: function(next) {
+ topics.getTopicField(postData.tid, 'slug', next);
+ }
+ }, function(err, results) {
+ if (err) {
+ return;
+ }
+ notifications.create({
+ text: '' + results.username + ' ' + message,
+ path: nconf.get('relative_path') + '/topic/' + results.slug + '#' + data.pid,
+ uniqueId: 'post:' + data.pid,
+ from: uid
+ }, function(nid) {
+ notifications.push(nid, [postData.uid]);
+ });
+ });
+ });
+ }
+}
+
SocketPosts.getRawPost = function(socket, pid, callback) {
posts.getPostFields(pid, ['content', 'deleted'], function(err, data) {
if(err) {
@@ -248,7 +281,7 @@ SocketPosts.flag = function(socket, pid, callback) {
user.getUserField(socket.uid, 'username', next);
},
function(username, next) {
- message = username + ' flagged a post.';
+ message = '' + username + ' flagged a post.';
posts.getPostField(pid, 'tid', next);
},
function(tid, next) {
@@ -306,6 +339,6 @@ SocketPosts.getRecentPosts = function(socket, data, callback) {
SocketPosts.getCategory = function(socket, pid, callback) {
posts.getCidByPid(pid, callback);
-}
+};
module.exports = SocketPosts;
\ No newline at end of file