diff --git a/compat/ebt.js b/compat/ebt.js index 94b78b2..23bd40a 100644 --- a/compat/ebt.js +++ b/compat/ebt.js @@ -3,26 +3,27 @@ // SPDX-License-Identifier: LGPL-3.0-only const pull = require('pull-stream') +const Hookable = require('hoox') const EBTIndex = require('../indexes/ebt') const { onceWhen } = require('../utils') exports.init = function (sbot, config) { sbot.db.registerIndex(EBTIndex) if (!sbot.post) sbot.post = sbot.db.post - sbot.getAtSequence = (key, cb) => { + sbot.getAtSequence = Hookable((key, cb) => { sbot.db.onDrain('ebt', () => { sbot.db.getIndex('ebt').getMessageFromAuthorSequence(key, cb) }) - } - sbot.getAtSequenceNativeMsg = (key, feedFormat, cb) => { + }) + sbot.getAtSequenceNativeMsg = Hookable((key, feedFormat, cb) => { sbot.db.onDrain('ebt', () => { sbot.db .getIndex('ebt') .getNativeMsgFromAuthorSequence(key, feedFormat, cb) }) - } - sbot.add = sbot.db.add - sbot.getVectorClock = function getVectorClock(cb) { + }) + sbot.add = Hookable(sbot.db.add) + sbot.getVectorClock = Hookable(function getVectorClock(cb) { onceWhen( sbot.db2migrate && sbot.db2migrate.synchronized, (isSynced) => isSynced === true, @@ -45,5 +46,5 @@ exports.init = function (sbot, config) { }) } ) - } + }) } diff --git a/compat/feedstate.js b/compat/feedstate.js index c53758c..d74302c 100644 --- a/compat/feedstate.js +++ b/compat/feedstate.js @@ -2,10 +2,11 @@ // // SPDX-License-Identifier: LGPL-3.0-only +const Hookable = require('hoox') const { onceWhen } = require('../utils') exports.init = function (sbot, config) { - sbot.getFeedState = function (feedId, cb) { + sbot.getFeedState = Hookable(function (feedId, cb) { onceWhen( sbot.db.stateFeedsReady, (ready) => ready === true, @@ -21,5 +22,5 @@ exports.init = function (sbot, config) { }) } ) - } + }) }