Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable checking of add-member spec #58

Merged
merged 14 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 48 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ module.exports = {
return pull(ssb.box2.listGroupIds({ live: !!opts.live }), paraMap(get, 4))
}

function getRootIdOfMsgAuthor(groupRootMsgId, cb) {
Powersource marked this conversation as resolved.
Show resolved Hide resolved
Powersource marked this conversation as resolved.
Show resolved Hide resolved
ssb.db.get(groupRootMsgId, (err, rootMsg) => {
// prettier-ignore
if (err) return cb(clarify(err, "couldn't get root msg for finding root feed"))

ssb.metafeeds.findRootFeedId(rootMsg.author, (err, rootFeedId) => {
// prettier-ignore
if (err) return cb(clarify(err, "couldn't find root feed id from root msg author"))

return cb(null, rootFeedId)
})
})
}

function addMembers(groupId, feedIds, opts = {}, cb) {
if (cb === undefined) return promisify(addMembers)(groupId, feedIds, opts)

Expand All @@ -328,41 +342,46 @@ module.exports = {
// prettier-ignore
if (err) return cb(clarify(err, `Failed to get group details when adding members`))

const content = {
type: 'group/add-member',
version: 'v2',
secret: secret.toString('base64'),
root,
tangles: {
members: {
root,
previous: [root], // TODO calculate previous for members tangle
},
// likely incorrect group tangle and this will be overwritten by
// publish(), we just add it here to make the spec pass
group: {
root,
previous: [root],
getRootIdOfMsgAuthor(root, (err, rootAuthorId) => {
// prettier-ignore
if (err) return cb(clarify(err, "couldn't get root id of author of root msg"))

const content = {
type: 'group/add-member',
version: 'v2',
groupKey: secret.toString('base64'),
root,
creator: rootAuthorId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed this (creator) being added to the spec? I dislike that it's like author. Why do we need it?

creator is the root metafeed id of the creator of the group

Nope, I was involved! I think we should call it groupCreatorRootFeedId or initAuthorRootrId .. if it's not too late :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too late! But this PR just adds the checking against the spec. Changing the field name would IMO be a different issue/pr.

tangles: {
members: {
root,
previous: [root], // TODO calculate previous for members tangle
},
// likely incorrect group tangle and this will be overwritten by
// publish(), we just add it here to make the spec pass
group: {
root,
previous: [root],
},
},
},
recps: [groupId, ...feedIds],
}

if (opts.text) content.text = opts.text
recps: [groupId, ...feedIds],
}

// TODO: this should accept bendybutt-v1 feed IDs
// if (!addMemberSpec(content))
// return cb(new Error(addMemberSpec.errorsString))
if (opts.text) content.text = opts.text

findOrCreateAdditionsFeed((err, additionsFeed) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Failed to find or create additions feed when adding members'))
if (!addMemberSpec(content))
Powersource marked this conversation as resolved.
Show resolved Hide resolved
return cb(new Error(addMemberSpec.errorsString))
Powersource marked this conversation as resolved.
Show resolved Hide resolved

addGroupTangle(content, (err, content) => {
findOrCreateAdditionsFeed((err, additionsFeed) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Failed to add group tangle when adding members'))
if (err) return cb(clarify(err, 'Failed to find or create additions feed when adding members'))

publishAndPrune(ssb, content, additionsFeed.keys, cb)
addGroupTangle(content, (err, content) => {
// prettier-ignore
if (err) return cb(clarify(err, 'Failed to add group tangle when adding members'))

publishAndPrune(ssb, content, additionsFeed.keys, cb)
})
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"fast-deep-equal": "^3.1.3",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"private-group-spec": "^2.0.0",
"private-group-spec": "^3.0.0",
"pull-paramap": "^1.2.2",
"pull-stream": "^3.7.0",
"ssb-bfe": "^3.7.0",
"ssb-box2": "^5.0.0",
"ssb-crut": "^4.6.1",
"ssb-db2": "^6.3.0",
"ssb-meta-feeds": "^0.38.2",
"ssb-meta-feeds": "github:ssbc/ssb-meta-feeds#find-root-feed-id",
Powersource marked this conversation as resolved.
Show resolved Hide resolved
"ssb-private-group-keys": "^1.1.1",
"ssb-ref": "^2.16.0",
"ssb-uri2": "^2.4.1"
Expand Down
5 changes: 4 additions & 1 deletion test/add-member.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ test('get added to a group', async (t) => {
id: groupId,
secret,
root,
} = await alice.tribes2.create().catch(t.fail)
} = await alice.tribes2.create().catch((err) => {
console.error("couldn't create group", err)
t.fail(err)
})
t.pass('alice created a group')

await alice.tribes2.addMembers(groupId, [bobRoot.id]).catch((err) => {
Expand Down