Skip to content

Node.js based forum software built for the modern web

added toPid to posts

Baris Soner Usaklid6d9776cde44
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index dbb1aa3431..e9fa69e934 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -405,13 +405,14 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
var username = '',
- post = $(this).parents('li[data-pid]');
+ post = $(this).parents('li[data-pid]'),
+ pid = $(this).parents('.post-row').attr('data-pid');
if (post.length) {
username = '@' + post.attr('data-username').replace(/\s/g, '-') + ' ';
}
if (thread_state.locked !== '1') {
- composer.newReply(tid, topic_name, selectionText.length > 0 ? selectionText + '\n\n' + username : '' + username);
+ composer.newReply(tid, pid, topic_name, selectionText.length > 0 ? selectionText + '\n\n' + username : '' + username);
}
});
@@ -436,7 +437,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
if($('.composer').length) {
composer.addQuote(tid, pid, topic_name, username, quoted);
}else {
- composer.newReply(tid, topic_name, username + ' said:\n' + quoted);
+ composer.newReply(tid, pid, topic_name, username + ' said:\n' + quoted);
}
});
}
diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index 3e352401a4..9c1bbf351c 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -294,22 +294,22 @@ define(['taskbar'], function(taskbar) {
var prevText = bodyEl.val();
if(tid !== composer.posts[uuid].tid) {
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
- }else {
+ } else {
text = username + ' said:\n' + text;
}
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body);
- }else{
- composer.newReply(tid,title,username + ' said:\n' + text);
+ } else {
+ composer.newReply(tid, pid, title, username + ' said:\n' + text);
}
-
}
};
- composer.newReply = function(tid, title, text) {
+ composer.newReply = function(tid, pid, title, text) {
if(allowed()) {
push({
tid: tid,
+ toPid: pid,
title: title,
body: text,
modified: false,
@@ -737,7 +737,8 @@ define(['taskbar'], function(taskbar) {
} else if (parseInt(postData.tid, 10) > 0) {
socket.emit('posts.reply', {
topic_id: postData.tid,
- content: bodyEl.val()
+ content: bodyEl.val(),
+ toPid: postData.toPid
}, done);
} else if (parseInt(postData.pid, 10) > 0) {
socket.emit('posts.edit', {
diff --git a/src/posts.js b/src/posts.js
index b010ef19b5..fa3703a585 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -20,7 +20,12 @@ var db = require('./database'),
(function(Posts) {
var customUserInfo = {};
- Posts.create = function(uid, tid, content, callback) {
+ Posts.create = function(data, callback) {
+ var uid = data.uid,
+ tid = data.tid,
+ content = data.content,
+ toPid = data.toPid;
+
if (uid === null) {
return callback(new Error('invalid-user'), null);
}
@@ -56,6 +61,10 @@ var db = require('./database'),
'deleted': 0
};
+ if (toPid) {
+ postData['toPid'] = toPid;
+ }
+
db.setObject('post:' + pid, postData, function(err) {
if(err) {
return next(err);
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 2d10ec91b1..2b54551554 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -14,6 +14,7 @@ var async = require('async'),
SocketPosts = {};
SocketPosts.reply = function(socket, data, callback) {
+
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
socket.emit('event:alert', {
title: 'Reply Unsuccessful',
@@ -28,7 +29,9 @@ SocketPosts.reply = function(socket, data, callback) {
return callback(new Error('invalid data'));
}
- topics.reply(data.topic_id, socket.uid, data.content, function(err, postData) {
+ data.uid = socket.uid;
+
+ topics.reply(data, function(err, postData) {
if(err) {
if (err.message === 'content-too-short') {
module.parent.exports.emitContentTooShortAlert(socket);
diff --git a/src/topics.js b/src/topics.js
index 7e0362e2cd..b7e22871a5 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -121,7 +121,7 @@ var async = require('async'),
Topics.create({uid: uid, title: title, cid: cid, thumb: thumb}, next);
},
function(tid, next) {
- Topics.reply(tid, uid, content, next);
+ Topics.reply({uid:uid, tid:tid, content:content}, next);
},
function(postData, next) {
threadTools.toggleFollow(postData.tid, uid);
@@ -143,9 +143,13 @@ var async = require('async'),
], callback);
};
- Topics.reply = function(tid, uid, content, callback) {
- var privileges;
- var postData;
+ Topics.reply = function(data, callback) {
+ var tid = data.topic_id,
+ uid = data.uid,
+ toPid = data.toPid,
+ content = data.content,
+ privileges,
+ postData;
async.waterfall([
function(next) {
@@ -170,7 +174,7 @@ var async = require('async'),
return next(new Error('content-too-short'));
}
- posts.create(uid, tid, content, next);
+ posts.create({uid:uid, tid:tid, content:content, toPid:toPid}, next);
},
function(data, next) {
postData = data;