Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ssbc/ssb-tribes into no-use-testbot
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Nov 2, 2023
2 parents cb9d209 + f324d2a commit 1880e22
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ A Secret-Stack server running the plugins:
- `ssb-tribes`
- `ssb-db2/compat`
- `ssb-db2/compat/feedstate`
- `ssb-box2` >= TODO
- `ssb-box2` >= 7.2.0
- `ssb-replicate` - (optional) used to auto-replicate people who you're in groups with

The secret stack option `config.box2.legacyMode` also needs to be `true`.
Expand Down
70 changes: 35 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,52 +195,52 @@ function init (ssb, config) {
const getMembersTangle = GetGroupTangle(ssb, null, 'members')

const tribePublish = (content, cb) => {
if (!content.recps) {
return ssb.db.create({
content
}, cb)
}
if (!content.recps) {
return ssb.db.create({
content
}, cb)
}

if (!isGroup(content.recps[0])) {
return ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
}
if (!isGroup(content.recps[0])) {
return ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
}

ssb.box2.getGroupInfo(content.recps[0], (err, groupInfo) => {
if (err) return cb(Error('error on getting group info in publish', { cause: err }))
ssb.box2.getGroupInfo(content.recps[0], (err, groupInfo) => {
if (err) return cb(Error('error on getting group info in publish', { cause: err }))

if (!groupInfo) return cb(Error('unknown groupId'))
if (!groupInfo) return cb(Error('unknown groupId'))

getGroupTangle(content.recps[0], (err, groupTangle) => {
if (err) return cb(Error("Couldn't get group tangle", { cause: err }))
getGroupTangle(content.recps[0], (err, groupTangle) => {
if (err) return cb(Error("Couldn't get group tangle", { cause: err }))

set(content, 'tangles.group', groupTangle)
tanglePrune(content) // prune the group tangle down if needed
set(content, 'tangles.group', groupTangle)
tanglePrune(content) // prune the group tangle down if needed

// we only want to have to calculate the members tangle if it's gonna be used
if (!isMemberType(content.type)) {
return ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
}
// we only want to have to calculate the members tangle if it's gonna be used
if (!isMemberType(content.type)) {
return ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
}

getMembersTangle(content.recps[0], (err, membersTangle) => {
if (err) return cb(Error("Couldn't get members tangle", { cause: err }))
getMembersTangle(content.recps[0], (err, membersTangle) => {
if (err) return cb(Error("Couldn't get members tangle", { cause: err }))

set(content, 'tangles.members', membersTangle)
tanglePrune(content, 'members')
set(content, 'tangles.members', membersTangle)
tanglePrune(content, 'members')

ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
})
ssb.db.create({
content,
encryptionFormat: 'box2'
}, cb)
})
})
}
})
}

const scuttle = Method(ssb) // ssb db methods

Expand Down
2 changes: 1 addition & 1 deletion lib/get-group-tangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function GetGroupTangle (server, _, tangle = 'group') {
pull(
server.db.query(
where(
equal(seekTanglesTangleRoot, info.root, { indexType: 'tanglesTangleRoot', prefix: true })
equal(seekTanglesTangleRoot, info.root, { indexType: `tangles${tangle}Update`, prefix: true })
),
toPullStream()
),
Expand Down
18 changes: 3 additions & 15 deletions listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ module.exports = {
dbLive({ old: true }),
toPullStream()
),
pull(
ssb.db.reindexed(),
pull.filter((msg) => {
return msg.value.content.type === 'group/add-member'
})
)
ssb.db.reindexed()
]),
// NOTE this will run through all messages on each startup, which will help guarentee
// all messages have been emitted AND processed
Expand All @@ -53,12 +48,7 @@ module.exports = {
dbLive({ old: true }),
toPullStream()
),
pull(
ssb.db.reindexed(),
pull.filter((msg) => {
return msg.value.content.type === 'group/exclude-member'
})
)
ssb.db.reindexed()
]),
pull.filter(m => m.sync !== true),
pull.filter(isExcludeMember),
Expand All @@ -82,9 +72,7 @@ module.exports = {
),
pull(
ssb.db.reindexed(),
pull.filter((msg) => {
return msg.value.content.type === 'group/po-box'
})
pull.filter(msg => msg.value.content.type === 'group/po-box')
)
]),
// NOTE this will run through all messages on each startup, which will help guarentee
Expand Down
20 changes: 7 additions & 13 deletions method/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ module.exports = function GroupMethods (ssb) {
if (!initSpec.isValid(content)) return cb(new Error(initSpec.isValid.errorsString))

/* enveloping */
// we have to do it manually this one time, because the auto-boxing checks for a known groupId
// we have to do it differently this one time, because the auto-boxing checks for a known groupId
// but the groupId is derived from the messageId of this message (which does not exist yet
// const plain = Buffer.from(JSON.stringify(content), 'utf8')

// const msgKey = new SecretKey().toBuffer()
const recps = [
{ key: groupKey.toBuffer(), scheme: keySchemes.private_group },
ssb.id // sneak this in so can decrypt it ourselves without rebuild!
Expand Down Expand Up @@ -86,13 +84,9 @@ module.exports = function GroupMethods (ssb) {
groupKey: writeKey.key.toString('base64'),
root,
tangles: {
members: {
root,
previous: [root] // TODO calculate previous for members tangle
},

group: { root, previous: [root] }
// NOTE: this is a dummy entry which is over-written in publish hook
group: { root, previous: [root] },
members: { root, previous: [root] }
// NOTE: these are dummy entries which are over-written in the publish function
},
recps: [groupId, ...authorIds]
}
Expand All @@ -114,9 +108,9 @@ module.exports = function GroupMethods (ssb) {
type: 'group/exclude-member',
excludes: authorIds,
tangles: {
members: { root, previous: [root] },
group: { root, previous: [root] }
// NOTE: these are dummy entries which are over-written in the publish hook
group: { root, previous: [root] },
members: { root, previous: [root] }
// NOTE: these are dummy entries which are over-written in the publish function
},
recps: [groupId]
}
Expand Down
4 changes: 2 additions & 2 deletions method/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ module.exports = function Link (ssb) {
where(
and(
dbType(type),
parent && equal(seekParent, parent, { indexType: 'parent', prefix: true }),
child && equal(seekChild, child, { indexType: 'child', prefix: true }),
parent && equal(seekParent, parent, { indexType: 'linkParent', prefix: true }),
child && equal(seekChild, child, { indexType: 'linkChild', prefix: true }),
equal(seekTanglesLinkRoot, null, { indexType: 'tanglesLinkRoot', prefix: true }),
equal(seekTanglesLinkPrevious, null, { indexType: 'tanglesLinkPrevious', prefix: true })
)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"cross-env": "^7.0.3",
"is-canonical-base64": "^1.1.1",
"scuttle-testbot": "github:ssbc/scuttle-testbot#no-use",
"ssb-box2": "ssbc/ssb-box2#pobox",
"ssb-box2": "^7.2.0",
"ssb-db2": "^7.1.1",
"ssb-replicate": "^1.3.3",
"standard": "^17.1.0",
Expand Down

0 comments on commit 1880e22

Please sign in to comment.