git ssb

7+

dinoworm 🐛 / patchcore



Commit 8a6dee20553eb2c7dc78f6ae843306099b24b093

expose message.sync.timestamp, use minimum received/asserted value as asserted timestamp

handles clocks set into the future, and avoid received "3 mins from
now" issue!
Matt McKegg committed on 12/12/2017, 2:00:43 AM
Parent: 091cd9014a216a160e1b882346f8460330cf4c78

Files changed

feed/obs/recent.jschanged
feed/pull/channel.jschanged
feed/pull/public.jschanged
message/html/timestamp.jschanged
message/sync/timestamp.jsadded
feed/obs/recent.jsView
@@ -8,9 +8,10 @@
88
99 exports.gives = nest('feed.obs.recent')
1010
1111 exports.needs = nest({
12- 'sbot.pull.log': 'first'
12 + 'sbot.pull.log': 'first',
13 + 'message.sync.timestamp': 'first'
1314 })
1415
1516 exports.create = function (api) {
1617 return nest('feed.obs.recent', function (limit) {
@@ -21,9 +22,9 @@
2122 ])
2223 )
2324
2425 var result = MutantPullReduce(stream, (result, msg) => {
25- if (msg.value.timestamp && Date.now() - msg.value.timestamp < 24 * hr) {
26 + if (api.message.sync.timestamp(msg) && Date.now() - api.message.sync.timestamp(msg) < 24 * hr) {
2627 result.add(msg.value.author)
2728 }
2829 return result
2930 }, {
feed/pull/channel.jsView
@@ -5,9 +5,10 @@
55 exports.gives = nest('feed.pull.channel')
66 exports.needs = nest({
77 'sbot.pull.backlinks': 'first',
88 'channel.sync.normalize': 'first',
9- 'message.sync.isBlocked': 'first'
9 + 'message.sync.isBlocked': 'first',
10 + 'message.sync.timestamp': 'first'
1011 })
1112
1213 exports.create = function (api) {
1314 return nest('feed.pull.channel', function (channel) {
@@ -16,9 +17,9 @@
1617
1718 return function (opts) {
1819 // handle last item passed in as lt
1920 var lt = (opts.lt && opts.lt.value)
20- ? opts.lt.value.timestamp
21 + ? api.message.sync.timestamp(opts.lt)
2122 : opts.lt
2223
2324 delete opts.lt
2425
feed/pull/public.jsView
@@ -3,16 +3,17 @@
33
44 exports.gives = nest('feed.pull.public')
55 exports.needs = nest({
66 'sbot.pull.feed': 'first',
7- 'message.sync.isBlocked': 'first'
7 + 'message.sync.isBlocked': 'first',
8 + 'message.sync.timestamp': 'first'
89 })
910
1011 exports.create = function (api) {
1112 return nest('feed.pull.public', (opts) => {
1213 // handle last item passed in as lt
1314 opts.lt = (opts.lt && opts.lt.value)
14- ? opts.lt.value.timestamp
15 + ? api.message.sync.timestamp(opts.lt)
1516 : opts.lt
1617
1718 return pull(
1819 api.sbot.pull.feed(opts),
message/html/timestamp.jsView
@@ -1,17 +1,19 @@
11 const h = require('mutant/h')
22 const nest = require('depnest')
33
44 exports.gives = nest('message.html.timestamp')
5-exports.needs = nest('lib.obs.timeAgo', 'first')
5 +exports.needs = nest({
6 + 'lib.obs.timeAgo': 'first',
7 + 'message.sync.timestamp': 'first'
8 +})
69
710 exports.create = function (api) {
811 return nest('message.html.timestamp', timestamp)
912
1013 function timestamp (msg) {
1114 return h('a.Timestamp', {
1215 href: msg.key,
13- title: new Date(msg.value.timestamp)
14- }, api.lib.obs.timeAgo(msg.value.timestamp))
16 + title: new Date(api.message.sync.timestamp(msg))
17 + }, api.lib.obs.timeAgo(api.message.sync.timestamp(msg)))
1518 }
1619 }
17-
message/sync/timestamp.jsView
@@ -1,0 +1,18 @@
1 +var nest = require('depnest')
2 +
3 +exports.gives = nest('message.sync.timestamp', true)
4 +
5 +// get the asserted timestamp for a given message unless the message was
6 +// received before the claimed time, then use recieve time
7 +// (handles clocks set into the future, and avoid received "3 mins from now" issue!)
8 +
9 +exports.create = function (api) {
10 + return nest('message.sync.timestamp', function (msg) {
11 + if (!msg || !msg.value || !msg.value.timestamp) return
12 + if (msg.timestamp) {
13 + return Math.min(msg.timestamp, msg.value.timestamp)
14 + } else {
15 + return msg.value.timestamp
16 + }
17 + })
18 +}

Built with git-ssb-web