[backend/core] Resolve user profile mentions on local user update (ISH-101)

This commit is contained in:
Laura Hausmann 2024-02-28 19:54:56 +01:00
parent 3e1a34c0b3
commit e441bb3e70
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 21 additions and 11 deletions

View file

@ -107,16 +107,7 @@ public class AccountController(
user.BannerUrl = banner.Url;
}
db.Update(user);
db.Update(user.UserProfile);
await db.SaveChangesAsync();
await userSvc.UpdateLocalUserAsync(user);
if (prevAvatarId != null && user.Avatar?.Id != prevAvatarId)
await driveSvc.RemoveFile(prevAvatarId);
if (prevBannerId != null && user.Banner?.Id != prevBannerId)
await driveSvc.RemoveFile(prevBannerId);
user = await userSvc.UpdateLocalUserAsync(user, prevAvatarId, prevBannerId);
var res = await userRenderer.RenderAsync(user, user.UserProfile, source: true);
return Ok(res);

View file

@ -296,11 +296,30 @@ public class UserService(
return user;
}
public async Task UpdateLocalUserAsync(User user)
public async Task<User> UpdateLocalUserAsync(User user, string? prevAvatarId, string? prevBannerId)
{
if (user.Host != null) throw new Exception("This method is only valid for local users");
if (user.UserProfile == null) throw new Exception("user.UserProfile must not be null at this stage");
db.Update(user);
db.Update(user.UserProfile);
await db.SaveChangesAsync();
user = await UpdateProfileMentions(user, null);
var activity = activityRenderer.RenderUpdate(await userRenderer.RenderAsync(user));
await deliverSvc.DeliverToFollowersAsync(activity, user, []);
_ = followupTaskSvc.ExecuteTask("UpdateLocalUserAsync", async provider =>
{
var bgDriveSvc = provider.GetRequiredService<DriveService>();
if (prevAvatarId != null && user.Avatar?.Id != prevAvatarId)
await bgDriveSvc.RemoveFile(prevAvatarId);
if (prevBannerId != null && user.Banner?.Id != prevBannerId)
await bgDriveSvc.RemoveFile(prevBannerId);
});
return user;
}
public async Task<User> CreateLocalUserAsync(string username, string password, string? invite)