/// <summary>
        /// 验证指定对象针对toUserId是否具有隐私权限
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户</param>
        /// <param name="specifyObjectId">指定对象Id</param>
        /// <returns>true-成功,false-失败</returns>
        bool IPrivacySpecifyObjectValidator.Validate(long userId, long toUserId, long specifyObjectId)
        {
            //done:zhengw,by mazq
            //1、所有分组Id是什么?
            //2、相互关注等特殊规则怎么制定的,编码的人遵照什么来编码
            //zhengw回复:使用FollowSpecifyGroupIds.All获取所有分组Id,具体参见:Examples\BusinessComponents\User\Follow\FollowEnum.cs中的FollowSpecifyGroupIds类

            //如果specifyObjectId为所有分组Id,则仅判断下toUserId是不是关注的人即可
            FollowService followService = new FollowService();

            if (specifyObjectId == FollowSpecifyGroupIds.All)
            {
                return(followService.IsFollowed(userId, toUserId));
            }
            else if (specifyObjectId == FollowSpecifyGroupIds.Mutual)
            {
                return(followService.IsMutualFollowed(userId, toUserId));
            }
            else
            {
                FollowEntity follow = followService.Get(userId, toUserId);
                if (follow == null)
                {
                    return(false);
                }
                IEnumerable <Category> categories = new CategoryService().GetCategoriesOfItem(follow.Id, userId, TenantTypeIds.Instance().User());
                if (categories == null)
                {
                    return(false);
                }
                return(categories.Any(n => n.CategoryId == specifyObjectId));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 判断用户是否关注了某个用户
        /// </summary>
        /// <param name="user"><see cref="IUser"/></param>
        /// <param name="toUserId">待检测用户Id</param>
        /// <returns></returns>
        public static bool IsFollowed(this IUser user, long toUserId)
        {
            if (user == null)
            {
                return(false);
            }

            FollowService followService = new FollowService();

            return(followService.IsFollowed(user.UserId, toUserId));
        }
Esempio n. 3
0
        //done:zhengw,by mazq 缺少注释
        //zhengw回复:已修改

        /// <summary>
        /// 获取接收人UserId集合
        /// </summary>
        /// <param name="activityService">动态业务逻辑类</param>
        /// <param name="activity">动态</param>
        /// <returns></returns>
        IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
        {
            //1、获取用户的所有粉丝,然后通过IsReceiveActivity()检查,是否给该粉丝推送动态;
            FollowService      followService   = new FollowService();
            IEnumerable <long> followerUserIds = followService.GetTopFollowerUserIds(activity.OwnerId, Follow_SortBy.DateCreated_Desc, ValueUtility.GetSqlMaxInt());

            if (followerUserIds == null)
            {
                return(new List <long>());
            }
            return(followerUserIds.Where(n => IsReceiveActivity(activityService, n, activity)));
        }
Esempio n. 4
0
        /// <summary>
        /// 把用户加入黑名单
        /// </summary>
        /// <param name="stopedUser">黑名单</param>
        public bool CreateStopedUser(StopedUser stopedUser)
        {
            FollowService followService = new FollowService();

            followService.CancelFollow(stopedUser.UserId, stopedUser.ToUserId);
            followService.CancelFollow(stopedUser.ToUserId, stopedUser.UserId);

            bool isCreat = stopedUserRepository.CreateStopedUser(stopedUser);

            EventBus <StopedUser> .Instance().OnAfter(stopedUser, new CommonEventArgs(EventOperationType.Instance().Create()));

            return(isCreat);
        }
Esempio n. 5
0
        ///<overloads>隐私验证</overloads>
        /// <summary>
        /// 隐私验证
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户Id</param>
        /// <param name="itemKey">隐私项目Key</param>
        /// <returns>true-验证通过,false-验证失败</returns>
        public bool Validate(long userId, long toUserId, string itemKey)
        {
            if (toUserId == userId)
            {
                return(true);
            }

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

            if (toUserId > 0)
            {
                toUser = userService.GetUser(toUserId);
            }
            if (toUser != null)
            {
                if (toUser.IsSuperAdministrator())
                {
                    return(true);
                }

                //被验证用户为黑名单用户
                if (IsStopedUser(userId, toUserId))
                {
                    return(false);
                }
            }
            Dictionary <string, PrivacyStatus> userUserPrivacySettings = GetUserPrivacySettings(userId);

            if (userUserPrivacySettings.ContainsKey(itemKey))
            {
                switch (userUserPrivacySettings[itemKey])
                {
                case PrivacyStatus.Public:
                    return(true);

                case PrivacyStatus.Part:
                    return(toUser != null && ValidateUserPrivacySpecifyObject(userId, toUserId, itemKey));

                case PrivacyStatus.Private:
                    return(false);

                default:
                    return(false);
                }
            }
            var privacyItem = GetPrivacyItem(itemKey);

            if (privacyItem != null)
            {
                switch (privacyItem.PrivacyStatus)
                {
                case PrivacyStatus.Private:
                    return(false);

                case PrivacyStatus.Part:
                    FollowService followService = new FollowService();
                    return(followService.IsFollowed(userId, toUserId));

                case PrivacyStatus.Public:
                    return(true);

                default:
                    return(true);
                }
            }
            return(false);
        }