Esempio n. 1
0
        public void RemoveOnlineUser()
        {
            var chatAdminUser = _service.GetChatUserByConnectionId(Context.ConnectionId);

            ChatRoomVM roomVM = new ChatRoomVM();

            if (chatAdminUser != null)
            {
                // Notify Admins
                Clients.Group("adminGroup").removeUser(chatAdminUser.UserName);
                Clients.Group("adminGroup").removeOnlineUser(chatAdminUser.UserName);
                // This is used to update the database
                var rooms = _service.GetAllActiveChatRoomsByUser(chatAdminUser.ChatUserId);
                if (rooms != null && rooms.Count > 0)
                {
                    foreach (var r in rooms)
                    {
                        ChatRoomVM chatRoomVM = new ChatRoomVM();
                        --r.ActiveUserCount;
                        if (r.ActiveUserCount == 0)
                        {
                            r.Status = 1;
                            r.EndTime = GetLocalTime();
                            _service.UpdateChatRoom(r);
                            RemoveActiveRoom(r.ChatRoomName);
                            Clients.Group("adminGroup").removeRoom(r.ChatRoomName);
                        }
                        else
                        {
                            r.HasAdminUser = false;
                            r.ChatUser = null;
                            _service.UpdateChatRoom(r);
                            chatRoomVM.ActiveUserCount = r.ActiveUserCount;
                            chatRoomVM.ChatRoomName = r.ChatRoomName;
                            chatRoomVM.HasAdminUser = r.HasAdminUser;
                            Clients.Group("adminGroup").updateActiveRoom(chatRoomVM);
                            // TODO: Place room update code for live feed here
                            RoomFeedVM roomFeed = new RoomFeedVM();

                            roomFeed.UsersInRoom = r.ActiveUserCount;
                            roomFeed.StartTime = r.StartTime;
                            roomFeed.RoomName = r.ChatRoomName;
                            roomFeed.HelperName = chatAdminUser.FirstName + " " + chatAdminUser.LastName;
                            roomFeed.ClientId = r.ChatUserId;
                            if (r.HasAdminUser == true) { roomFeed.BeingHelped = "Yes"; } else { roomFeed.BeingHelped = "No"; }
                            Clients.Group("adminGroup").updateRoom(roomFeed);
                            Groups.Remove(Context.ConnectionId, roomFeed.RoomName);
                        }

                    }
                    chatAdminUser.IsOnline = false;
                    chatAdminUser.LogOutTime = GetLocalTime();

                    _service.UpdateAdminUser(chatAdminUser);
                }
                else
                {
                    chatAdminUser.IsOnline = false;
                    chatAdminUser.LogOutTime = GetLocalTime();
                    _service.UpdateAdminUser(chatAdminUser);
                }
            }
        }
Esempio n. 2
0
        public void CloseRoom(string groupNames)
        {
            string[] groups = groupNames.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (var g in groups)
            {
                var chatRoom = _service.GetActiveRoomByName(g);

                var chatUser = _service.GetChatUserByConnectionId(Context.ConnectionId);
                var activeChatRooms = _service.GetActiveChatRooms();

                ChatRoomVM roomVM = new ChatRoomVM();

                if (chatRoom != null)
                {
                    //var chatRoomCount = chatRoom.ActiveUserCount;
                    //chatRoomCount--;
                    //chatRoom.ActiveUserCount = chatRoomCount;

                    if (chatRoom.ActiveUserCount > 0)
                    {
                        //chatRoom.HasAdminUser = false;
                        //chatRoom.AdminChatUserId = null;
                        //chatRoom.ChatUser = null;

                        chatRoom.Status = 1;
                        chatRoom.EndTime = GetLocalTime();

                        _service.UpdateChatRoom(chatRoom);

                        roomVM.ActiveUserCount = chatRoom.ActiveUserCount;
                        roomVM.ChatRoomId = chatRoom.ChatRoomId;
                        roomVM.ChatRoomName = chatRoom.ChatRoomName;
                        roomVM.ChatUserId = chatRoom.ChatUserId;
                        roomVM.HasAdminUser = chatRoom.HasAdminUser;

                        //Clients.Group("adminGroup").updateActiveRoom(roomVM);
                        RemoveActiveRoom(g);
                        Clients.Group("adminGroup").removeRoom(chatRoom.ChatRoomName);
                        Clients.Group(chatRoom.ChatRoomName).closeChatSession();

                        //TODIZZLE
                        //RoomFeedVM roomFeed = new RoomFeedVM();

                        //roomFeed.UsersInRoom = chatRoom.ActiveUserCount;
                        //roomFeed.StartTime = chatRoom.StartTime;
                        //roomFeed.RoomName = chatRoom.ChatRoomName;
                        //roomFeed.HelperName = chatUser.FirstName + " " + chatUser.LastName;
                        //roomFeed.ClientId = chatRoom.ChatUserId;
                        //if (chatRoom.HasAdminUser == true) { roomFeed.BeingHelped = "Yes"; } else { roomFeed.BeingHelped = "No"; }
                        //Clients.Group("adminGroup").updateRoom(roomFeed);
                        Groups.Remove(Context.ConnectionId, g);
                    }
                    else if (chatRoom.ActiveUserCount == 0)
                    {
                        // TODO: Save the Room to repository
                        chatRoom.Status = 1;
                        DateTime myUtcDateTime = GetLocalTime();
                        DateTime myConvertedDateTime = TimeZoneInfo.ConvertTime(myUtcDateTime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));
                        chatRoom.EndTime = GetLocalTime();
                        _service.UpdateChatRoom(chatRoom);

                        var rooms = _service.GetActiveChatRooms();

                        RemoveActiveRoom(g);
                        Clients.Group("adminGroup").removeRoom(chatRoom.ChatRoomName);
                        Clients.Group(chatRoom.ChatRoomName).closeChatSession();
                    }
                }
                else
                {
                    Clients.Group("adminGroup").loadActiveRooms(activeChatRooms);
                }
            }
        }
