/// <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)); } }
/// <summary> /// 取消关注后更新缓存 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void CancelFollowEventModule_After(FollowEntity sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { CategoryService service = new CategoryService(); service.ClearCategoriesFromItem(sender.Id, sender.UserId, TenantTypeIds.Instance().User()); //更新用户缓存 ICacheService cacheService = DIContainer.Resolve<ICacheService>(); RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(User)).RealTimeCacheHelper; if (cacheService.EnableDistributedCache) { realTimeCacheHelper.IncreaseEntityCacheVersion(sender.UserId); } else { string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(sender.UserId); User user = cacheService.Get<User>(cacheKey); if (user != null && user.FollowedCount > 0) { user.FollowedCount--; } } } }
/// <summary> /// 更新关注实体 /// </summary> /// <param name="follow">关注用户实体</param> public void Update(FollowEntity follow) { EventBus <FollowEntity> .Instance().OnBefore(follow, new CommonEventArgs(EventOperationType.Instance().Update())); followRepository.Update(follow); EventBus <FollowEntity> .Instance().OnAfter(follow, new CommonEventArgs(EventOperationType.Instance().Update())); }
/// <summary> /// 移除用户的粉丝 /// </summary> /// <param name="userId">用户Id</param> /// <param name="followerUserId">粉丝的用户Id</param> public void RemoveFollower(long userId, long followerUserId) { followRepository.RemoveFollower(userId, followerUserId); FollowEntity follow = followRepository.Get(followerUserId, userId); EventBus <FollowEntity> .Instance().OnAfter(follow, new CommonEventArgs(EventOperationType.Instance().Delete())); }
/// <summary> /// 清除用户关注 /// </summary> /// <param name="userId">用户Id</param> public void CleanByUser(long userId) { followRepository.CleanByUser(userId); FollowEntity follow = FollowEntity.New(); follow.UserId = userId; EventBus <FollowEntity> .Instance().OnAfter(follow, new CommonEventArgs(EventOperationType.Instance().Delete())); }
/// <summary> /// 取消关注 /// </summary> /// <param name="userId">用户Id</param> /// <param name="followedUserId">被关注用户Id</param> public void CancelFollow(long userId, long followedUserId) { FollowEntity follow = followRepository.Get(userId, followedUserId); EventBus <FollowEntity> .Instance().OnBefore(follow, new CommonEventArgs(EventOperationType.Instance().Delete())); followRepository.CancelFollow(userId, followedUserId); EventBus <FollowEntity> .Instance().OnAfter(follow, new CommonEventArgs(EventOperationType.Instance().Delete())); }
/// <summary> /// 新建实体时使用 /// </summary> public static FollowEntity New() { FollowEntity followedUser = new FollowEntity() { NoteName = string.Empty, IsNewFollower = true, DateCreated = DateTime.UtcNow }; return(followedUser); }
private void FollowUser_After(FollowEntity followEntity,CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { if (searcher == null) { searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE); } searcher.Update(followEntity.UserId); } }
/// <summary> /// 判断是否关注了被判定用户 /// </summary> /// <param name="userId">用户Id</param> /// <param name="toUserId">被判定用户Id</param> /// <param name="groupNames">被关注用户所属分组</param> /// <returns>true-关注,false-没关注</returns> public bool IsFollowed(long userId, long toUserId, out IEnumerable <string> groupNames) { bool isFollow = followRepository.IsFollowed(userId, toUserId); groupNames = null; if (isFollow) { FollowEntity followEntity = followRepository.Get(userId, toUserId); groupNames = categoryService.GetCategoriesOfItem(followEntity.Id, userId, TenantTypeIds.Instance().User()).Select(n => n.CategoryName); } return(isFollow); }
/// <summary> /// 判断是否关注了被判定用户 /// </summary> /// <param name="userId">用户Id</param> /// <param name="toUserId">被判定用户Id</param> /// <param name="isQuietly">是否去为悄悄关注</param> /// <returns>true-关注,false-没关注</returns> public bool IsFollowed(long userId, long toUserId, out bool isQuietly) { bool isFollow = followRepository.IsFollowed(userId, toUserId); isQuietly = false; if (isFollow) { FollowEntity follow = Get(userId, toUserId); isQuietly = follow != null ? follow.IsQuietly : isQuietly; } return(isFollow); }
/// <summary> /// 关注用户 /// </summary> /// <param name="userId">用户Id</param> /// <param name="followUserId">被关注用户Id</param> /// <param name="isQuietly">是否悄悄关注</param> public bool Follow(long userId, long followUserId, bool isQuietly = false) { FollowEntity follow = FollowEntity.New(); follow.UserId = userId; follow.FollowedUserId = followUserId; follow.IsQuietly = isQuietly; EventBus <FollowEntity> .Instance().OnBefore(follow, new CommonEventArgs(EventOperationType.Instance().Create())); bool isSuccess = followRepository.Follow(userId, followUserId, isQuietly); EventBus <FollowEntity> .Instance().OnAfter(follow, new CommonEventArgs(EventOperationType.Instance().Create())); return(isSuccess); }
/// <summary> /// 关注后更新缓存 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowUpdateCountModule_After(FollowEntity sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { //更新用户缓存 ICacheService cacheService = DIContainer.Resolve<ICacheService>(); RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(User)).RealTimeCacheHelper; if (cacheService.EnableDistributedCache) { realTimeCacheHelper.IncreaseEntityCacheVersion(sender.UserId); } else { string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(sender.UserId); User user = cacheService.Get<User>(cacheKey); if (user != null) { user.FollowedCount++; } } } }
/// <summary> /// 用户积分处理 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowPointModule_After(FollowEntity sender, CommonEventArgs eventArgs) { IUserService userservice = DIContainer.Resolve<IUserService>(); IUser followedUser = userservice.GetUser(sender.FollowedUserId); if (followedUser == null) { return; } string pointItemKey = string.Empty; PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_FollowUser"), followedUser.DisplayName); #region 设置积分项Key if (EventOperationType.Instance().Create() == eventArgs.EventOperationType) pointItemKey = PointItemKeys.Instance().FollowUser(); else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType) pointItemKey = PointItemKeys.Instance().CancelFollowUser(); #endregion pointService.GenerateByRole(sender.UserId, pointItemKey, description); }
/// <summary> /// 生成通知 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowNoticeModule_After(FollowEntity sender, CommonEventArgs eventArgs) { if (EventOperationType.Instance().Create() == eventArgs.EventOperationType) { if (sender.IsQuietly) return; IUserService userService = DIContainer.Resolve<IUserService>(); //关注用户 IUser user = userService.GetUser(sender.UserId); if (user == null) return; IUser followedUser = userService.GetUser(sender.FollowedUserId); if (followedUser == null) return; NoticeService service = new NoticeService(); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.TemplateName = "FollowUser"; notice.UserId = followedUser.UserId; notice.LeadingActorUserId = user.UserId; notice.LeadingActor = user.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(user.UserName)); notice.RelativeObjectId = followedUser.UserId; notice.RelativeObjectName = followedUser.DisplayName; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(followedUser.UserName)); service.Create(notice); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { NoticeService service = new NoticeService(); IEnumerable<Notice> notices = service.GetTops(sender.FollowedUserId, 20).Where(n => n.TemplateName == "FollowUser").Where(n => n.LeadingActorUserId == sender.UserId); foreach (var notice in notices) { service.Delete(notice.Id); } } }
/// <summary> /// 关注用户/取消关注动态处理 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowActivityEventModule_After(FollowEntity sender, CommonEventArgs eventArgs) { ActivityService activityService = new ActivityService(); if (EventOperationType.Instance().Create() == eventArgs.EventOperationType) { IUser user = DIContainer.Resolve<UserService>().GetUser(sender.UserId); if (user == null) return; Activity activity = Activity.New(); activity.ActivityItemKey = ActivityItemKeys.Instance().FollowUser(); activity.OwnerType = ActivityOwnerTypes.Instance().User(); activity.OwnerId = sender.UserId; activity.OwnerName = user.DisplayName; activity.UserId = sender.UserId; activity.ReferenceId = sender.FollowedUserId; activity.TenantTypeId = TenantTypeIds.Instance().User(); activityService.Generate(activity, false); activityService.TraceBackInboxAboutOwner(sender.UserId, sender.FollowedUserId, ActivityOwnerTypes.Instance().User()); } else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType) { activityService.RemoveInboxAboutOwner(sender.UserId, sender.FollowedUserId, ActivityOwnerTypes.Instance().User()); } }
/// <summary> /// 新建实体时使用 /// </summary> public static FollowEntity New() { FollowEntity followedUser = new FollowEntity() { NoteName = string.Empty, IsNewFollower = true, DateCreated = DateTime.UtcNow, LastContactDate = DateTime.UtcNow }; return followedUser; }