/// <summary> /// /// </summary> /// <param name="objLiveChatInfo"></param> /// <returns></returns> private LiveChatViewModel GetLiveChatViewModel(LiveChatInfo objLiveChatInfo) { var livechat = new LiveChatViewModel(); livechat.LiveChatID = objLiveChatInfo.LiveChatID; livechat.PortalID = objLiveChatInfo.PortalID; var moduleID = int.Parse(PortalController.GetPortalSetting("MyDnnLiveChatModuleID", objLiveChatInfo.PortalID, "-1")); var Settings = new ModuleController().GetModule(moduleID).ModuleSettings; //Visitor livechat.Visitor = new LiveChatVisitorViewModel() { UserID = objLiveChatInfo.VisitorUserID, VisitorGUID = objLiveChatInfo.VisitorGUID, DisplayName = objLiveChatInfo.VisitorName, Email = objLiveChatInfo.VisitorEmail, IP = objLiveChatInfo.VisitorIP, UserAgent = objLiveChatInfo.VisitorUserAgent, Avatar = (Settings["VisitorDefaultAvatar"] != null ? Settings["VisitorDefaultAvatar"].ToString() : string.Empty) }; var visitor = VisitorsOnlineApi.Instance.GetVisitorByGUID(objLiveChatInfo.PortalID, objLiveChatInfo.VisitorGUID); if (visitor != null) { if (visitor.UserID > 0) livechat.Visitor.Avatar = DotNetNuke.Common.Globals.ResolveUrl("~/dnnimagehandler.ashx?mode=profilepic&userid=" + visitor.UserID); livechat.Visitor.LastURL = visitor.LastURL; livechat.Visitor.ReferrerURL = visitor.ReferrerURL; livechat.Visitor.PastVisits = visitor.TotalConnections; livechat.Visitor.OnlineDate = visitor.OnlineDate; } //Departments livechat.Departments = LiveChatDepartmentManager.Instance.GetLiveChatDepartmentsViewModel(objLiveChatInfo.PortalID, objLiveChatInfo.LiveChatID); //Agents livechat.Agents = LiveChatAgentManager.Instance.GetLiveChatAgentsViewModel(objLiveChatInfo.PortalID, objLiveChatInfo.LiveChatID); livechat.AgentDefaultAvatar = (Settings["AgentDefaultAvatar"] != null ? Settings["AgentDefaultAvatar"].ToString() : string.Empty); //Messages var messages = LiveChatMessageManager.Instance.GetMessages(objLiveChatInfo.LiveChatID); livechat.Messages = messages; livechat.Rate = objLiveChatInfo.Rate; livechat.IsClosed = objLiveChatInfo.IsClosed; return livechat; }
/// <summary> /// /// </summary> /// <param name="livechat"></param> /// <returns></returns> public int StartLiveChatByVisitor(LiveChatViewModel livechat) { if (LiveChatManager.Instance.hasVisitorOpenedLiveChat(livechat.PortalID, livechat.Visitor.VisitorGUID)) return 0; var visitor = VisitorsOnlineApi.Instance.GetVisitorByGUID(livechat.PortalID, livechat.Visitor.VisitorGUID); var objLiveChatInfo = new LiveChatInfo() { PortalID = livechat.PortalID, VisitorGUID = livechat.Visitor.VisitorGUID, VisitorName = livechat.Visitor.DisplayName, VisitorEmail = livechat.Visitor.Email, VisitorUserID = visitor.UserID, VisitorIP = visitor.IP, VisitorUserAgent = visitor.UserAgent, VisitorMessage = livechat.Message, CreateDate = DateTime.Now, CloseDate = DateTime.MaxValue, IsClosed = false, }; int livechatID = LiveChatManager.Instance.AddLiveChat(objLiveChatInfo); LiveChatDepartmentManager.Instance.AddLiveChatDepartment(new LiveChatDepartmentInfo() { LiveChatID = livechatID, DepartmentID = livechat.Departments.First().DepartmentID, CreateDate = DateTime.Now }); //create messages var objLiveChatMessageInfo = new LiveChatMessageInfo() { LiveChatID = livechatID, SentBy = MessageSentBy.System, CreateDate = DateTime.Now, MessageType = MessageType.Text, Message = "Chat started", }; LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo); if (!string.IsNullOrEmpty(livechat.Message)) { objLiveChatMessageInfo = new LiveChatMessageInfo() { LiveChatID = livechatID, SentBy = MessageSentBy.Visitor, CreateDate = DateTime.Now, MessageType = MessageType.Text, Message = livechat.Message }; LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo); } livechat = GetLiveChatViewModel(objLiveChatInfo); //ersale live chat kamel shode be khode visitor(darkhast konande chat) Clients.Group(livechat.PortalID + "-" + visitor.VisitorGUID).startLiveChat(livechat); //send live chat request to agents var department = livechat.Departments.First(); Clients.Group(DepartmentAgentsGroupName + department.DepartmentID).incomingLiveChat(livechatID, visitor.VisitorGUID, livechat.Message, "add"); var context = GlobalHost.ConnectionManager.GetHubContext<VisitorsOnlineHub>(); context.Clients.Group("MyDnnLiveChatAgents-" + department.DepartmentID).invokeScript(string.Format("mydnnLiveChatRequests({0},'add');", livechatID)); //update visitor info in visitor list visitor.DisplayName = livechat.Visitor.DisplayName; visitor.Email = livechat.Visitor.Email; //eslah shavad ///VisitorsOnlineApi.Instance.UpdateVisitorOnline(livechat.PortalID, visitor.VisitorGUID, visitor.UserName, visitor.DisplayName, visitor.Email, visitor.LastURL, Context.ConnectionId, true); //var context = GlobalHost.ConnectionManager.GetHubContext<VisitorsOnlineHub>(); ///context.Clients.Group("MyDnnVisitorsOnline").updateVisitorInfo(visitor); return livechatID; }