Esempio n. 3
0
        // Add ChatUser and ChatRoom to SignalR Groups
        public void JoinGroup(string groupName)
        {
            Groups.Add(Context.ConnectionId, groupName);

            // If admin, add to ChatRoom's list of active ChatUsers
            //var user = activeUsers.Find(u => u.ConnectionId == Context.ConnectionId);
            //var room = activeChatRooms.Find(r => r.ChatRoomName == groupName);

            var adminUser = _service.GetChatUserByConnectionId(Context.ConnectionId);
            var chatRoom = _service.GetActiveRoomByName(groupName);
            var defaultCannedMessage = _service.GetDefaultCannedMessage();

            if (adminUser != null && chatRoom != null)
            {
                ChatRoomVM roomVM = new ChatRoomVM();
                ChatMessage message = new ChatMessage();

                // Initial Welcome Message
                if (chatRoom.FirstMessage == true)
                {
                    if (defaultCannedMessage != null)
                    {
                        message.ChatRoom = chatRoom;
                        message.ChatRoomId = chatRoom.ChatRoomId;
                        message.UserName = adminUser.UserName;
                        message.Content = defaultCannedMessage.CannedMessageContent;
                        message.MessageSent = GetLocalTime();
                        chatRoom.ChatMessages.Add(message);
                        chatRoom.FirstMessage = false;

                        Clients.Group(groupName).DisplayMessage(message.UserName, message.Content, groupName);
                        Clients.Group(groupName).DisplayMessageToClient(adminUser.FirstName, message.Content);
                    }
                }

                ++chatRoom.ActiveUserCount;
                chatRoom.AdminChatUserId = adminUser.ChatUserId;
                chatRoom.HasAdminUser = true;
                chatRoom.ChatUser = adminUser;

                adminUser.ChatRooms.Add(chatRoom);

                roomVM.HasAdminUser = chatRoom.HasAdminUser;
                roomVM.ActiveUserCount = chatRoom.ActiveUserCount;
                roomVM.ChatRoomName = chatRoom.ChatRoomName;

                _service.UpdateChatRoom(chatRoom);
                _service.UpdateAdminUser(adminUser);

                Clients.OthersInGroup(groupName).userConnected(adminUser.FirstName);
                Clients.Group("adminGroup").updateActiveRoom(roomVM);

                RoomFeedVM roomFeed = new RoomFeedVM();

                roomFeed.UsersInRoom = chatRoom.ActiveUserCount;
                roomFeed.StartTime = chatRoom.StartTime;
                roomFeed.RoomName = chatRoom.ChatRoomName;
                roomFeed.HelperName = adminUser.FirstName + " " + adminUser.LastName;
                roomFeed.ClientId = chatRoom.ChatUserId;
                if (chatRoom.HasAdminUser == true) { roomFeed.BeingHelped = "Yes"; } else { roomFeed.BeingHelped = "No"; }

                // TODO: Update Chat Room in Live Feed
                Clients.All.updateRoom(roomFeed);
            }
        }
