House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -52,7 +52,7 @@ namespace PrivaPub.Services
|
||||
["object"] = actor.Uri,
|
||||
["to"] = new JsonArray(ActivityPubRenderer.Public),
|
||||
["cc"] = new JsonArray(actor.Followers)
|
||||
}, token);
|
||||
}, token: token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,46 +64,33 @@ namespace PrivaPub.Services
|
||||
// announcements, the feeds it read, its featured hashtags, endorsements, notes and dismissed suggestions, its media)
|
||||
// goes with it. Its link to its login stays, so the login keeps no other
|
||||
// trace than that.
|
||||
public class PersonaRemoval : IPersonaRemoval
|
||||
public class PersonaRemoval(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IDeliveryService delivery,
|
||||
IMediaService mediaService,
|
||||
IGroupRemoval groups,
|
||||
IOpenIddictTokenManager openIddictTokenManager,
|
||||
IOpenIddictAuthorizationManager authorizations) : IPersonaRemoval
|
||||
{
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IDeliveryService _delivery;
|
||||
readonly IMediaService _media;
|
||||
readonly IGroupRemoval _groups;
|
||||
readonly IOpenIddictTokenManager _tokens;
|
||||
readonly IOpenIddictAuthorizationManager _authorizations;
|
||||
|
||||
public PersonaRemoval(DbEntities dbEntities, ILocalActorService localActors, IDeliveryService delivery, IMediaService media, IGroupRemoval groups,
|
||||
IOpenIddictTokenManager tokens, IOpenIddictAuthorizationManager authorizations)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_delivery = delivery;
|
||||
_media = media;
|
||||
_groups = groups;
|
||||
_tokens = tokens;
|
||||
_authorizations = authorizations;
|
||||
}
|
||||
|
||||
public async Task<bool> Remove(string avatarId, CancellationToken token)
|
||||
{
|
||||
var avatar = string.IsNullOrEmpty(avatarId) ? default : await _dbEntities.Avatars.MatchID(avatarId).Match(a => !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
var avatar = string.IsNullOrEmpty(avatarId) ? default : await dbEntities.Avatars.MatchID(avatarId).Match(a => !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
if (avatar == default)
|
||||
return false;
|
||||
var now = DateTime.UtcNow;
|
||||
// nothing acts as it while it goes
|
||||
await _tokens.RevokeBySubjectAsync(avatar.ID, token);
|
||||
await _authorizations.RevokeBySubjectAsync(avatar.ID, token);
|
||||
await Domain.Social.WebPush.Forget(new[] { avatar.ID });//its Web Push subscriptions with its tokens (R9)
|
||||
await openIddictTokenManager.RevokeBySubjectAsync(avatar.ID, token);
|
||||
await authorizations.RevokeBySubjectAsync(avatar.ID, token);
|
||||
await Domain.Social.WebPush.Forget(new[] { avatar.ID }, token);//its Web Push subscriptions with its tokens (R9)
|
||||
Streams.CloseFor(avatar.ID);
|
||||
|
||||
foreach (var group in await _dbEntities.Groups.Match(g => g.OwnerAvatarId == avatar.ID && !g.DeletionAt.HasValue).ExecuteAsync(token))
|
||||
await _groups.Remove(group.ID, token);
|
||||
var persona = _localActors.FromAvatar(avatar);
|
||||
var followed = (await _dbEntities.Followings.Match(f => f.AvatarId == avatar.ID && !f.TargetIsLocal).ExecuteAsync(token))
|
||||
foreach (var group in await dbEntities.Groups.Match(g => g.OwnerAvatarId == avatar.ID && !g.DeletionAt.HasValue).ExecuteAsync(token))
|
||||
await groups.Remove(group.ID, token);
|
||||
var persona = localActors.FromAvatar(avatar);
|
||||
var followed = (await dbEntities.Followings.Match(f => f.AvatarId == avatar.ID && !f.TargetIsLocal).ExecuteAsync(token))
|
||||
.Select(f => f.TargetActorURI);
|
||||
await ActorDeletion.Announce(persona, followed, _dbEntities, _delivery, token);
|
||||
await ActorDeletion.Announce(persona, followed, dbEntities, delivery, token);
|
||||
await DB.Default.Update<Avatar>().MatchID(avatar.ID).Modify(a => a.DeletionAt, now).ExecuteAsync(token);
|
||||
await Empty(avatar.ID, now, token);
|
||||
await DB.Default.DeleteAsync<PersonaListMember>(m => m.AvatarId == avatar.ID);
|
||||
@@ -125,7 +112,7 @@ namespace PrivaPub.Services
|
||||
// nothing of it publishes later, and none of its files stays served: its posts' media, its pictures and what its
|
||||
// scheduled posts held
|
||||
await DB.Default.DeleteAsync<ScheduledStatus>(s => s.AvatarId == avatar.ID);
|
||||
await _media.Trash(m => m.OwnerAvatarId == avatar.ID, "persona removed", token);
|
||||
await mediaService.Trash(m => m.OwnerAvatarId == avatar.ID, "persona removed", token);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,26 +140,18 @@ namespace PrivaPub.Services
|
||||
// with the persona that owns it): a Delete of the group's actor to its followers and its members elsewhere, its name kept
|
||||
// reserved while its documents answer 410, and the personas here that followed or joined it no longer do. The posts made
|
||||
// in it stay their authors'.
|
||||
public class GroupRemoval : IGroupRemoval
|
||||
public class GroupRemoval(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IDeliveryService delivery) : IGroupRemoval
|
||||
{
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public GroupRemoval(DbEntities dbEntities, ILocalActorService localActors, IDeliveryService delivery)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_delivery = delivery;
|
||||
}
|
||||
|
||||
public async Task<bool> Remove(string groupId, CancellationToken token)
|
||||
{
|
||||
var group = string.IsNullOrEmpty(groupId) ? default : await _dbEntities.Groups.MatchID(groupId).Match(g => !g.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
var group = string.IsNullOrEmpty(groupId) ? default : await dbEntities.Groups.MatchID(groupId).Match(g => !g.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
if (group == default)
|
||||
return false;
|
||||
var actor = _localActors.FromGroup(group);
|
||||
await ActorDeletion.Announce(actor, group.Members.Where(m => m.IsForeign).Select(m => m.AvatarId), _dbEntities, _delivery, token);
|
||||
var actor = localActors.FromGroup(group);
|
||||
await ActorDeletion.Announce(actor, group.Members.Where(m => m.IsForeign).Select(m => m.AvatarId), dbEntities, delivery, token);
|
||||
await DB.Default.Update<GroupEntity>().MatchID(group.ID).Modify(g => g.DeletionAt, DateTime.UtcNow).ExecuteAsync(token);
|
||||
await DB.Default.DeleteAsync<Following>(f => f.TargetActorURI == actor.Uri);
|
||||
await DB.Default.DeleteAsync<Follower>(f => f.LocalActorId == group.ID && f.LocalActorKind == LocalActorKind.Group);
|
||||
|
||||
Reference in new issue
Block a user