mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #12984, fix pids numeric sorting, handle non-integers
This commit is contained in:
@@ -24,7 +24,14 @@ module.exports = function (Topics) {
|
|||||||
throw new Error('[[error:invalid-pid]]');
|
throw new Error('[[error:invalid-pid]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
pids.sort((a, b) => a - b);
|
if (pids.every(isFinite)) {
|
||||||
|
pids.sort((a, b) => a - b);
|
||||||
|
} else {
|
||||||
|
const pidsDatetime = (await db.sortedSetScores(`tid:${fromTid}:posts`, pids)).map(t => t || 0);
|
||||||
|
const map = pids.reduce((map, pid, idx) => map.set(pidsDatetime[idx], pid), new Map());
|
||||||
|
pidsDatetime.sort((a, b) => a - b);
|
||||||
|
pids = pidsDatetime.map(key => map.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
const mainPid = pids[0];
|
const mainPid = pids[0];
|
||||||
if (!cid) {
|
if (!cid) {
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ module.exports = function (Topics) {
|
|||||||
timestampISO: replyPids.length ? utils.toISOString(pidMap[replyPids[0]].timestamp) : undefined,
|
timestampISO: replyPids.length ? utils.toISOString(pidMap[replyPids[0]].timestamp) : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
replyPids.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
|
replyPids.sort((a, b) => pidMap[a].timestamp - pidMap[b].timestamp);
|
||||||
|
|
||||||
replyPids.forEach((replyPid) => {
|
replyPids.forEach((replyPid) => {
|
||||||
const replyData = pidMap[replyPid];
|
const replyData = pidMap[replyPid];
|
||||||
|
|||||||
Reference in New Issue
Block a user