From 89285a4571f5ed71bb38352fdfe65e6550d32e4c Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Mon, 6 Sep 2021 11:11:03 +0200 Subject: [PATCH] Refactor formats a bit more --- index.js | 11 ++++++++++- test/clock.js | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f325e8d..a879f52 100644 --- a/index.js +++ b/index.js @@ -47,16 +47,25 @@ function cleanClock (clock, isFeed) { exports.init = function (sbot, config) { const formats = { 'classic': { + // used in sbot.post & in ebt:stream to distinguish between + // messages and notes isMsg(m) { return Number.isInteger(m.sequence) && m.sequence > 0 && typeof m.author == 'string' && m.content }, + // used in request, block, cleanClock isFeed: ref.isFeed, + // used in ebt:events getMsgAuthor(msg) { return msg.author }, + // used in ebt:events getMsgSequence(msg) { return msg.sequence + }, + // used in getAt + getAtTransform(msg) { + return msg ? msg.value : null } } } @@ -85,7 +94,7 @@ exports.init = function (sbot, config) { }, getAt (pair, cb) { sbot.getAtSequence([pair.id, pair.sequence], (err, data) => { - cb(err, data ? data.value : null) + cb(err, formats[formatName].getAtTransform(data)) }) }, append (msg, cb) { diff --git a/test/clock.js b/test/clock.js index a158fd7..0e5df1a 100644 --- a/test/clock.js +++ b/test/clock.js @@ -15,18 +15,18 @@ const CONNECTION_TIMEOUT = 500 // ms const REPLICATION_TIMEOUT = 2 * CONNECTION_TIMEOUT const alice = createSsbServer({ - temp: 'test-block-alice', + temp: 'test-clock-alice', timeout: CONNECTION_TIMEOUT, keys: u.keysFor('alice') }) const bob = createSsbServer({ - temp: 'test-block-bob', + temp: 'test-clock-bob', timeout: CONNECTION_TIMEOUT, keys: u.keysFor('bob') }) -tape('alice blocks bob, then unblocks', async (t) => { +tape('clock works', async (t) => { await Promise.all([ pify(alice.publish)({ type: 'post', text: 'hello' }), pify(bob.publish)({ type: 'post', text: 'hello' })