public static int[] GetActionID(int chatID)
    {
        List <int> result = new List <int>();

        result.Add(chatID);
        Chat chat = Chats.GetChat(UserSession.LoginUser, chatID);

        if (chat == null)
        {
            return(null);
        }
        result.Add(chat == null || chat.ActionID == null ? -1 : (int)chat.ActionID);

        int?userID = null;

        if (chat.InitiatorType == ChatParticipantType.External)
        {
            ChatClients clients = new ChatClients(UserSession.LoginUser);
            clients.LoadByChatClientID(chat.InitiatorID);
            if (!clients.IsEmpty)
            {
                userID = clients[0].LinkedUserID;
            }
        }

        result.Add(chat.GetInitiatorLinkedUserID());

        return(result.ToArray());
    }
        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);
        }
        public static string GetChatClient(RestCommand command, int chatClientID)
        {
            ChatClient chatClient = ChatClients.GetChatClient(command.LoginUser, chatClientID);

            if (chatClient.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(chatClient.GetXml("ChatClient", true));
        }
Exemple #4
0
        //private ChatClient GetNewChatClient(string connectionId, string name)
        //{
        //    ChatClient client = new ChatClient()
        //                {
        //                    ConnectionId = connectionId,
        //                    Name = name,
        //                    ChatMessages = new List<LiveChatMessage>()
        //                };

        //    return client;
        //}

        private ChatClient GetChatClient(string connectionId)
        {
            ChatClient client = null;

            if (ChatClients.ContainsKey(connectionId))
            {
                client = ChatClients[connectionId];
            }

            return(client);
        }
Exemple #5
0
        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);
        }
        public static string GetChatClients(RestCommand command)
        {
            ChatClients chatClients = new ChatClients(command.LoginUser);

            chatClients.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(chatClients.GetXml("ChatClients", "ChatClient", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Exemple #7
0
        private void GetChatConnections(CommandArgs args)
        {
            int connectedUsersCount = 0;

            foreach (ChatClient client in ChatClients.ToArray())
            {
                if (client.ClientSocket.Connected)
                {
                    connectedUsersCount++;
                    Reference.Tell(args.sender.networkPlayer, $"{((IPEndPoint)client.ClientSocket.RemoteEndPoint).Address.ToString()}:{((IPEndPoint)client.ClientSocket.RemoteEndPoint).Port.ToString()}, time: {DateTime.Now - client.ConnectedAt}");
                }
                else
                {
                    ChatClients.Remove(client);
                }
            }
            Reference.Tell(args.sender.networkPlayer, $"There are {connectedUsersCount} connections.");
        }
Exemple #8
0
 public ChatMail(ChatClients clients)
 {
     mClients = clients;
     mLogger  = LogManager.GetCurrentClassLogger();
 }