예제 #1
0
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <param name="fromOwnerId">动态拥有者</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //首先检查是否屏蔽用户
            UserBlockService userBlockService = new UserBlockService();

            if (userBlockService.IsBlockedUser(userId, activity.OwnerId))
            {
                return(false);
            }

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();

            if (privacyService.IsStopedUser(activity.OwnerId, userId))
            {
                return(false);
            }

            //判断指定对象可见
            Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > dictionary = new ContentPrivacyService().GetPrivacySpecifyObjects(activity.TenantTypeId, activity.SourceId);

            if (dictionary != null && dictionary.Count() > 0)
            {
                foreach (var pair in dictionary)
                {
                    IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed <IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                    foreach (var specifyObject in pair.Value)
                    {
                        if (privacySpecifyUserGetter.Validate(activity.OwnerId, userId, specifyObject.SpecifyObjectId))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }

            //检查用户是否接收该动态项目
            Dictionary <string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                {
                    return(activityItem.IsUserReceived);
                }
                else
                {
                    return(true);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 内容隐私验证
        /// </summary>
        /// <param name="privacyable">可隐私接口</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(IPrivacyable privacyable, long toUserId)
        {
            if (privacyable.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }
            if (privacyable.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            if (toUserId == privacyable.UserId)
            {
                return(true);
            }

            //被验证用户为超级管理员
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        toUser      = userService.GetUser(toUserId);

            if (toUser.IsInRoles(RoleNames.Instance().SuperAdministrator()))
            {
                return(true);
            }

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();

            if (privacyService.IsStopedUser(privacyable.UserId, toUserId))
            {
                return(false);
            }

            //判断指定对象可见
            Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > dictionary = GetPrivacySpecifyObjects(privacyable.TenantTypeId, privacyable.ContentId);

            if (dictionary == null || dictionary.Count() == 0)
            {
                return(false);
            }
            foreach (var pair in dictionary)
            {
                IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed <IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                foreach (var specifyObject in pair.Value)
                {
                    if (privacySpecifyUserGetter.Validate(privacyable.UserId, toUserId, specifyObject.SpecifyObjectId))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #3
0
        /// <summary>
        /// 解析内容用于创建AtUser
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="userId">内容作者UserId</param>
        /// <param name="associateId">关联项Id</param>
        public void ResolveBodyForEdit(string body, long userId, long associateId)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("@"))
            {
                return;
            }

            List <long> userIds = new List <long>();

            PrivacyService privacyService = new PrivacyService();
            IUserService   userService    = DIContainer.Resolve <IUserService>();

            string userNameRegex = new UserSettings().NickNameRegex, tempNickName = string.Empty;

            userNameRegex = userNameRegex.TrimStart('^').TrimEnd('$');

            Regex           rg      = new Regex("(?<=(\\@))" + userNameRegex, RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches = rg.Matches(body);

            if (matches != null)
            {
                foreach (Match m in matches)
                {
                    if (string.IsNullOrEmpty(m.Value) || tempNickName.Equals(m.Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    tempNickName = m.Value;
                    IUser user = userService.GetUserByNickName(tempNickName);

                    if (user == null ||
                        userIds.Contains(user.UserId) ||
                        !privacyService.Validate(user.UserId, userId, PrivacyItemKeys.Instance().AtUser()))
                    {
                        continue;
                    }

                    userIds.Add(user.UserId);
                }
            }

            if (userIds.Count > 0)
            {
                BatchCreateAtUser(userIds, associateId, userId);
            }
        }
예제 #4
0
        /// <summary>
        /// 解析内容中的AtUser用户展示展示
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="associateId">关联项Id</param>
        /// <param name="userId">关联项作者Id</param>
        /// <param name="TagGenerate">用户生成对应标签的方法</param>
        public string ResolveBodyForDetail(string body, long associateId, long userId, Func <string, string, string> TagGenerate)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("@") || userId <= 0)
            {
                return(body);
            }

            IList <long> userIds = GetAtUserIds(associateId);

            if (userIds != null)
            {
                PrivacyService privacyService = new PrivacyService();
                IUserService   userService    = DIContainer.Resolve <IUserService>();
                bool           endMatch       = false;
                foreach (var atUserId in userIds)
                {
                    if (atUserId == 0)
                    {
                        continue;
                    }

                    IUser user = userService.GetUser(atUserId);
                    if (user == null)
                    {
                        continue;
                    }

                    if (privacyService.Validate(user.UserId, userId, PrivacyItemKeys.Instance().AtUser()))
                    {
                        string nickName = user.NickName;

                        body = body.Replace("@" + nickName, TagGenerate(user.UserName, nickName));
                        body = body.Replace("@" + nickName + "</p>", TagGenerate(user.UserName, nickName) + "</p>");

                        if (!endMatch && body.EndsWith("@" + nickName))
                        {
                            endMatch = true;
                            body     = body.Remove(body.Length - (nickName.Length + 1), nickName.Length + 1) + TagGenerate(user.UserName, nickName);
                        }
                    }
                }
            }
            return(body);
        }
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <param name="fromOwnerId">动态拥有者</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //首先检查是否屏蔽用户
            UserBlockService userBlockService = new UserBlockService();
            if (userBlockService.IsBlockedUser(userId, activity.OwnerId))
                return false;

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();
            if (privacyService.IsStopedUser(activity.OwnerId, userId))
                return false;

            //判断指定对象可见
            Dictionary<int, IEnumerable<ContentPrivacySpecifyObject>> dictionary = new ContentPrivacyService().GetPrivacySpecifyObjects(activity.TenantTypeId, activity.SourceId);
            if (dictionary != null && dictionary.Count() > 0)
            {
                foreach (var pair in dictionary)
                {
                    IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed<IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                    foreach (var specifyObject in pair.Value)
                    {
                        if (privacySpecifyUserGetter.Validate(activity.OwnerId, userId, specifyObject.SpecifyObjectId))
                            return true;
                    }
                }
                return false;
            }

            //检查用户是否接收该动态项目
            Dictionary<string, bool> userSettings = activityService.GetActivityItemUserSettings(userId);
            if (userSettings.ContainsKey(activity.ActivityItemKey))
                return userSettings[activity.ActivityItemKey];
            else
            {
                //如果用户没有设置从默认设置获取
                ActivityItem activityItem = activityService.GetActivityItem(activity.ActivityItemKey);
                if (activityItem != null)
                    return activityItem.IsUserReceived;
                else
                    return true;
            }
        }
예제 #6
0
        /// <summary>
        /// 内容隐私验证
        /// </summary>        
        /// <param name="privacyable">可隐私接口</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(IPrivacyable privacyable, long toUserId)
        {
            if (privacyable.PrivacyStatus == PrivacyStatus.Public)
                return true;
            if (privacyable.PrivacyStatus == PrivacyStatus.Private)
                return false;

            if (toUserId == privacyable.UserId)
                return true;

            //被验证用户为超级管理员
            IUserService userService = DIContainer.Resolve<IUserService>();
            IUser toUser = userService.GetUser(toUserId);
            if (toUser.IsSuperAdministrator())
                return true;

            //被验证用户为黑名单用户
            PrivacyService privacyService = new PrivacyService();
            if (privacyService.IsStopedUser(privacyable.UserId, toUserId))
                return false;

            //判断指定对象可见
            Dictionary<int, IEnumerable<ContentPrivacySpecifyObject>> dictionary = GetPrivacySpecifyObjects(privacyable.TenantTypeId, privacyable.ContentId);
            if (dictionary == null || dictionary.Count() == 0)
                return false;
            foreach (var pair in dictionary)
            {
                IPrivacySpecifyObjectValidator privacySpecifyUserGetter = DIContainer.ResolveNamed<IPrivacySpecifyObjectValidator>(pair.Key.ToString());
                foreach (var specifyObject in pair.Value)
                {
                    if (privacySpecifyUserGetter.Validate(privacyable.UserId, toUserId, specifyObject.SpecifyObjectId))
                        return true;
                }
            }
            return false;
        }
예제 #7
0
        /// <summary>
        /// 搜索“使用了相同标签”的用户
        /// </summary>
        /// <param name="userId">当前用户的ID(浏览者)</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="tagNameDic">存储用户ID到标签列表的映射,用于页面列表输出</param>
        /// <returns></returns>
        public PagingDataSet<User> SearchInterestedWithTags(long userId, int pageIndex, int pageSize, out Dictionary<long, IEnumerable<string>> tagNameDic)
        {
            //Dictionary,用于页面列表输出
            tagNameDic = new Dictionary<long, IEnumerable<string>>();

            //无效用户ID,直接返回空列表
            if (userId <= 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            Query query = null;
            Filter filter = null;
            Sort sort = null;

            //先搜索出当前用户的标签
            //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort
            LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder();
            searchBuilder.WithField(UserIndexDocument.UserId, userId.ToString(), true);
            searchBuilder.BuildQuery(out query, out filter, out sort);

            IEnumerable<Document> docs = searchEngine.Search(query, filter, sort, 1);

            //索引中无此用户,直接返回空列表
            if (docs == null || docs.Count<Document>() == 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            string[] myTagNames = docs.First<Document>().GetValues(UserIndexDocument.TagName);

            //当前用户无标签,直接返回空列表
            if (myTagNames != null && myTagNames.Count() == 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            //查找有相同标签的用户
            //先查询当前用户关注的人(包括“悄悄关注”的用户),此处需要调用数据库查询,因为索引中没有存储“是否悄悄关注”属性
            IEnumerable<long> myFollowedUserIds = followService.GetPortionFollowedUserIds(userId);
            //黑名单用户
            IEnumerable<long> stopUserIds = new PrivacyService().GetStopedUsers(userId).Select(n => n.Key);
            //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort
            searchBuilder = new LuceneSearchBuilder(0);
            //搜索条件需要排除掉当前用户本身
            searchBuilder.WithPhrases(UserIndexDocument.TagName, myTagNames.ToList<string>())
                         .NotWithField(UserIndexDocument.UserId, userId.ToString()) //排除掉当前用户
                         .NotWithFields(UserIndexDocument.UserId, myFollowedUserIds.Select(n => n.ToString()))//排除掉已关注用户
                         .NotWithFields(UserIndexDocument.UserId, stopUserIds.Select(n => n.ToString()));//排除掉黑名单用户
            searchBuilder.BuildQuery(out query, out filter, out sort);

            PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, pageIndex, pageSize);
            docs = searchResult.ToList<Document>();

            //如果没有使用相同标签的用户,直接返回空列表
            if (docs == null || docs.Count<Document>() == 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            //“使用了相同标签”的用户ID列表
            List<long> sameUserIds = new List<long>();
            foreach (Document doc in docs)
            {
                long sameUserId = long.Parse(doc.Get(UserIndexDocument.UserId));
                sameUserIds.Add(sameUserId);

                string[] tagNames = doc.GetValues(UserIndexDocument.TagName);

                //比较获取“相同的标签”
                IEnumerable<string> sameTagNames = myTagNames.Intersect<string>(tagNames);

                //加入Dictionary,用于页面列表输出
                if (!tagNameDic.ContainsKey(sameUserId))
                {
                    tagNameDic.Add(sameUserId, sameTagNames);
                }
            }

            //批量查询“使用了相同标签”的用户列表
            IEnumerable<User> sameUsers = userService.GetFullUsers(sameUserIds).Where(n => n.IsCanbeFollow == true && n.IsActivated == true && n.IsBanned == false);

            //组装分页对象
            PagingDataSet<User> users = new PagingDataSet<User>(sameUsers)
            {
                TotalRecords = searchResult.TotalRecords,
                PageSize = searchResult.PageSize,
                PageIndex = searchResult.PageIndex,
                QueryDuration = searchResult.QueryDuration
            };

            return users;
        }
예제 #8
0
        /// <summary>
        /// 用户卡片
        /// </summary>
        public ActionResult _UserCard(long userId)
        {
            IUser user = userService.GetFullUser(userId);
            if (user == null)
            {
                return HttpNotFound();
            }

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser != null)
            {
                bool isStopped = new PrivacyService().IsStopedUser(currentUser.UserId, user.UserId);
                ViewData["isStopped"] = isStopped;
            }

            bool seeMessage = false;
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Message()))
            {
                seeMessage = true;
            }
            ViewData["seeMessage"] = seeMessage;

            return View(user);
        }
예제 #9
0
        public JsonResult _IsStopped(long userId)
        {
            if (UserContext.CurrentUser != null)
            {
                Dictionary<long, StopedUser> stopedUsers = new PrivacyService().GetStopedUsers(UserContext.CurrentUser.UserId);
                if (stopedUsers.Keys.Contains(userId))
                {
                    return Json(new { isStoped = true }, JsonRequestBehavior.AllowGet);
                }
            }

            return Json(new { isStoped = false }, JsonRequestBehavior.AllowGet);
        }
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
            {
                filterContext.Result = new HttpNotFoundResult();
                return;
            }
            IUserService userService = DIContainer.Resolve<IUserService>();
            User currentSpaceUser = userService.GetFullUser(spaceKey);
            if (currentSpaceUser == null)
            {
                filterContext.Result = new HttpNotFoundResult();
                return;
            }
            IUser currentUser = UserContext.CurrentUser;
            //判断空间访问隐私
            PrivacyService privacyService = new PrivacyService();
            if (!privacyService.Validate(currentSpaceUser.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().VisitUserSpace()))
            {
                if (currentUser == null)
                {
                    if (filterContext.HttpContext.Request.IsAjaxRequest())
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(false, SiteUrls.LoginModal._LoginInModal));
                    else
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                }
                else
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().PrivacyHome(currentSpaceUser.UserName)/* 跳向无权访问页 */);
                return;
            }

            //判断该用户是否有访问该空间的权限
            if (!RequireOwnerOrAdministrator)
                return;
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(false, SiteUrls.LoginModal._LoginInModal));
                else
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (currentSpaceUser.UserId == currentUser.UserId)
            {
                //if (currentUser.IsBanned)
                //{
                //    IAuthenticationService authenticationService = DIContainer.ResolvePerHttpRequest<IAuthenticationService>();
                //    authenticationService.SignOut();
                //    filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                //      {
                //          Title = "帐号被封禁!",
                //          Body = "由于您的非法操作,您的帐号已被封禁,如有疑问,请联系管理员",
                //          StatusMessageType = StatusMessageType.Error
                //      }));
                //}
                return;
            }
            if (currentUser.IsInRoles(RoleNames.Instance().SuperAdministrator(), RoleNames.Instance().ContentAdministrator()))
                return;
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title = "无权访问",
                Body = "您无权访问此页面,只有空间主人或管理员才能访问",
                StatusMessageType = StatusMessageType.Hint
            })/* 跳向无权访问页 */);
        }
