Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # Knots/bin/Debug/net8.0/Knots.dll # Knots/bin/Debug/net8.0/Knots.pdb # Knots/obj/Debug/net8.0/Knots.csproj.CoreCompileInputs.cache # Knots/obj/Debug/net8.0/Knots.csproj.FileListAbsolute.txt # Knots/obj/Debug/net8.0/Knots.dll # Knots/obj/Debug/net8.0/Knots.pdb # Knots/obj/Debug/net8.0/ref/Knots.dll # Knots/obj/Debug/net8.0/refint/Knots.dll
This commit is contained in:
+10
-6
@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.SignalR;
|
||||
namespace Knots.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class ChatHub : Hub
|
||||
public class ChatHub(KnotsDbContext db, AutoMapper.IMapper mapper) : Hub
|
||||
{
|
||||
// Rejoindre une conversation (room)
|
||||
public async Task JoinConversation(string conversationId)
|
||||
@@ -21,14 +21,18 @@ public class ChatHub : Hub
|
||||
// Envoyer un message à une conversation
|
||||
public async Task SendMessage(string conversationId, string content)
|
||||
{
|
||||
var message = new
|
||||
var message = new Models.Message
|
||||
{
|
||||
SenderId = Context.UserIdentifier,
|
||||
Content = content,
|
||||
SentAt = DateTime.UtcNow
|
||||
// adapte aux noms réels de ton modèle (AuthorId, Contenu, Date...)
|
||||
AuthorId = int.Parse(Context.UserIdentifier!),
|
||||
Contenu = content,
|
||||
Date = DateTime.UtcNow,
|
||||
DiscussionId = int.Parse(conversationId)
|
||||
};
|
||||
|
||||
// Diffuse à tous les membres de la conversation
|
||||
db.Messages.Add(message);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await Clients.Group(conversationId).SendAsync("ReceiveMessage", message);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ public class Message
|
||||
[Required] public DateTime Date { get; set; }
|
||||
[Required] public Boolean Type { get; set; }
|
||||
|
||||
public int AuthorId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; } = null!;
|
||||
|
||||
|
||||
+20
-3
@@ -21,7 +21,8 @@ builder.Services.AddCors(options =>
|
||||
policyBuilder
|
||||
.WithOrigins("http://localhost:5250", "http://localhost:4200")
|
||||
.WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
|
||||
.AllowAnyHeader();
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,7 +48,24 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(
|
||||
Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]!))
|
||||
|
||||
};
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
{
|
||||
var accessToken = context.Request.Query["access_token"];
|
||||
var path = context.HttpContext.Request.Path;
|
||||
if (!string.IsNullOrEmpty(accessToken) &&
|
||||
path.StartsWithSegments("/hubs"))
|
||||
{
|
||||
context.Token = accessToken;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
@@ -58,8 +76,6 @@ builder.Services.AddAutoMapper(cfg => { }, typeof(Program).Assembly);
|
||||
// On construit l'application en lui donnant vie
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
app.MapHub<ChatHub>("hubs/chat");
|
||||
|
||||
app.UseCors();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
@@ -73,5 +89,6 @@ app.UseAuthentication()
|
||||
}
|
||||
).UseSwaggerGen();
|
||||
|
||||
app.MapHub<ChatHub>("hubs/chat");
|
||||
|
||||
app.Run();
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
dab059269bab79457b7504e70cb873c79efe1561e6d178c96e5a58f0a7d08788
|
||||
bab9e1ed6ec5ae3422f4377cfa8a1795b3c9881cbfdada74a84426e15b5819ff
|
||||
|
||||
@@ -518,4 +518,4 @@ C:\Users\dogge\RiderProjects\Knots\Knots\obj\Debug\net8.0\refint\Knots.dll
|
||||
C:\Users\dogge\RiderProjects\Knots\Knots\obj\Debug\net8.0\Knots.pdb
|
||||
C:\Users\dogge\RiderProjects\Knots\Knots\obj\Debug\net8.0\Knots.genruntimeconfig.cache
|
||||
C:\Users\dogge\RiderProjects\Knots\Knots\obj\Debug\net8.0\ref\Knots.dll
|
||||
C:\Users\Carte\RiderProjects\Knots\Knots\bin\Debug\net8.0\System.Net.WebSockets.WebSocketProtocol.dll
|
||||
C:\Users\dogge\RiderProjects\Knots\Knots\bin\Debug\net8.0\System.Net.WebSockets.WebSocketProtocol.dll
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user