Skip to content

Commit

Permalink
Remove some keystore usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Oct 20, 2023
1 parent 6b7a01e commit dd62bad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
44 changes: 21 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,24 @@ function init (ssb, config) {
.forEach(id => ssb.replicate.request({ id, replicate: true }))
})

state.loading.keystore.once(() => {
pull(
pull.values(keystore.group.listSync()),
paraMap(
(groupId, cb) => scuttle.group.listAuthors(groupId, (err, feedIds) => {
if (err) return cb(new Error('error listing authors to replicate on start'))
cb(null, feedIds)
}),
5
),
pull.flatten(),
pull.unique(),
pull.drain(feedId => {
if (feedId === ssb.id) return
ssb.replicate.request({ id: feedId, replicate: true })
}, (err) => {
if (err) console.error('error on initializing replication of group members')
})
)
})
pull(
ssb.box2.listGroupIds(),
paraMap(
(groupId, cb) => scuttle.group.listAuthors(groupId, (err, feedIds) => {
if (err) return cb(new Error('error listing authors to replicate on start'))
cb(null, feedIds)
}),
5
),
pull.flatten(),
pull.unique(),
pull.drain(feedId => {
if (feedId === ssb.id) return
ssb.replicate.request({ id: feedId, replicate: true })
}, (err) => {
if (err) console.error('error on initializing replication of group members')
})
)
}
})

Expand All @@ -208,12 +206,12 @@ function init (ssb, config) {
const isMemberType = (type) => type === 'group/add-member' || type === 'group/exclude-member'

/* Tangle: auto-add tangles.group info to all private-group messages */
const getGroupTangle = GetGroupTangle(ssb, keystore, 'group')
const getMembersTangle = GetGroupTangle(ssb, keystore, 'members')
const getGroupTangle = GetGroupTangle(ssb, null, 'group')
const getMembersTangle = GetGroupTangle(ssb, null, 'members')
// TODO: make this a ssb.tribes.publish function instead of a hook

/* API */
const scuttle = Method(ssb, keystore, state) // ssb db methods
const scuttle = Method(ssb) // ssb db methods

const tribeCreate = (opts, cb) => {
opts = opts || {} // NOTE this catches opts = null, leave it like this
Expand Down
2 changes: 1 addition & 1 deletion method/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const addMemberSpec = require('../spec/group/add-member')
const excludeMemberSpec = require('../spec/group/exclude-member')
const groupPoBoxSpec = require('../spec/group/po-box')

module.exports = function GroupMethods (ssb, keystore, state) {
module.exports = function GroupMethods (ssb) {
const groupPoBoxCrut = new Crut(
ssb,
groupPoBoxSpec,
Expand Down
24 changes: 4 additions & 20 deletions method/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
const Link = require('./link')
const Group = require('./group')

module.exports = function Method (ssb, keystore, state) {
module.exports = function Method (ssb) {
const link = Link(ssb)
const group = Group(ssb, keystore, state)
const group = Group(ssb)

return {
group: {
init: patient(group.init),
addMember: patient(group.addMember),
excludeMembers: patient(group.excludeMembers),
listAuthors: group.listAuthors,
addPOBox: patient(group.addPOBox),
getPOBox: group.getPOBox
},
group,

link
link,
// create createSubGroupLink findGroupByFeedId findParentGroupLinks findSubGroupLinks
}

function patient (fn) {
// for functions that need keystore to be ready
return function (...args) {
if (state.loading.keystore.value === false) return fn(...args)

state.loading.keystore.once(() => fn(...args))
}
}
}

0 comments on commit dd62bad

Please sign in to comment.