ssbc / ssb-tribes2

SSB private groups with ssb-db2
8 stars 1 forks source link

Delete group feeds when getting excluded from a group #102

Open Powersource opened 1 year ago

Powersource commented 1 year ago

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 https://github.com/ssbc/ssb-tribes2/issues/103

This came up in https://github.com/ssbc/ssb-tribes2/pull/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