I searched and tried many way but I couldn't. There are information about group chat on web but there are not about private chat. what way should i follow? Can u share article or advice about this? This is my last stage of my project. Please.
public void Send(string user, string content, string recipientId,string image)
{
var sender = _userService.GetByUserName(Context.User.Identity.Name);
Message message = new Message
{
Content = content,
RecipientId = recipientId,
SenderId = sender.Id
};
_db.Message.Add(message);
_db.SaveChange();
Clients.Users(recipientId, sender.Id).SendAsync("ReceiveMessage", user, content, image);
}
<pre>"use strict";
var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
connection.on("ReceiveMessage", function (user, content,image) {
var d = new Date();
var date = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
var msg = content;
var kullanici = user;
var img = new Image();
img.src =image;
document.querySelector("#messageList").innerHTML += "<li class='left clearfix'>" +
"<span class='chat-img pull-left'>"
+ "<img src='"+ img.src + "' width='50' height='50'/>" +
"</span>" +
"<div class='chat-body clearfix' style='color: white'>" +
" <div class='header'>" +
"" style="color: rgba(0, 0, 255, 1)">" + kullanici + "" + "<small class='pull-right text-muted'>" +
"<span class='glyphicon glyphicon - time'>" + "</span>" + date +
" </small >" +
"</div >" +
" <p style='color:white'>" +
msg +
"</p >" +
"</div >" +
" </li >";
});
connection.start().then(function () {
document.querySelector("#sendButton").disabled = false;
}).catch(function (err) {
return console.error(err.toString());
});
document.querySelector("#sendButton").addEventListener("click", function (event) {
var user = document.querySelector("#userInput").value;
var content = document.querySelector("#messageInput").value;
var recipientId = document.querySelector("#recipient").value;
var image = document.querySelector("#userImage1").src;
connection.invoke("Send", user, content, recipientId,image).catch(function (err) {
return console.error(err.toString());
});
event.preventDefault();
});
What I have tried:
I searched and tried many way but I couldn't.