Skip to content

Node.js based forum software built for the modern web

fixed sorting for topics

Baris Soner Usaklic1ba447aec36
diff --git a/src/categories.js b/src/categories.js
index 135f6e2a16..043b50ef89 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -36,7 +36,16 @@ var RDB = require('./redis.js'),
function getTopics(next) {
Categories.getTopicsByTids(tids, current_user, function(topics) {
+ // Float pinned topics to the top
+ topics = topics.sort(function(a, b) {
+ if (a.pinned !== b.pinned) return b.pinned - a.pinned;
+ else {
+ return b.timestamp - a.timestamp;
+ }
+ });
+ console.log(topics);
next(null, topics);
+
}, category_id);
}
@@ -202,15 +211,6 @@ var RDB = require('./redis.js'),
}
}
- // Float pinned topics to the top
- retrieved_topics = retrieved_topics.sort(function(a, b) {
- if (a.pinned !== b.pinned) return b.pinned - a.pinned;
- else {
- // assume equal, tids are already sorted due to RDB.zadd(schema.topics().recent, Date.now(), tid);
- return 0;
- }
- });
-
callback(retrieved_topics);
});
});