[backend/federation] Process user updates (ISH-32)
This commit is contained in:
parent
69610a61d1
commit
e806811e21
4 changed files with 25 additions and 3 deletions
|
@ -122,6 +122,20 @@ public class ActivityHandlerService(
|
|||
await noteSvc.LikeNoteAsync(note, activity.Actor);
|
||||
return;
|
||||
}
|
||||
case ASUpdate: {
|
||||
switch (activity.Object) {
|
||||
case ASActor actor:
|
||||
if (actor.Id != activity.Actor.Id)
|
||||
throw GracefulException.UnprocessableEntity("Refusing to update actor with mismatching id");
|
||||
await userSvc.UpdateUserAsync(resolvedActor, actor);
|
||||
return;
|
||||
case ASNote note:
|
||||
throw new NotImplementedException("Note updates haven't been implemented yet");
|
||||
//return;
|
||||
default:
|
||||
throw GracefulException.UnprocessableEntity("Update activity object is invalid");
|
||||
}
|
||||
}
|
||||
default: {
|
||||
throw new NotImplementedException($"Activity type {activity.Type} is unknown");
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public class ASActivity : ASObject {
|
|||
private const string Ns = Constants.ActivityStreamsNs;
|
||||
|
||||
public const string Create = $"{Ns}#Create";
|
||||
public const string Update = $"{Ns}#Update";
|
||||
public const string Delete = $"{Ns}#Delete";
|
||||
public const string Follow = $"{Ns}#Follow";
|
||||
public const string Unfollow = $"{Ns}#Unfollow";
|
||||
|
@ -59,6 +60,10 @@ public class ASLike : ASActivity {
|
|||
public ASLike() => Type = Types.Like;
|
||||
}
|
||||
|
||||
public class ASUpdate : ASActivity {
|
||||
public ASUpdate() => Type = Types.Update;
|
||||
}
|
||||
|
||||
//TODO: add the rest
|
||||
|
||||
public sealed class ASActivityConverter : ASSerializer.ListSingleObjectConverter<ASActivity>;
|
|
@ -37,6 +37,7 @@ public class ASObject : ASObjectBase {
|
|||
ASNote.Types.Note => token.ToObject<ASNote>(),
|
||||
Types.Tombstone => token.ToObject<ASTombstone>(),
|
||||
ASActivity.Types.Create => token.ToObject<ASCreate>(),
|
||||
ASActivity.Types.Update => token.ToObject<ASUpdate>(),
|
||||
ASActivity.Types.Delete => token.ToObject<ASDelete>(),
|
||||
ASActivity.Types.Follow => token.ToObject<ASFollow>(),
|
||||
ASActivity.Types.Unfollow => token.ToObject<ASUnfollow>(),
|
||||
|
|
|
@ -145,8 +145,10 @@ public class UserService(
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<User> UpdateUserAsync(User user) {
|
||||
if (!user.NeedsUpdate) return user;
|
||||
public async Task<User> UpdateUserAsync(User user, ASActor? actor = null) {
|
||||
if (!user.NeedsUpdate && actor == null) return user;
|
||||
if (actor is { IsUnresolved: true } or { Username: null })
|
||||
actor = null; // This will trigger a fetch a couple lines down
|
||||
|
||||
// Prevent multiple update jobs from running concurrently
|
||||
db.Update(user);
|
||||
|
@ -156,7 +158,7 @@ public class UserService(
|
|||
var uri = user.Uri ?? throw new Exception("Encountered remote user without a Uri");
|
||||
logger.LogDebug("Updating user with uri {uri}", uri);
|
||||
|
||||
var actor = await fetchSvc.FetchActorAsync(user.Uri);
|
||||
actor ??= await fetchSvc.FetchActorAsync(user.Uri);
|
||||
actor.Normalize(uri, user.AcctWithPrefix);
|
||||
|
||||
user.UserProfile ??= await db.UserProfiles.FirstOrDefaultAsync(p => p.User == user);
|
||||
|
|
Loading…
Add table
Reference in a new issue