[backend/core] Resolve user profile mentions on local user update (ISH-101)
This commit is contained in:
parent
3e1a34c0b3
commit
e441bb3e70
2 changed files with 21 additions and 11 deletions
|
@ -107,16 +107,7 @@ public class AccountController(
|
||||||
user.BannerUrl = banner.Url;
|
user.BannerUrl = banner.Url;
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Update(user);
|
user = await userSvc.UpdateLocalUserAsync(user, prevAvatarId, prevBannerId);
|
||||||
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);
|
|
||||||
|
|
||||||
var res = await userRenderer.RenderAsync(user, user.UserProfile, source: true);
|
var res = await userRenderer.RenderAsync(user, user.UserProfile, source: true);
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
|
|
|
@ -296,11 +296,30 @@ public class UserService(
|
||||||
return user;
|
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.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));
|
var activity = activityRenderer.RenderUpdate(await userRenderer.RenderAsync(user));
|
||||||
await deliverSvc.DeliverToFollowersAsync(activity, 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)
|
public async Task<User> CreateLocalUserAsync(string username, string password, string? invite)
|
||||||
|
|
Loading…
Add table
Reference in a new issue