[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:
parent
89a743d121
commit
cf215b3d57
2 changed files with 28 additions and 0 deletions
|
@ -85,6 +85,12 @@ public class ActivityHandlerService(
|
|||
return;
|
||||
}
|
||||
|
||||
if (activity.Object is ASNote note)
|
||||
{
|
||||
await noteSvc.DeleteNoteAsync(note, resolvedActor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (activity.Object is not ASTombstone tombstone)
|
||||
throw GracefulException
|
||||
.UnprocessableEntity($"Delete activity object is invalid: {activity.Object?.Type}");
|
||||
|
|
|
@ -570,6 +570,28 @@ public class NoteService(
|
|||
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)
|
||||
{
|
||||
var renote = await ResolveNoteAsync(note);
|
||||
|
|
Loading…
Add table
Reference in a new issue