summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/undo.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-07-11 16:22:21 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-11 16:22:21 +0200
commit846057f0d696fded87d105dec1245e9ba32763ce (patch)
tree9a4914c07bcf189a3eea0a2c091567c56cdf4963 /internal/federation/federatingdb/undo.go
parentfavourites GET implementation (#95) (diff)
downloadgotosocial-846057f0d696fded87d105dec1245e9ba32763ce.tar.xz
Block/unblock (#96)
* remote + local block logic, incl. federation * improve blocking stuff * fiddle with display of blocked profiles * go fmt
Diffstat (limited to 'internal/federation/federatingdb/undo.go')
-rw-r--r--internal/federation/federatingdb/undo.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go
index 3feee6457..063adaedd 100644
--- a/internal/federation/federatingdb/undo.go
+++ b/internal/federation/federatingdb/undo.go
@@ -85,6 +85,31 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
// UNDO LIKE
case string(gtsmodel.ActivityStreamsAnnounce):
// UNDO BOOST/REBLOG/ANNOUNCE
+ case string(gtsmodel.ActivityStreamsBlock):
+ // UNDO BLOCK
+ ASBlock, ok := iter.GetType().(vocab.ActivityStreamsBlock)
+ if !ok {
+ return errors.New("UNDO: couldn't parse block into vocab.ActivityStreamsBlock")
+ }
+ // make sure the actor owns the follow
+ if !sameActor(undo.GetActivityStreamsActor(), ASBlock.GetActivityStreamsActor()) {
+ return errors.New("UNDO: block actor and activity actor not the same")
+ }
+ // convert the block to something we can understand
+ gtsBlock, err := f.typeConverter.ASBlockToBlock(ASBlock)
+ if err != nil {
+ return fmt.Errorf("UNDO: error converting asblock to gtsblock: %s", err)
+ }
+ // make sure the addressee of the original block is the same as whatever inbox this landed in
+ if gtsBlock.TargetAccountID != targetAcct.ID {
+ return errors.New("UNDO: block object account and inbox account were not the same")
+ }
+ // delete any existing BLOCK
+ if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsBlock.URI}}, &gtsmodel.Block{}); err != nil {
+ return fmt.Errorf("UNDO: db error removing block: %s", err)
+ }
+ l.Debug("block undone")
+ return nil
}
}