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

Delete group feeds when getting excluded from a group #102

Open
Powersource opened this issue Apr 26, 2023 · 0 comments
Open

Delete group feeds when getting excluded from a group #102

Powersource opened this issue Apr 26, 2023 · 0 comments

Comments

@Powersource
Copy link
Collaborator

Powersource commented Apr 26, 2023

To save storage and for privacy.

Note that this doesn't delete every message related to the group, there are also the group feed announce messages, and member addition messages. We don't want to delete those messages, but we want to delete their secrets. That's a different issue though #103

This came up in #101 (not super relevant though)

The code might look a bit something like this

diff --git a/index.js b/index.js
index 3d574f6..772e891 100644
--- a/index.js
+++ b/index.js
@@ -503,7 +508,26 @@ module.exports = {
           pull.drain(
             (msg) => {
               const groupId = msg.value.content.recps[0]
-              ssb.box2.excludeGroupInfo(groupId, null)
+              get(groupId, (err, groupInfo) => {
+                // prettier-ignore
+                if (err) return cb(clarify(err, 'todo'))
+
+                pull(
+                  ssb.metafeeds.branchStream({ old: true, live: false }),
+                  // get all leaf feeds
+                  pull.filter((branch) => branch.length === 4),
+                  pull.map((branch) => branch[3]),
+                  // get all feeds for this epoch
+                  pull.filter(
+                    (feed) =>
+                      feed.purpose === groupInfo.writeKey.key.toString('base64')
+                  )
+                )
+                ssb.box2.excludeGroupInfo(groupId, (err) => {
+                  // prettier-ignore
+                  if (err) return cb(clarify(err, 'Error on excluding group info after finding exclusion of ourselves'))
+                })
+              })
             },
             (err) => {
               // prettier-ignore

would have to move the excludeGroupInfo into a drain in the pull. And in the drain we'd delete the feeds safely using https://github.com/ssbc/ssb-db2#deletefeedfeedid-cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant