コード例 #1
0
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="activityService"></param>
        /// <param name="userId">UserId</param>
        /// <param name="activity">动态</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //检查用户是否已在信息发布者的粉丝圈里面
            FollowService followService = new FollowService();

            if (followService.IsFollowed(userId, activity.UserId))
            {
                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>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary <long, bool> isFollowesUser = new Dictionary <long, bool>();

            long userId        = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService      followService = new FollowService();
            IEnumerable <long> ids           = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable <User> users = userService.GetFullUsers(ids);

            return(View(users));
        }
コード例 #3
0
        /// <summary>
        /// 最新加入
        /// </summary>
        /// <param name="spaceKey">群组标识</param>
        /// <param name="topNumber">前几条数据</param>
        /// <returns></returns>
        public ActionResult _ListMembers(string spaceKey, int topNumber)
        {
            long  groupId     = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey);
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(new EmptyResult());
            }
            PagingDataSet <GroupMember> groupMembers = groupService.GetGroupMembers(groupId, false, SortBy_GroupMember.DateCreated_Desc);
            IEnumerable <GroupMember>   members      = groupMembers.Take(topNumber);
            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (var member in members)
            {
                if (followService.IsFollowed(currentUser.UserId, member.UserId))
                {
                    isCurrentUserFollowDic[member.UserId] = true;
                }
                else
                {
                    isCurrentUserFollowDic[member.UserId] = false;
                }
            }
            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            return(View(members));
        }
コード例 #4
0
 /// <summary>
 /// 检查用户是否接收动态
 /// </summary>
 /// <param name="activityService"></param>
 /// <param name="isPublic">群组是否为公开群组</param>
 /// <param name="userId">UserId</param>
 /// <param name="activity">动态</param>
 /// <returns>接收动态返回true,否则返回false</returns>
 private bool IsReceiveActivity(ActivityService activityService, bool isPublic, long userId, Activity activity)
 {
     if (isPublic)
     {
         //检查用户是否已在信息发布者的粉丝圈里面
         FollowService followService = new FollowService();
         if (followService.IsFollowed(userId, activity.UserId))
             return false;
     }
     //检查用户是否已屏蔽群组
     if (new UserBlockService().IsBlockedGroup(userId, activity.OwnerId))
         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;
     }
 }
コード例 #5
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);
        }