Esempio n. 4
0
        // Disconnects Users
        public override Task OnDisconnected()
        {
            // Get user from Active User list
            var user = activeUsers.Find(u => u.ConnectionId == Context.ConnectionId);

            var chatAdminUser = _service.GetChatUserByConnectionId(Context.ConnectionId);

            if (chatAdminUser != null)
            {
                Clients.Group("adminGroup").removeOnlineUser(chatAdminUser.UserName);
            }

            ChatRoomVM roomVM = new ChatRoomVM();

            if (user != null)
            {
                // get room
                var chatRoom = _service.GetActiveRoomByName(user.roomName);
                // Remove user from ChatRoom
                var chatRoomCount = chatRoom.ActiveUserCount;

                chatRoom.ActiveUserCount = chatRoomCount - 1;

                // Check to see if there are any other users
                if (chatRoom.ActiveUserCount == 0)
                {
                    // If no users then remove room from active Chat Rooms list
                    chatRoom.Status = 1;
                    chatRoom.EndTime = GetLocalTime();
                    // Javascript function that removes room from ChatLobby room list.
                    RemoveActiveRoom(chatRoom.ChatRoomName);
                    // Update the room in the database.
                    _service.UpdateChatRoom(chatRoom);
                    Clients.All.removeRoom(chatRoom.ChatRoomName);
                }
                else
                {
                    // If there are still users in a room update the count in the lobby
                    //TODO: change to roomVM
                    roomVM.ActiveUserCount = chatRoom.ActiveUserCount;
                    roomVM.ChatRoomName = chatRoom.ChatRoomName;
                    roomVM.HasAdminUser = chatRoom.HasAdminUser;

                    _service.UpdateChatRoom(chatRoom);
                    Clients.Group("adminGroup").updateActiveRoom(roomVM);
                    // TODO: Place room update code for live feed here
                    RoomFeedVM roomFeed = new RoomFeedVM();

                    roomFeed.UsersInRoom = chatRoom.ActiveUserCount;
                    roomFeed.StartTime = chatRoom.StartTime;
                    roomFeed.RoomName = chatRoom.ChatRoomName;
                    roomFeed.ClientId = chatRoom.ChatUserId;
                    if (chatRoom.HasAdminUser == true) { roomFeed.BeingHelped = "Yes"; } else { roomFeed.BeingHelped = "No"; }
                    Clients.All.updateRoom(roomFeed);
                    Groups.Remove(Context.ConnectionId, roomFeed.RoomName);
                }
                activeUsers.Remove(user);
            }
            else if (chatAdminUser != null && chatAdminUser.IsOnline == true)
            {
                // Notify Admins
                Clients.Group("adminGroup").removeUser(chatAdminUser.UserName);
                Clients.Group("adminGroup").removeOnlineUser(chatAdminUser.UserName);
                // This is used to update the database
                var rooms = _service.GetAllActiveChatRoomsByUser(chatAdminUser.ChatUserId);
                if (rooms != null && rooms.Count > 0)
                {
                    foreach (var r in rooms)
                    {
                        ChatRoomVM chatRoomVM = new ChatRoomVM();
                        --r.ActiveUserCount;
                        if (r.ActiveUserCount == 0)
                        {
                            r.Status = 1;
                            r.EndTime = GetLocalTime();
                            _service.UpdateChatRoom(r);
                            RemoveActiveRoom(r.ChatRoomName);
                            Clients.Group("adminGroup").removeRoom(r.ChatRoomName);
                        }
                        else
                        {
                            r.HasAdminUser = false;
                            r.ChatUser = null;
                            _service.UpdateChatRoom(r);
                            chatRoomVM.ActiveUserCount = r.ActiveUserCount;
                            chatRoomVM.ChatRoomName = r.ChatRoomName;
                            chatRoomVM.HasAdminUser = r.HasAdminUser;
                            Clients.Group("adminGroup").updateActiveRoom(chatRoomVM);
                            // TODO: Place room update code for live feed here
                            RoomFeedVM roomFeed = new RoomFeedVM();

                            roomFeed.UsersInRoom = r.ActiveUserCount;
                            roomFeed.StartTime = r.StartTime;
                            roomFeed.RoomName = r.ChatRoomName;
                            roomFeed.HelperName = chatAdminUser.FirstName + " " + chatAdminUser.LastName;
                            roomFeed.ClientId = r.ChatUserId;
                            if (r.HasAdminUser == true) { roomFeed.BeingHelped = "Yes"; } else { roomFeed.BeingHelped = "No"; }
                            Clients.Group("adminGroup").updateRoom(roomFeed);
                            Groups.Remove(Context.ConnectionId, roomFeed.RoomName);
                        }

                    }
                    chatAdminUser.IsOnline = false;
                    chatAdminUser.LogOutTime = GetLocalTime();

                    _service.UpdateAdminUser(chatAdminUser);
                }
                else
                {
                    chatAdminUser.IsOnline = false;
                    chatAdminUser.LogOutTime = GetLocalTime();
                    _service.UpdateAdminUser(chatAdminUser);
                }
            }
            return base.OnDisconnected();
        }
Esempio n. 5
0
        // Get all current active ChatRooms for display in admin chat lobby
        public void GetActiveRooms()
        {
            var rooms = _service.GetActiveChatRooms();

            List<ChatRoomVM> crList = new List<ChatRoomVM>();

            foreach (var r in rooms)
            {
                ChatRoomVM roomVM = new ChatRoomVM();
                roomVM.ActiveUserCount = r.ActiveUserCount;
                roomVM.ChatRoomId = r.ChatRoomId;
                roomVM.ChatRoomName = r.ChatRoomName;
                roomVM.ChatUserId = r.ChatUserId;
                roomVM.HasAdminUser = r.HasAdminUser;
                crList.Add(roomVM);
            }
            Clients.Client(Context.ConnectionId).loadActiveRooms(crList);
        }