From 0bd830cf4ebf9cf3e4df1f2dba4b851b9361fc14 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 12 Dec 2019 21:02:57 -1000 Subject: Revert "Sort messages in thread by timestamp" This reverts commit 01ea88684375793b3e009d8cefb9722384e2c88b. Messages with wrong timestamps is more common than I thought. --- lib/serve.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/serve.js b/lib/serve.js index e865f75..17f809c 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 ssbSort = require('ssb-sort') +var sort = require('ssb-sort') var crypto = require('crypto') var toPull = require('stream-to-pull-stream') var serveEmoji = require('emoji-server')() @@ -35,18 +35,6 @@ 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' @@ -565,7 +553,7 @@ Serve.prototype.new = function (ext) { self.wrapPage('peers'), self.respondSink(500, {'Content-Type': ctype(ext)}) ) - sortMsgs(msgs) + sort(msgs) var maxTS = msgs.reduce(function (max, msg) { return Math.max(msg.timestamp, max) }, -Infinity) @@ -1333,7 +1321,7 @@ Serve.prototype.channel = function (path) { function threadHeads(msgs, rootId, opts) { var includeVotes = opts && opts.includeVotes - return ssbSort.heads(msgs.filter(function (msg) { + return sort.heads(msgs.filter(function (msg) { var c = msg.value && msg.value.content return (c && ( c.type === 'web-root' ? c.site === rootId : @@ -1385,7 +1373,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(sortMsgs(links)), + pull.values(sort(links)), self.app.voteBranches && pull.map(function (link) { var o = {} for (var k in link) o[k] = link[k] @@ -4321,7 +4309,7 @@ Serve.prototype.aboutDiff = function (url) { function gotLinks(err, links) { if (err) return cb(null, pull.once(u.renderError(err).outerHTML)) - sortMsgs(links) + sort(links) links = links.filter(function (msg) { var c = msg && msg.value && msg.value.content return c && c.type === 'about' && c.about === rootId -- cgit v1.2.3