[backend/federation] Handle ASDelete activities of ASNote objects

Some implementations seem to send deletes of ASNote objects instead of ASTombstone objects.
This commit is contained in:
Laura Hausmann 2024-04-25 19:13:57 +02:00
parent 89a743d121
commit cf215b3d57
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 28 additions and 0 deletions

View file

@ -85,6 +85,12 @@ public class ActivityHandlerService(
return; return;
} }
if (activity.Object is ASNote note)
{
await noteSvc.DeleteNoteAsync(note, resolvedActor);
return;
}
if (activity.Object is not ASTombstone tombstone) if (activity.Object is not ASTombstone tombstone)
throw GracefulException throw GracefulException
.UnprocessableEntity($"Delete activity object is invalid: {activity.Object?.Type}"); .UnprocessableEntity($"Delete activity object is invalid: {activity.Object?.Type}");

View file

@ -570,6 +570,28 @@ public class NoteService(
await DeleteNoteAsync(dbNote); await DeleteNoteAsync(dbNote);
} }
public async Task DeleteNoteAsync(ASNote note, User actor)
{
// ReSharper disable once EntityFramework.NPlusOne.IncompleteDataQuery (it doesn't know about IncludeCommonProperties())
var dbNote = await db.Notes.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Uri == note.Id);
if (dbNote == null)
{
logger.LogDebug("Note '{id}' isn't known, skipping", note.Id);
return;
}
// ReSharper disable once EntityFramework.NPlusOne.IncompleteDataUsage (same reason as above)
if (dbNote.User != actor)
{
logger.LogDebug("Note '{id}' isn't owned by actor requesting its deletion, skipping", note.Id);
return;
}
logger.LogDebug("Deleting note '{id}' owned by {userId}", note.Id, actor.Id);
await DeleteNoteAsync(dbNote);
}
public async Task UndoAnnounceAsync(ASNote note, User actor) public async Task UndoAnnounceAsync(ASNote note, User actor)
{ {
var renote = await ResolveNoteAsync(note); var renote = await ResolveNoteAsync(note);