public ChatResult AddFriendRequest(string friendId) { ChatResult result = Manager.Instance.AddFriendRequest(Context.ConnectionId, friendId); if (result.Success) { CustomerInfo customer = Manager.Instance.GetCustomerByConnectionId(Context.ConnectionId); CustomerInfo returnCustomer = new CustomerInfo(customer.CustomerId, customer.CustomerName, customer.Status); List<string> friendConnectionIds = Manager.Instance.GetCustomerByCustomerId(friendId).ConnectionList; Clients.Clients(friendConnectionIds).OnAddFriendRequest(returnCustomer); } return result; }
public ChatResult AddFriendRespond(string friendId, bool agree) { ChatResult result = Manager.Instance.AddFriendRespond(Context.ConnectionId, friendId, agree); if (result.Success) { CustomerInfo myCustomer = Manager.Instance.GetCustomerByConnectionId(Context.ConnectionId); CustomerInfo friendCustomer = Manager.Instance.GetCustomerByCustomerId(friendId); CustomerInfo returnMyCustomer = new CustomerInfo(myCustomer.CustomerId, myCustomer.CustomerName, myCustomer.Status); CustomerInfo returnFriendCustomer = new CustomerInfo(friendCustomer.CustomerId, friendCustomer.CustomerName, friendCustomer.Status); //send to request customer //gửi về 2 thông tin: bool agree, Customer Clients.Clients(friendCustomer.ConnectionList).OnAddFriendRespond(agree, returnMyCustomer); //send to respond customer //gửi về 2 thông tin nếu bool agree = true : customerid, string name if (agree == true) Clients.Clients(myCustomer.ConnectionList).OnAddFriendRespond(agree, returnFriendCustomer); } return result; }
public List<CustomerInfo> SearchCustomerByCustomerName(string connectionId, string customerId) { if (m_mapConnectionIdCustomer.ContainsKey(connectionId)) { List<CustomerInfo> cusList = m_customerInfoDict.Values.Where(t => t.CustomerId.Contains(customerId)).ToList(); List<CustomerInfo> sendCustomerList = new List<CustomerInfo>(); foreach (CustomerInfo cus in cusList) { CustomerInfo newCus = new CustomerInfo(cus.CustomerId, cus.CustomerName, cus.Status); sendCustomerList.Add(newCus); } return sendCustomerList; } return null; }
/// <summary> /// trong trường hợp GetFriendRequest thì key sẽ là ID của friend, value là friend mà request đến mình /// </summary> /// <param name="connectionId"></param> /// <returns></returns> public List<CustomerInfo> GetFriendRequest(string connectionId) { if (m_mapConnectionIdCustomer.ContainsKey(connectionId)) { string myCustomerId = m_mapConnectionIdCustomer[connectionId]; List<CustomerInfo> requestList = new List<CustomerInfo>(); if (m_requestAddFriendDict.ContainsKey(myCustomerId)) { foreach (string friendId in m_requestAddFriendDict[myCustomerId]) { CustomerInfo cus = m_customerInfoDict[friendId]; CustomerInfo friendCus = new CustomerInfo(cus.CustomerId, cus.CustomerName, cus.Status); requestList.Add(friendCus); } } return requestList; } return null; }
public List<CustomerInfo> GetFriendListByCustomerId(string connectionId) { if (m_mapConnectionIdCustomer.ContainsKey(connectionId)) { string myCustomerId = m_mapConnectionIdCustomer[connectionId]; List<CustomerInfo> customerList = new List<CustomerInfo>(); List<string> friendIdList = m_customerInfoDict[myCustomerId].FriendList; foreach (string friendId in friendIdList) { CustomerInfo cus = m_customerInfoDict[friendId]; CustomerInfo newCus = new CustomerInfo(cus.CustomerId, cus.CustomerName, cus.Status); customerList.Add(newCus); } return customerList; } return null; }