예제 #11
0
        public ActionResult PersonalInformation(string spaceKey)
        {
            pageResourceManager.InsertTitlePart("个人资料");
            User user = userService.GetFullUser(spaceKey);
            IUser currentUser = UserContext.CurrentUser;

            IEnumerable<WorkExperience> workExperiences = userProfileService.GetWorkExperiences(user.UserId);
            ViewData["workExperiences"] = workExperiences;
            IEnumerable<EducationExperience> educationExperiences = userProfileService.GetEducationExperiences(user.UserId);
            ViewData["educationExperiences"] = educationExperiences;

            PrivacyService privacyService = new PrivacyService();
            bool seeBirthDay = false;
            bool seeMobile = false;
            bool seeEmail = false;
            bool seeQQ = false;
            bool seeMsn = false;
            bool seeWork = false;
            bool seeEducation = false;
            bool seeUserSpace = false;
            bool seeFollow = false;
            bool seeMessage = false;
            bool seeTrueName = false;
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Birthday()))
            {
                seeBirthDay = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Mobile()))
            {
                seeMobile = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Email()))
            {
                seeEmail = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().QQ()))
            {
                seeQQ = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Msn()))
            {
                seeMsn = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().WorkExperience()))
            {
                seeWork = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().EducationExperience()))
            {
                seeEducation = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().VisitUserSpace()))
            {
                seeUserSpace = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().InviteFollow()))
            {
                seeFollow = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Message()))
            {
                seeMessage = true;
            }
            if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().TrueName()))
            {
                seeTrueName = true;
            }

            ViewData["seeBirthDay"] = seeBirthDay;
            ViewData["seeMobile"] = seeMobile;
            ViewData["seeEmail"] = seeEmail;
            ViewData["seeQQ"] = seeQQ;
            ViewData["seeMsn"] = seeMsn;
            ViewData["seeWork"] = seeWork;
            ViewData["seeEducation"] = seeEducation;
            ViewData["seeUserSpace"] = seeUserSpace;
            ViewData["seeFollow"] = seeFollow;
            ViewData["seeMessage"] = seeMessage;
            ViewData["seeTrueName"] = seeTrueName;
            return View(user);
        }
