Skip to content

Commit

Permalink
Refactor formats a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
arj03 committed Sep 6, 2021
1 parent 287ab25 commit 89285a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down

0 comments on commit 89285a4

Please sign in to comment.