Example #1
0
        /// <summary>
        /// 获取最近聊天记录-最新50条
        /// </summary>
        /// <returns></returns>
        public JsonResult Friend_GetFriendsNewsList()
        {
            var obj = oFriendsBLL.Friend_GetFriendsNewsList(GetUserInfo().Id);
            List <SessionUserInfo> models = Common.CacheHelper <List <SessionUserInfo> > .GetCache("OnLineUsers");

            ReturnModel <List <ChatUserInfo> > remodel = JsonConvert.DeserializeObject <ReturnModel <List <ChatUserInfo> > >(obj.ToString());

            foreach (ChatUserInfo model in remodel.Data)
            {
                model.IsOnline = 0;
                if (models != null && models.Count(x => x.Id == model.FriendId) > 0)
                {
                    model.IsOnline = 1;
                }
            }
            return(Json(remodel));
        }
Example #2
0
        /// <summary>
        /// 登录连线
        /// </summary>
        public void connect()
        {
            UserInfo = GetSignalrUserInfo();
            ////获取所有的群
            //var GroupsObj = oGroupsBLL.Group_GetAllGroupsList();
            //ReturnModel<List<Friends_ChatGroup>> Groups = JsonConvert.DeserializeObject<ReturnModel<List<Friends_ChatGroup>>>(GroupsObj.ToString());
            ////遍历群判断是否存在在线群里
            //foreach (Friends_ChatGroup Group in Groups.Data)
            //{
            //    if(GroupOnLineUsers.Count(x => x.GroupId == Group.GroupId) == 0)
            //    {
            //        GroupOnLineUsers.Add(Group);
            //    }
            //}

            //var MyGroupObj = oGroupsBLL.Group_GetGroupsList(UserInfo.Id);
            //ReturnModel<List<Friends_GroupList>> MyGroups = JsonConvert.DeserializeObject<ReturnModel<List<Friends_GroupList>>>(MyGroupObj.ToString());

            ////把我加入到存在我的在线群成员里
            //foreach (Friends_GroupList MyGroup in MyGroups.Data)
            //{
            //    if (GroupOnLineUsers.First(p => p.GroupId == MyGroup.Id).GroupOnLineUserInfos != null)
            //    {
            //        if (GroupOnLineUsers.First(p => p.GroupId == MyGroup.Id).GroupOnLineUserInfos.Count(x => x.UserId == UserInfo.Id) == 0)
            //        {
            //            GroupOnLineUsers.First(p => p.GroupId == MyGroup.Id).GroupOnLineUserInfos.Add(new GroupOnLineUserInfo() { UserId = UserInfo.Id });
            //        }
            //    }
            //    else
            //    {
            //        List<GroupOnLineUserInfo> GroupOnLineUserInfos = new List<GroupOnLineUserInfo>();
            //        GroupOnLineUserInfos.Add(new GroupOnLineUserInfo { UserId = UserInfo.Id });
            //        GroupOnLineUsers.First(p => p.GroupId == MyGroup.Id).GroupOnLineUserInfos = GroupOnLineUserInfos;
            //    }
            //}

            //如果不存在
            if (OnLineUsers.Count(x => x.Id == UserInfo.Id) == 0)
            {
                //添加在线人员
                OnLineUsers.Add(UserInfo);
                //把在线人员添加到缓存
                Common.CacheHelper <List <SessionUserInfo> > .Insert("OnLineUsers", OnLineUsers);

                //获取好友列表
                var obj = oFriendsBLL.Friend_GetFriendsNewsList(UserInfo.Id);
                ReturnModel <List <ChatUserInfo> > models = JsonConvert.DeserializeObject <ReturnModel <List <ChatUserInfo> > >(obj.ToString());
                var result = new { UserId = UserInfo.Id, Msg = "您的好友 " + UserInfo.UserName + " 上线了" };
                foreach (ChatUserInfo model in models.Data)
                {
                    //标记上线的好友并加入我的在线好友集合
                    if (OnLineUsers.Count(x => x.Id == model.FriendId) > 0)
                    {
                        model.IsOnline = 1;
                        Clients.User(model.FriendId.ToString()).onLineTips(result);
                    }
                }
                //发送好友列表数据信息给自己
                Clients.Caller.getFriendsNewsList(models);
            }
        }