コード例 #6
0
        public void TestIsFollowed()
        {
            mockFollowRepository.Setup(x => x.IsFollowed(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            var  followService = new FollowService(mockFollowRepository.Object);
            bool checkFolled   = followService.IsFollowed("5d111299f3b75e0001f4ed78", "5d111299f3b75e0001f4ed78");

            Assert.IsTrue(checkFolled);
        }
コード例 #7
0
        /// <summary>
        /// 微博图片模式数据页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="tenantTypeId"></param>
        /// <param name="mediaType"></param>
        /// <param name="isOriginal"></param>
        /// <param name="sortBy"></param>
        /// <returns></returns>
        public ActionResult _Waterfall(int pageIndex = 1, string tenantTypeId = "", MediaType?mediaType = null, bool?isOriginal = null, SortBy_Microblog sortBy = SortBy_Microblog.DateCreated)
        {
            //获取微博分页数据
            PagingDataSet <MicroblogEntity> MicroblogEntities = microblogService.GetPagings(pageIndex, tenantTypeId: TenantTypeIds.Instance().User(), mediaType: mediaType, sortBy: sortBy);

            //获取微博图片
            AttachmentService <Attachment> attachementService = new AttachmentService <Attachment>(TenantTypeIds.Instance().Microblog());

            foreach (var MicroblogEntity in MicroblogEntities.Where(n => n.HasPhoto))
            {
                IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(MicroblogEntity.MicroblogId);

                if (attachments != null && attachments.Count <Attachment>() > 0)
                {
                    MicroblogEntity.ImageWidth = attachments.First().Width;
                    MicroblogEntity.ImageUrl   = SiteUrls.Instance().ImageUrl(attachments.First(), TenantTypeIds.Instance().Microblog(), ImageSizeTypeKeys.Instance().Big());
                }
            }

            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                //设置当前登录用户对当前页用户的关注情况
                Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();
                foreach (var user in MicroblogEntities.Select(m => m.User))
                {
                    if (user == null)
                    {
                        continue;
                    }

                    //如果当前登录用户关注了该用户
                    if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                    {
                        if (!isCurrentUserFollowDic.ContainsKey(user.UserId))
                        {
                            isCurrentUserFollowDic.Add(user.UserId, true);
                        }
                    }
                    else
                    {
                        if (!isCurrentUserFollowDic.ContainsKey(user.UserId))
                        {
                            isCurrentUserFollowDic.Add(user.UserId, false);
                        }
                    }
                }
                ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            }

            return(View(MicroblogEntities.AsEnumerable <MicroblogEntity>()));
        }
コード例 #8
0
ファイル: FindUserController.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 排行榜
        /// </summary>
        /// <returns></returns>
        public ActionResult Ranking(SortBy_User?sortBy = null, int pageIndex = 1)
        {
            if (sortBy == null)
            {
                sortBy = SortBy_User.HitTimes;
            }
            PagingDataSet <User> users = userService.GetPagingUsers(sortBy, pageIndex, 20);
            IUser CurrentUser          = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                //设置当前登录用户对当前页用户的关注情况
                Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();
                foreach (var user in users)
                {
                    //如果当前登录用户关注了该用户
                    if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                    {
                        isCurrentUserFollowDic[user.UserId] = true;
                    }
                    else
                    {
                        isCurrentUserFollowDic[user.UserId] = false;
                    }
                }
                ViewData["sortBy"] = sortBy;
                ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            }

            //查询用户标签
            IEnumerable <long>                itemInTagIds   = tagService.GetItemInTagIdsByItemIds(users.Select(n => n.UserId));
            IEnumerable <ItemInTag>           itemInTags     = tagService.GetItemInTags(itemInTagIds);
            Dictionary <long, List <string> > userTagNameDic = new Dictionary <long, List <string> >();

            foreach (ItemInTag itemInTag in itemInTags)
            {
                if (userTagNameDic.ContainsKey(itemInTag.ItemId))
                {
                    List <string> tagNames = userTagNameDic[itemInTag.ItemId];
                    tagNames.Add(itemInTag.TagName);
                }
                else
                {
                    List <string> tagNames = new List <string>();
                    tagNames.Add(itemInTag.TagName);
                    userTagNameDic.Add(itemInTag.ItemId, tagNames);
                }
            }
            ViewData["userTagNameDic"] = userTagNameDic;

            pageResourceManager.InsertTitlePart("用户排行");

            return(View(users));
        }
コード例 #9
0
        /// <summary>
        /// 检查用户是否接收动态
        /// </summary>
        /// <param name="activityService"></param>
        /// <param name="userId">UserId</param>
        /// <param name="activity">动态</param>
        /// <returns>接收动态返回true,否则返回false</returns>
        private bool IsReceiveActivity(ActivityService activityService, long userId, Activity activity)
        {
            //检查用户是否已在信息发布者的粉丝圈里面
            if (followService.IsFollowed(userId, activity.UserId))
            {
                return(false);
            }

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

            if (userSettings.ContainsKey(activity.ActivityItemKey))
            {
                return(userSettings[activity.ActivityItemKey]);
            }
            else
            {
                return(isUserReceived);
            }
        }
コード例 #10
0
        public ActionResult _CreateGroupMember(long ActivityId)
        {
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(Content(string.Empty));
            }

            GroupEntity group = groupService.Get(activity.ReferenceId);

            if (group == null)
            {
                return(Content(string.Empty));
            }
            IUser currentUser = UserContext.CurrentUser;

            IEnumerable <GroupMember> groupMembers = groupService.GetGroupMembers(group.GroupId, true, SortBy_GroupMember.DateCreated_Desc);

            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (GroupMember user in groupMembers)
            {
                //如果当前登录用户关注了该用户
                if (followService.IsFollowed(currentUser == null ? 0 : currentUser.UserId, user.UserId))
                {
                    isCurrentUserFollowDic[user.UserId] = true;
                }
                else
                {
                    isCurrentUserFollowDic[user.UserId] = false;
                }
            }

            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            ViewData["ActivityId"]             = ActivityId;
            ViewData["GroupMembers"]           = groupMembers;
            ViewData["ActivityUserId"]         = activity.UserId;
            return(View(group));
        }
コード例 #11
0
ファイル: MicroblogController.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 关注的用户菜单控件
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary<long, bool> isFollowesUser = new Dictionary<long, bool>();

            long userId = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService followService = new FollowService();
            IEnumerable<long> ids = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable<User> users = userService.GetFullUsers(ids);

            return View(users);
        }
コード例 #12
0
ファイル: PrivacyService.cs プロジェクト: ClaytonWang/Dw3cSNS
        ///<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;
        }