Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1026 from ssbc/add-deletion
Browse files Browse the repository at this point in the history
Add feed deletion
  • Loading branch information
Powersource committed Jun 23, 2019
2 parents 5b82942 + 87abaa2 commit 1819a26
Show file tree
Hide file tree
Showing 4 changed files with 529 additions and 27 deletions.
46 changes: 43 additions & 3 deletions lib/main-window.js
Expand Up @@ -14,6 +14,7 @@ var setupContextMenuAndSpellCheck = require('./context-menu-and-spellcheck')
var watch = require('mutant/watch')
var requireStyle = require('require-style')
var ssbUri = require('ssb-uri')
const pull = require('pull-stream')

try {
var mouseForwardBack = require('mouse-forward-back')
Expand Down Expand Up @@ -48,7 +49,8 @@ module.exports = function (config) {
'app.linkPreview': 'first',
'channel.obs.subscribed': 'first',
'settings.obs.get': 'first',
'intl.sync.i18n': 'first'
'intl.sync.i18n': 'first',
'contact.obs.blocking': 'first'
}))

const i18n = api.intl.sync.i18n
Expand All @@ -60,8 +62,8 @@ module.exports = function (config) {
var includeParticipating = api.settings.obs.get('patchwork.includeParticipating', false)

// prompt to setup profile on first use
onceTrue(api.sbot.obs.connection, (sbot) => {
sbot.latestSequence(api.keys.sync.id(), (err, key) => {
onceTrue(api.sbot.obs.connection, (ssb) => {
ssb.latestSequence(api.keys.sync.id(), (err, key) => {
if (err) {
// This may throw an error if the feed doesn't have any messages, but
// that shouldn't cause any problems so this error can be ignored.
Expand All @@ -71,6 +73,44 @@ module.exports = function (config) {
api.profile.sheet.edit({ usePreview: false })
}
})

const currentlyDeleting = {}

watch(api.contact.obs.blocking(id), (blocking) => {
if (blocking.length === 0) return

if (ssb.del == null) return

blocking.forEach(feed => {
pull(
ssb.createUserStream({ id: feed }),
pull.asyncMap((msg, cb) => {
const key = msg.key
if (currentlyDeleting[key] === true) {
return cb(null, null) // already deleting
}

currentlyDeleting[key] = true

ssb.del(key, (err) => {
currentlyDeleting[key] = false
cb(err, key)
})
}),
pull.filter(),
pull.collect((err, keys) => {
if (err) {
console.error(keys)
throw err
}

if (keys.length > 0) {
console.log(`deleted ${keys.length} messages from blocked authors`)
}
})
)
})
})
})

var defaultViews = computed(includeParticipating, (includeParticipating) => {
Expand Down
8 changes: 4 additions & 4 deletions lib/server-process.js
Expand Up @@ -21,10 +21,12 @@ var fixPath = require('fix-path')

var createSbot = require('secret-stack')()
.use(require('ssb-db'))
.use(require('ssb-master'))
.use(require('ssb-gossip'))
.use(require('ssb-replicate'))
.use(require('ssb-local'))
.use(require('ssb-logging'))
.use(require('ssb-master'))
.use(require('ssb-no-auth'))
.use(require('ssb-replicate'))
.use(require('ssb-unix-socket'))
// .use(require('ssb-friends')) // woah! (being handled in sbot/index.js and sbot/contacts.js)
.use(require('ssb-blobs'))
Expand All @@ -34,8 +36,6 @@ var createSbot = require('secret-stack')()
// .use(require('ssb-dht-invite')) // this one must come before dhtTransport
// .use(dhtTransport)
.use(require('ssb-invite'))
.use(require('ssb-local'))
.use(require('ssb-logging'))
.use(require('ssb-query'))
.use(require('ssb-search'))
.use(require('ssb-ws'))
Expand Down

0 comments on commit 1819a26

Please sign in to comment.