-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix 'previous' in the members tangle #88
Changes from 17 commits
1b81850
a850a4f
0f34ae0
8259aca
af11d47
26dd2fc
fc7a2c0
cae98d7
f9d7a42
5e4ad46
59e2fe5
e522476
74624a5
5cf4f7f
cd11fa3
5438099
a29f1f9
b0d13f7
9ccfd24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,27 +214,40 @@ function init (ssb, config) { | |
* (because they can't post messages to the group before then) | ||
*/ | ||
|
||
const memberType = (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) | ||
const getGroupTangle = GetGroupTangle(ssb, keystore, 'group') | ||
const getMembersTangle = GetGroupTangle(ssb, keystore, 'members') | ||
ssb.publish.hook(function (publish, args) { | ||
const [content, cb] = args | ||
if (!content.recps) return publish.apply(this, args) | ||
|
||
if (!isGroup(content.recps[0])) return publish.apply(this, args) | ||
|
||
onKeystoreReady(() => { | ||
getGroupTangle(content.recps[0], (err, tangle) => { | ||
// NOTE there are two ways an err can occur in getGroupTangle | ||
// 1. recps is not a groupId | ||
// 2. unknown groupId, | ||
if (!keystore.group.has(content.recps[0])) return cb(Error('unknown groupId')) | ||
|
||
getGroupTangle(content.recps[0], (err, groupTangle) => { | ||
if (err) return cb(Error("Couldn't get group tangle", { cause: err })) | ||
|
||
// Rather than cb(err) here we we pass it on to boxers to see if an err is needed | ||
if (err) return publish.apply(this, args) | ||
// we only want to have to calculate the members tangle if it's gonna be used | ||
const maybeMembersTangle = memberType(content.type) | ||
? getMembersTangle | ||
: (_, cb) => cb() | ||
|
||
set(content, 'tangles.group', tangle) | ||
tanglePrune(content) // prune the group tangle down if needed | ||
maybeMembersTangle(content.recps[0], (err, membersTangle) => { | ||
if (err) return cb(Error("Couldn't get members tangle", { cause: err })) | ||
|
||
publish.call(this, content, cb) | ||
set(content, 'tangles.group', groupTangle) | ||
tanglePrune(content) // prune the group tangle down if needed | ||
if (memberType(content.type)) { | ||
set(content, 'tangles.members', membersTangle) | ||
tanglePrune(content, 'members') | ||
mixmix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
publish.call(this, content, cb) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the 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, 'group')
if (!memberType(content.type)) {
return publish.call(this, content, cb)
}
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')
publish.call(this, content, cb)
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah that's smart There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}) | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename
isMemberType
to hint it will returnBoolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done