aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-05 12:11:30 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-12-07 16:48:18 -1000
commit01ea88684375793b3e009d8cefb9722384e2c88b (patch)
treecdaddc1fa01de9aeaf1ab490b186fc0e83556abf
parentd7c4e48d49294efeb2d0597185956e18d20df928 (diff)
downloadpatchfoo-01ea88684375793b3e009d8cefb9722384e2c88b.tar.gz
patchfoo-01ea88684375793b3e009d8cefb9722384e2c88b.zip
Sort messages in thread by timestamp
ssb-sort was not doing so well
-rw-r--r--lib/serve.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 41d4d6f..d9df589 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -3,7 +3,7 @@ var qs = require('querystring')
var pull = require('pull-stream')
var path = require('path')
var paramap = require('pull-paramap')
-var sort = require('ssb-sort')
+var ssbSort = require('ssb-sort')
var crypto = require('crypto')
var toPull = require('stream-to-pull-stream')
var serveEmoji = require('emoji-server')()
@@ -35,6 +35,18 @@ var hlCssDir = path.join(require.resolve('highlight.js'), '../../styles')
var urlIdRegex = /^(?:\/+(([%&@]|%25|%26)(?:[A-Za-z0-9\/+]|%2[Ff]|%2[Bb]){43}(?:=|%3D)\.(?:sha256|ed25519))([^?]*)?|(\/.*?))(?:\?(.*))?$/
+function compareMsgTs(msgA, msgB) {
+ var tsA = msgA && msgA.value && msgA.value.timestamp || msgA.timestamp
+ var tsB = msgB && msgB.value && msgB.value.timestamp || msgB.timestamp
+ return tsA - tsB
+}
+
+function sortMsgs(msgs) {
+ msgs.sort(compareMsgTs)
+ // ssbSort(msgs)
+ return msgs
+}
+
function ctype(name) {
switch (name && /[^.\/]*$/.exec(name)[0] || 'html') {
case 'html': return 'text/html'
@@ -550,7 +562,7 @@ Serve.prototype.new = function (ext) {
self.wrapPage('peers'),
self.respondSink(500, {'Content-Type': ctype(ext)})
)
- sort(msgs)
+ sortMsgs(msgs)
var maxTS = msgs.reduce(function (max, msg) {
return Math.max(msg.timestamp, max)
}, -Infinity)
@@ -1318,7 +1330,7 @@ Serve.prototype.channel = function (path) {
function threadHeads(msgs, rootId, opts) {
var includeVotes = opts && opts.includeVotes
- return sort.heads(msgs.filter(function (msg) {
+ return ssbSort.heads(msgs.filter(function (msg) {
var c = msg.value && msg.value.content
return (c && (
c.type === 'web-root' ? c.site === rootId :
@@ -1370,7 +1382,7 @@ Serve.prototype.streamThreadWithComposer = function (opts) {
if (err) return cb(new Error(err.stack))
var branches = threadHeads(links, threadRootId, threadHeadsOpts)
cb(null, pull(
- pull.values(sort(links)),
+ pull.values(sortMsgs(links)),
self.app.voteBranches && pull.map(function (link) {
var o = {}
for (var k in link) o[k] = link[k]
@@ -4232,7 +4244,7 @@ Serve.prototype.aboutDiff = function (url) {
function gotLinks(err, links) {
if (err) return cb(null, pull.once(u.renderError(err).outerHTML))
- sort(links)
+ sortMsgs(links)
links = links.filter(function (msg) {
var c = msg && msg.value && msg.value.content
return c && c.type === 'about' && c.about === rootId