예제 #12
0
        /// <summary>
        /// 搜索共同关注的人
        /// </summary>
        /// <param name="userId">粉丝的用户ID</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="followedUserIdDic">每个相同关注用户中共同关注的用户ID列表</param>
        /// <param name="followedUserDic">每个共同关注的用户的ID与User的映射</param>
        /// <returns>符合搜索条件的User分页集合</returns>
        public PagingDataSet<User> SearchInterestedWithFollows(long userId, int pageIndex, int pageSize, out Dictionary<long, IEnumerable<long>> followedUserIdDic, out Dictionary<long, User> followedUserDic)
        {
            followedUserIdDic = new Dictionary<long, IEnumerable<long>>();
            followedUserDic = new Dictionary<long, User>();

            if (userId <= 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            //先查询当前用户关注的人(包括“悄悄关注”的用户),此处需要调用数据库查询,因为索引中没有存储“是否悄悄关注”属性
            IEnumerable<long> myFollowedUserIds = followService.GetPortionFollowedUserIds(userId);
            if (myFollowedUserIds != null && myFollowedUserIds.Count() == 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            //黑名单用户
            IEnumerable<long> stopUserIds = new PrivacyService().GetStopedUsers(userId).Select(n => n.Key);

            //搜索“我”关注的人中包含“共同关注的人”的用户
            //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort
            Query query = null;
            Filter filter = null;
            Sort sort = null;
            LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder();
            searchBuilder.WithFields(FollowedUserIds, myFollowedUserIds.Select(n => n.ToString()), true)
                         .NotWithField(UserId, userId.ToString())//排除掉当前用户
                         .NotWithFields(UserIndexDocument.UserId, myFollowedUserIds.Select(n => n.ToString()))//排除掉已关注用户
                         .NotWithFields(UserIndexDocument.UserId, stopUserIds.Select(n => n.ToString()));//排除掉黑名单用户
            searchBuilder.BuildQuery(out query, out filter, out sort);

            PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, pageIndex, pageSize);
            IEnumerable<Document> docs = searchResult.ToList<Document>();

            if (docs == null || docs.Count() == 0)
            {
                return new PagingDataSet<User>(new List<User>());
            }

            List<long> sameFollowedUserIdList = new List<long>();

            //解析出搜索结果中的用户ID
            List<long> followerUserIds = new List<long>();
            foreach (Document doc in docs)
            {
                long followerUserId = long.Parse(doc.Get(UserId));
                followerUserIds.Add(followerUserId);

                //“我”关注的人关注的人
                string[] followedUserIds = doc.GetValues(FollowedUserIds);

                //比较获取“共同关注的人”
                IEnumerable<long> sameFollowedUserIds = myFollowedUserIds.Intersect<long>(followedUserIds.Select(n => Convert.ToInt64(n)));
                if (!followedUserIdDic.ContainsKey(followerUserId))
                {
                    followedUserIdDic.Add(followerUserId, sameFollowedUserIds);
                }

                sameFollowedUserIdList.AddRange(sameFollowedUserIds);
            }

            //批量查询“共同关注的用户”列表
            IEnumerable<User> followerUserList = userService.GetFullUsers(followerUserIds).Where(n => n.IsCanbeFollow == true && n.IsActivated == true && n.IsBanned == false);

            //组装分页对象
            PagingDataSet<User> users = new PagingDataSet<User>(followerUserList)
            {
                TotalRecords = searchResult.TotalRecords,
                PageSize = searchResult.PageSize,
                PageIndex = searchResult.PageIndex,
                QueryDuration = searchResult.QueryDuration
            };

            //批量查询“共同关注的用户”关注的“共同关注用户”列表
            IEnumerable<User> sameFollowedUserList = userService.GetFullUsers(sameFollowedUserIdList.Distinct());
            followedUserDic = sameFollowedUserList.ToDictionary(n => n.UserId);

            return users;
        }
예제 #13
0
        /// <summary>
        /// 可能感兴趣的人
        /// </summary>
        /// <returns></returns>
        public ActionResult Interested()
        {
            IUser CurrentUser = UserContext.CurrentUser;
            if (CurrentUser == null)
            {
                return Redirect(SiteUrls.Instance().Login());
            }

            // 没有感兴趣的人时,推荐人气用户,需去除已关注用户和自己
            //根据点击数取热门用户
            IEnumerable<IUser> topUsers = userService.GetTopUsers(100, SortBy_User.HitTimes);

            //已关注用户
            IEnumerable<long> followedUserIds = followService.GetTopFollowedUserIds(CurrentUser.UserId, 1000);

            //黑名单用户
            IEnumerable<long> stopUserIds = new PrivacyService().GetStopedUsers(CurrentUser.UserId).Select(n => n.Key);

            //去除已关注用户和加黑名单用户
            IEnumerable<IUser> hotUsers = topUsers.Where(n => !followedUserIds.Contains(n.UserId) && n.UserId != CurrentUser.UserId && !stopUserIds.Contains(n.UserId)).Take(Math.Min(8, topUsers.Count()));
            ViewData["userName"] = CurrentUser.UserName;
            pageResourceManager.InsertTitlePart("可能感兴趣的人");

            return View(hotUsers);
        }
예제 #14
0
파일: AtUserService.cs 프로젝트: hbulzy/SYS
        /// <summary>
        /// 解析内容用于创建AtUser
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="userId">内容作者UserId</param>
        /// <param name="associateId">关联项Id</param>
        public void ResolveBodyForEdit(string body, long userId, long associateId)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("@"))
                return;

            List<long> userIds = new List<long>();

            PrivacyService privacyService = new PrivacyService();
            IUserService userService = DIContainer.Resolve<IUserService>();

            string userNameRegex = new UserSettings().NickNameRegex, tempNickName = string.Empty;
            userNameRegex = userNameRegex.TrimStart('^').TrimEnd('$');

            Regex rg = new Regex("(?<=(\\@))" + userNameRegex, RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches = rg.Matches(body);

            if (matches != null)
            {
                foreach (Match m in matches)
                {
                    if (string.IsNullOrEmpty(m.Value) || tempNickName.Equals(m.Value, StringComparison.CurrentCultureIgnoreCase))
                        continue;

                    tempNickName = m.Value;
                    IUser user = userService.GetUserByNickName(tempNickName);

                    if (user == null
                        || userIds.Contains(user.UserId)
                        || !privacyService.Validate(user.UserId, userId, PrivacyItemKeys.Instance().AtUser()))
                        continue;

                    userIds.Add(user.UserId);
                }
            }

            if (userIds.Count > 0)
                BatchCreateAtUser(userIds, associateId, userId);
        }
