mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 08:31:22 +01:00
nested reply improvements
on new post increase count and add nested reply if replies are expanded on post purge reduce count and remove nested reply
This commit is contained in:
@@ -166,15 +166,16 @@ define('forum/topic/events', [
|
||||
return false;
|
||||
}
|
||||
|
||||
function onPostPurged(pid) {
|
||||
components.get('post', 'pid', pid).fadeOut(500, function () {
|
||||
function onPostPurged(postData) {
|
||||
components.get('post', 'pid', postData.pid).fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
ajaxify.data.postcount --;
|
||||
postTools.updatePostCount(ajaxify.data.postcount);
|
||||
posts.showBottomPostBar();
|
||||
});
|
||||
|
||||
postTools.updatePostCount();
|
||||
ajaxify.data.postcount --;
|
||||
postTools.updatePostCount(ajaxify.data.postcount);
|
||||
require(['forum/topic/replies'], function (replies) {
|
||||
replies.onPostPurged(postData);
|
||||
});
|
||||
}
|
||||
|
||||
function togglePostDeleteState(data) {
|
||||
|
||||
@@ -37,6 +37,10 @@ define('forum/topic/posts', [
|
||||
} else {
|
||||
onNewPostInfiniteScroll(data);
|
||||
}
|
||||
|
||||
require(['forum/topic/replies'], function (replies) {
|
||||
replies.onNewPost(data);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.modifyPostsByPrivileges = function (posts) {
|
||||
|
||||
@@ -42,6 +42,8 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
|
||||
var tplData = {
|
||||
posts: data,
|
||||
privileges: ajaxify.data.privileges,
|
||||
'downvote:disabled': ajaxify.data['downvote:disabled'],
|
||||
'reputation:disabled': ajaxify.data['reputation:disabled'],
|
||||
loggedIn: !!app.user.uid,
|
||||
hideReplies: true
|
||||
};
|
||||
@@ -60,5 +62,34 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
|
||||
}
|
||||
}
|
||||
|
||||
Replies.onNewPost = function (data) {
|
||||
var post = data.posts[0];
|
||||
if (!post) {
|
||||
return;
|
||||
}
|
||||
incrementCount(post, 1);
|
||||
data.hideReplies = true;
|
||||
app.parseAndTranslate('topic', 'posts', data, function (html) {
|
||||
var replies = $('[component="post"][data-pid="' + post.toPid + '"] [component="post/replies"]').first();
|
||||
if (replies.length) {
|
||||
replies.append(html);
|
||||
posts.processPage(html);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Replies.onPostPurged = function (post) {
|
||||
incrementCount(post, -1);
|
||||
};
|
||||
|
||||
function incrementCount(post, inc) {
|
||||
var replyCount = $('[component="post"][data-pid="' + post.toPid + '"]').find('[component="post/reply-count"]').first();
|
||||
var countEl = replyCount.find('[component="post/reply-count/text"]');
|
||||
var count = Math.max(0, parseInt(countEl.attr('data-replies'), 10) + inc);
|
||||
countEl.attr('data-replies', count);
|
||||
replyCount.toggleClass('hidden', !count);
|
||||
countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]');
|
||||
}
|
||||
|
||||
return Replies;
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var validator = require('validator');
|
||||
|
||||
var posts = require('../../posts');
|
||||
@@ -137,28 +136,29 @@ module.exports = function (SocketPosts) {
|
||||
|
||||
SocketPosts.purge = function (socket, data, callback) {
|
||||
function purgePost() {
|
||||
posts.tools.purge(socket.uid, data.pid, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
websockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
|
||||
|
||||
topics.getTopicField(data.tid, 'title', function (err, title) {
|
||||
if (err) {
|
||||
return winston.error(err);
|
||||
}
|
||||
var postData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
posts.getPostField(data.pid, 'toPid', next);
|
||||
},
|
||||
function (toPid, next) {
|
||||
postData = {pid: data.pid, toPid: toPid};
|
||||
posts.tools.purge(socket.uid, data.pid, next);
|
||||
},
|
||||
function (next) {
|
||||
websockets.in('topic_' + data.tid).emit('event:post_purged', postData);
|
||||
topics.getTopicField(data.tid, 'title', next);
|
||||
},
|
||||
function (title, next) {
|
||||
events.log({
|
||||
type: 'post-purge',
|
||||
uid: socket.uid,
|
||||
pid: data.pid,
|
||||
ip: socket.ip,
|
||||
title: validator.escape(String(title))
|
||||
});
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
if (!data || !parseInt(data.pid, 10)) {
|
||||
|
||||
@@ -8,6 +8,7 @@ var db = require('./mocks/databasemock');
|
||||
var topics = require('../src/topics');
|
||||
var posts = require('../src/posts');
|
||||
var categories = require('../src/categories');
|
||||
var privileges = require('../src/privileges');
|
||||
var user = require('../src/user');
|
||||
|
||||
describe('Post\'s', function () {
|
||||
@@ -135,6 +136,7 @@ describe('Post\'s', function () {
|
||||
|
||||
describe('delete/restore/purge', function () {
|
||||
var pid;
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
before(function (done) {
|
||||
topics.reply({
|
||||
uid: voterUid,
|
||||
@@ -144,14 +146,13 @@ describe('Post\'s', function () {
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
pid = data.pid;
|
||||
done();
|
||||
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a post', function (done) {
|
||||
posts.delete(pid, voterUid, function (err, postData) {
|
||||
socketPosts.delete({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
assert(postData);
|
||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
assert.equal(parseInt(isDeleted, 10), 1);
|
||||
@@ -161,9 +162,8 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should restore a post', function (done) {
|
||||
posts.restore(pid, voterUid, function (err, postData) {
|
||||
socketPosts.restore({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
assert(postData);
|
||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
assert.equal(parseInt(isDeleted, 10), 0);
|
||||
@@ -173,9 +173,8 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should purge a post', function (done) {
|
||||
posts.purge(pid, voterUid, function (err) {
|
||||
socketPosts.purge({uid: voterUid}, {pid: pid}, function (err) {
|
||||
assert.ifError(err);
|
||||
assert.equal(arguments.length, 1);
|
||||
posts.exists('post:' + pid, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
assert.equal(exists, false);
|
||||
|
||||
Reference in New Issue
Block a user