From 51f3f52b9584d4dcb8274be583a5c95111ead1eb Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Fri, 21 Apr 2023 13:59:53 +0300 Subject: [PATCH] add helper API: setFeedGoal(who,type) --- lib/plugin.js | 13 ++++++++++--- test/feed-sync.test.js | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index 325402c..71a2c17 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,5 +1,6 @@ const toPull = require('push-stream-to-pull-stream') const pull = require('pull-stream') +const FeedV1 = require('ppppp-db/lib/feed-v1') const makeDebug = require('debug') const getSeverity = require('ssb-network-errors') const Algorithm = require('./algorithm') @@ -67,11 +68,16 @@ module.exports = { } /** - * @param {string} id + * @param {string} tangleId * @param {Goal} goal */ - function setGoal(id, goal = 'all') { - goals.set(id, goal) + function setGoal(tangleId, goal = 'all') { + goals.set(tangleId, goal) + } + + function setFeedGoal(author, type, goal = 'all') { + const tangleId = FeedV1.getFeedRootHash(author, type) + goals.set(tangleId, goal) } function initiate() { @@ -83,6 +89,7 @@ module.exports = { return { connect, setGoal, + setFeedGoal, initiate, } }, diff --git a/test/feed-sync.test.js b/test/feed-sync.test.js index e68debd..1722a53 100644 --- a/test/feed-sync.test.js +++ b/test/feed-sync.test.js @@ -229,8 +229,8 @@ test('sync a feed with goal=newest but too far behind', async (t) => { t.deepEquals(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol') } - alice.tangleSync.setGoal(carolRootHash, 'newest-5') - bob.tangleSync.setGoal(carolRootHash, 'newest-5') + alice.tangleSync.setFeedGoal(carolID, 'post', 'newest-5') + bob.tangleSync.setFeedGoal(carolID, 'post', 'newest-5') const remoteAlice = await p(bob.connect)(alice.getAddress()) t.pass('bob connected to alice')