git ssb

10+

Matt McKegg / patchwork



Commit 6bf1d61b158ce574e9cc6736605236ab1895c14f

sort backlinks by asserted time (or branch if available)

fixes #590
Matt McKegg committed on 7/18/2017, 4:29:22 AM
Parent: 8aaece459cf35d19c7635e39fdd6996ae3e029d2

Files changed

overrides/patchcore/backlinks/obs.jschanged
overrides/patchcore/backlinks/obs.jsView
@@ -4,8 +4,9 @@
44 var computed = require('mutant/computed')
55 var resolve = require('mutant/resolve')
66 var pull = require('pull-stream')
77 var onceIdle = require('mutant/once-idle')
8 +var sorted = require('sorted-array-functions')
89
910 exports.needs = nest({
1011 'sbot.pull.backlinks': 'first',
1112 'sbot.obs.connection': 'first',
@@ -64,9 +65,9 @@
6465 index: 'DTA' // use asserted timestamps
6566 }),
6667 pull.drain((msg) => {
6768 var value = resolve(collection)
68- value.push(msg)
69 + sorted.add(value, msg, compareAsserted)
6970 collection.set(value)
7071 }, () => {
7172 sync.set(true)
7273 })
@@ -117,4 +118,26 @@
117118 function unsubscribe (id) {
118119 onceTrue(api.sbot.obs.connection(), (sbot) => sbot.patchwork.liveBacklinks.unsubscribe(id))
119120 }
120121 }
122 +
123 +function compareAsserted (a, b) {
124 + if (isReplyTo(a, b)) {
125 + return -1
126 + } else if (isReplyTo(b, a)) {
127 + return 1
128 + } else {
129 + return a.value.timestamp - b.value.timestamp
130 + }
131 +}
132 +
133 +function isReplyTo (maybeReply, msg) {
134 + return (includesOrEquals(maybeReply.branch, msg.key))
135 +}
136 +
137 +function includesOrEquals (array, value) {
138 + if (Array.isArray(array)) {
139 + return array.includes(value)
140 + } else {
141 + return array === value
142 + }
143 +}

Built with git-ssb-web