refactor deleter code to use unixtimestamp

v1.18.x
barisusakli 8 years ago
parent 447b7b02ca
commit 3b41c40b93

@ -146,24 +146,6 @@ topicsController.get = function (req, res, callback) {
next(null, data.topicData);
});
},
function (topicData, next) {
if (!topicData.deleterUid) {
return next(null, topicData);
}
user.getUserFields(topicData.deleterUid, ['username', 'userslug'], function(err, deleter) {
if (err) {
return next(err);
}
topicData.deleter = deleter;
topicData.deleter.timestampISO = topicData.deletedTimestampISO
delete topicData.deleterUid;
delete topicData.deletedTimestampISO;
next(null, topicData);
});
},
function (topicData, next) {
function findPost(index) {
for (var i = 0; i < topicData.posts.length; i += 1) {

@ -180,6 +180,7 @@ var social = require('./social');
isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid),
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
postSharing: async.apply(social.getActivePostSharing),
deleter: async.apply(getDeleter, topicData),
related: function (next) {
async.waterfall([
function (next) {
@ -202,6 +203,8 @@ var social = require('./social');
topicData.isIgnoring = results.isIgnoring[0];
topicData.bookmark = results.bookmark;
topicData.postSharing = results.postSharing;
topicData.deleter = results.deleter;
topicData.deletedTimestampISO = utils.toISOString(topicData.deletedTimestamp);
topicData.related = results.related || [];
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
@ -258,6 +261,13 @@ var social = require('./social');
], callback);
}
function getDeleter(topicData, callback) {
if (!topicData.deleterUid) {
return setImmediate(callback, null, null);
}
user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback);
}
Topics.getMainPost = function (tid, uid, callback) {
Topics.getMainPosts([tid], uid, function (err, mainPosts) {
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);

@ -21,7 +21,7 @@ module.exports = function (Topics) {
Topics.setTopicFields(tid, {
deleted: 1,
deleterUid: uid,
deletedTimestampISO: (new Date()).toISOString()
deletedTimestamp: Date.now(),
}, next);
},
function (next) {
@ -52,7 +52,7 @@ module.exports = function (Topics) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function (next) {
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestampISO'], next);
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestamp'], next);
},
function (next) {
Topics.updateRecent(tid, topicData.lastposttime, next);

Loading…
Cancel
Save