예제 #15
0
파일: AtUserService.cs 프로젝트: hbulzy/SYS
        /// <summary>
        /// 解析内容中的AtUser用户展示展示
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="associateId">关联项Id</param>
        /// <param name="userId">关联项作者Id</param>
        /// <param name="TagGenerate">用户生成对应标签的方法</param>
        public string ResolveBodyForDetail(string body, long associateId, long userId, Func<string, string, string> TagGenerate)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("@") || userId <= 0)
                return body;

            IList<long> userIds = GetAtUserIds(associateId);

            if (userIds != null)
            {
                PrivacyService privacyService = new PrivacyService();
                IUserService userService = DIContainer.Resolve<IUserService>();
                bool endMatch = false;
                foreach (var atUserId in userIds)
                {
                    if (atUserId == 0)
                        continue;

                    IUser user = userService.GetUser(atUserId);
                    if (user == null)
                        continue;

                    if (privacyService.Validate(user.UserId, userId, PrivacyItemKeys.Instance().AtUser()))
                    {
                        string nickName = user.NickName;

                        body = body.Replace("@" + nickName, TagGenerate(user.UserName, nickName));
                        body = body.Replace("@" + nickName + "</p>", TagGenerate(user.UserName, nickName) + "</p>");

                        if (!endMatch && body.EndsWith("@" + nickName))
                        {
                            endMatch = true;
                            body = body.Remove(body.Length - (nickName.Length + 1), nickName.Length + 1) + TagGenerate(user.UserName, nickName);
                        }
                    }
                }
            }
            return body;
        }