teaser fixes

if a post is deleted/restored update the teaser to the latest undeleted
pid, if all posts are deleted it will be set to null
v1.18.x
Barış Soner Uşaklı
parent edb856ba90
commit e7dd881092

@ -33,6 +33,9 @@ module.exports = function(Posts) {
},
function(next) {
Posts.dismissFlag(pid, next);
},
function(next) {
topics.updateTeaser(postData.tid, next);
}
], function(err) {
callback(err, postData);
@ -64,6 +67,9 @@ module.exports = function(Posts) {
},
function(next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, pid, next);
},
function(next) {
topics.updateTeaser(postData.tid, next);
}
], function(err) {
callback(err, postData);

@ -165,17 +165,23 @@ module.exports = function(Topics) {
};
Topics.getLatestUndeletedPid = function(tid, callback) {
Topics.getLatestUndeletedReply(tid, function(err, pid) {
if (err) {
return callback(err);
}
if (parseInt(pid, 10)) {
return callback(null, pid.toString());
async.waterfall([
function(next) {
Topics.getLatestUndeletedReply(tid, next);
},
function(pid, next) {
if (parseInt(pid, 10)) {
return callback(null, pid.toString());
}
Topics.getTopicField(tid, 'mainPid', next);
},
function(mainPid, next) {
posts.getPostFields(mainPid, ['pid', 'deleted'], next);
},
function(mainPost, next) {
next(null, parseInt(mainPost.pid, 10) && parseInt(mainPost.deleted, 10) !== 1 ? mainPost.pid.toString() : null);
}
Topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
callback(err, parseInt(mainPid, 10) ? mainPid.toString() : null);
});
});
], callback);
};
Topics.getLatestUndeletedReply = function(tid, callback) {
@ -199,8 +205,11 @@ module.exports = function(Topics) {
if (err) {
return next(err);
}
latestPid = pids[0];
isDeleted = parseInt(deleted, 10) === 1;
if (!isDeleted) {
latestPid = pids[0];
}
++index;
next();
});

@ -101,11 +101,12 @@ module.exports = function(Topics) {
};
Topics.updateTeaser = function(tid, callback) {
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
Topics.getLatestUndeletedPid(tid, function(err, pid) {
if (err) {
return callback(err);
}
var pid = Array.isArray(pids) && pids.length ? pids[0] : null;
pid = pid || null;
Topics.setTopicField(tid, 'teaserPid', pid, callback);
});
};

Loading…
Cancel
Save