chat: add initial GuildsController
This commit is contained in:
parent
7b4cbd4fb7
commit
727f2f6ba2
23 changed files with 248 additions and 38 deletions
35
Foxchat.Chat/Services/UserResolverService.cs
Normal file
35
Foxchat.Chat/Services/UserResolverService.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using Foxchat.Chat.Database;
|
||||
using Foxchat.Chat.Database.Models;
|
||||
using Foxchat.Core.Federation;
|
||||
using Foxchat.Core.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Foxchat.Chat.Services;
|
||||
|
||||
public class UserResolverService(ILogger logger, ChatContext db, RequestSigningService requestSigningService)
|
||||
{
|
||||
public async Task<User> ResolveUserAsync(IdentityInstance instance, string userId)
|
||||
{
|
||||
var user = await db.Users.FirstOrDefaultAsync(u => u.InstanceId == instance.Id && u.RemoteUserId == userId);
|
||||
if (user != null)
|
||||
{
|
||||
// TODO: update user if it's been long enough
|
||||
return user;
|
||||
}
|
||||
|
||||
var userResponse = await requestSigningService.RequestAsync<Users.User>(HttpMethod.Get, instance.Domain,
|
||||
$"/_fox/ident/users/{userId}");
|
||||
|
||||
user = new User
|
||||
{
|
||||
Instance = instance,
|
||||
Username = userResponse.Username,
|
||||
RemoteUserId = userResponse.Id,
|
||||
Avatar = userResponse.AvatarUrl
|
||||
};
|
||||
|
||||
db.Add(user);
|
||||
await db.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue