示例#1
0
        // Hàm xử lý nếu có user disconnect
        private void UserDisConnect(string connectId, string name)
        {
            using (var db = new OZChatDbContext())
            {
                var user = db.HubUsers.FirstOrDefault(p => p.UserName == name);
                if (user.Connected == true)
                {
                    Clients.Others.disConnect(name, user.FullName, user.ID);
                    var     listConnection     = db.Connection.Where(p => p.UserID == user.ID).ToList();
                    Boolean isRemoveConnection = false;
                    for (var i = 0; i < listConnection.Count(); i++)
                    {
                        if (listConnection[i].ConnectionID == connectId)
                        {
                            db.Connection.Remove(listConnection[i]);
                            isRemoveConnection = true;
                        }
                    }
                    if (isRemoveConnection == true && listConnection.Count == 1)
                    {
                        user.Connected = false;
                    }
                    db.SaveChanges();
                    if (isRemoveConnection == true && listConnection.Count == 1)
                    {
                        CommonStatic.RemoveOnlineUser(user.ID);
                    }

                    CommonStatic.RemoveInteractives(user.ID);
                    CommonStatic.RemoveInteracGroup(user.ID);
                }
            }
            //LeaveRoom();
        }
示例#2
0
        //Hàm lấy ra toàn bộ tin nhắn của 1 nhóm
        public async Task getAllGroupMessage(int groupId)
        {
            var userId = Context.User.Identity.GetUserId();

            using (var db = new OZChatDbContext())
            {
                var messages = db.MessageGroups.Where(p => p.GroupID == groupId).OrderByDescending(p => p.ID).Take(50).ToList();
                await Clients.Caller.allGroupMessage(messages.OrderBy(p => p.ID).ToList(), userId);

                var newMessage = db.NewMessageGroups.FirstOrDefault(p => p.UserID == userId && p.GroupID == groupId);
                if (newMessage != null)
                {
                    await Clients.Caller.devCountMessageGroup(groupId, newMessage.Count);

                    db.NewMessageGroups.Remove(newMessage);
                    db.SaveChanges();
                }
            }
            // Xóa tương tác cũ sau đó thêm tương tác mới
            CommonStatic.RemoveInteracGroup(userId);
            CommonStatic.AddInteracGroup(userId, groupId);
            removeInteracPrivate();
        }
示例#3
0
        public void removeInteracGroup()
        {
            string userId = Context.User.Identity.GetUserId();

            CommonStatic.RemoveInteracGroup(userId);
        }