Skip to content

Commit

Permalink
handle Tombstone like Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Feb 9, 2025
1 parent 267dc42 commit 9638ccf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 5 additions & 4 deletions ap/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
type ObjectType string

const (
Note ObjectType = "Note"
Page ObjectType = "Page"
Article ObjectType = "Article"
Question ObjectType = "Question"
Note ObjectType = "Note"
Page ObjectType = "Page"
Article ObjectType = "Article"
Question ObjectType = "Question"
Tombstone ObjectType = "Tombstone"
)

// Object represents most ActivityPub objects.
Expand Down
22 changes: 19 additions & 3 deletions fed/inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,25 @@ func (l *Listener) handleInbox(w http.ResponseWriter, r *http.Request) {
Object: id,
}
} else if err == nil && exists && queued.Type == ap.Delete {
slog.Warn("Ignoring forwarded Delete activity for existing object", "activity", &activity, "id", id, "sender", sender.ID)
w.WriteHeader(http.StatusBadRequest)
return
var parsed ap.Object
if err := json.Unmarshal([]byte(fetched), &parsed); err != nil {
slog.Warn("Ignoring invalid forwarded Delete activity", "activity", &activity, "sender", sender.ID, "error", err)
w.WriteHeader(http.StatusBadRequest)
return
} else if parsed.Type != ap.Tombstone {
slog.Warn("Ignoring forwarded Delete activity for existing object", "activity", &activity, "id", id, "sender", sender.ID)
w.WriteHeader(http.StatusBadRequest)
return
}

// hack for Mastodon: a deleted Note is replaced with a Tombstone
slog.Debug("Wrapping Tombstone with Delete", "activity", &activity, "sender", sender.ID)
queued = &ap.Activity{
ID: queued.ID,
Type: ap.Delete,
Actor: queued.Actor,
Object: &parsed,
}
} else if err != nil {
slog.Warn("Failed to fetch forwarded object", "activity", &activity, "id", id, "sender", sender.ID, "error", err)
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 9638ccf

Please sign in to comment.