private void AddMessageToRoom(string roomId, string clientId, string fromName, string messageText, string dt, bool isAdminMessage) { var message = new ChatMessage() { From = fromName, Message = messageText, SentDateTime = dt, IsAdminMessage = false }; var isExistChatClient = ChatClients.Any(i => i.RoomId == roomId); var chatClient = isExistChatClient ? ChatClients.First(i => i.RoomId == roomId) : new ChatClient() { RoomId = roomId, ClientId = clientId, ClientName = fromName, Messages = new List <ChatMessage>() }; chatClient.LastMessage = messageText; chatClient.LastMessageDateTime = dt; chatClient.Messages.Add(message); if (!isExistChatClient) { ChatClients.Add(chatClient); } MessageUpdated(chatClient, message); }
private void SendToChat(ChatClient client, string message, bool isRequest) { Agent agent = null; string connectionId = Context.ConnectionId; string agentId = ""; if (!isRequest && ChatSessions.ContainsKey(connectionId)) { agentId = ChatSessions[connectionId]; agent = Agents[agentId]; client = GetChatClient(connectionId); } else { if (client != null) { //Add new chat client client.ChatMessages = new List <LiveChatMessage>(); client.ConnectionId = connectionId; if (!ChatClients.ContainsKey(connectionId)) { ChatClients.Add(connectionId, client); } else { ChatClients[connectionId] = client; } } agent = GetLessBuzyAgent(); if (agent != null) { StartChat(connectionId, agent.Id, agent.Name); } else { Clients.Caller.addMessage("", UiStringNoAgentAreCurrentlyAvailable); return; } } Clients.Caller.addMessage(client.Name, message); LogMessage(client, agent.Name, string.Format("{0} : {1}", client.Name, message)); if (!isRequest) { Clients.Client(agent.Id).addMessage(connectionId, UiStringSystem, UiStringThisVisitorAppearToHaveLost); } Clients.Client(agent.Id).addMessage(connectionId, UiStringVisitor, message); }