LES MESSAGES MARCHENT
This commit is contained in:
+13
-13
@@ -7,39 +7,39 @@ namespace Knots.Hubs;
|
|||||||
public class ChatHub(KnotsDbContext db, AutoMapper.IMapper mapper) : Hub
|
public class ChatHub(KnotsDbContext db, AutoMapper.IMapper mapper) : Hub
|
||||||
{
|
{
|
||||||
// Rejoindre une conversation (room)
|
// Rejoindre une conversation (room)
|
||||||
public async Task JoinConversation(string conversationId)
|
public async Task JoinConversation(string discussionId)
|
||||||
{
|
{
|
||||||
await Groups.AddToGroupAsync(Context.ConnectionId, conversationId);
|
await Groups.AddToGroupAsync(Context.ConnectionId, discussionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quitter une conversation
|
// Quitter une conversation
|
||||||
public async Task LeaveConversation(string conversationId)
|
public async Task LeaveConversation(string discussionId)
|
||||||
{
|
{
|
||||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, conversationId);
|
await Groups.RemoveFromGroupAsync(Context.ConnectionId, discussionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Envoyer un message à une conversation
|
// Envoyer un message à une conversation
|
||||||
public async Task SendMessage(string conversationId, string content)
|
public async Task SendMessage(string discussionId, string content)
|
||||||
{
|
{
|
||||||
var message = new Models.Message
|
var message = new Models.Message
|
||||||
{
|
{
|
||||||
// adapte aux noms réels de ton modèle (AuthorId, Contenu, Date...)
|
Contenu = content,
|
||||||
AuthorId = int.Parse(Context.UserIdentifier!),
|
Date = DateTime.UtcNow,
|
||||||
Contenu = content,
|
Type = false,
|
||||||
Date = DateTime.UtcNow,
|
UserId = int.Parse(Context.UserIdentifier!),
|
||||||
DiscussionId = int.Parse(conversationId)
|
DiscussionId = int.Parse(discussionId)
|
||||||
};
|
};
|
||||||
|
|
||||||
db.Messages.Add(message);
|
db.Messages.Add(message);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
await Clients.Group(conversationId).SendAsync("ReceiveMessage", message);
|
await Clients.Group(discussionId).SendAsync("ReceiveMessage", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notifier que l'utilisateur est en train d'écrire
|
// Notifier que l'utilisateur est en train d'écrire
|
||||||
public async Task Typing(string conversationId)
|
public async Task Typing(string discussionId)
|
||||||
{
|
{
|
||||||
await Clients.OthersInGroup(conversationId)
|
await Clients.OthersInGroup(discussionId)
|
||||||
.SendAsync("UserTyping", Context.UserIdentifier);
|
.SendAsync("UserTyping", Context.UserIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,8 +9,6 @@ public class Message
|
|||||||
[Required] public DateTime Date { get; set; }
|
[Required] public DateTime Date { get; set; }
|
||||||
[Required] public Boolean Type { get; set; }
|
[Required] public Boolean Type { get; set; }
|
||||||
|
|
||||||
public int AuthorId { get; set; }
|
|
||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
public User User { get; set; } = null!;
|
public User User { get; set; } = null!;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Knots")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Knots")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4f994ba183ab4a079dd7e762d3b7cacca26f8f75")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e6021dcc619fd4151caff82644b9bda369ef15fd")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Knots")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Knots")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Knots")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Knots")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
aa1c1119a88f3e3b5738f6ea6f67686474d5c6d7e7b2612859a07f3ee65ef199
|
c634a46dc11c9265972dbfd647e5dc8eb04ef78a5549341a950a2b63f97dc490
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user