/// <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); } //检查用户是否接收该动态项目 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); } } }
/// <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); } } }
/// <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; } }
/// <summary> /// 屏蔽群组 /// </summary> /// <param name="spaceKey">空间名</param> /// <returns>屏蔽群组名</returns> public ActionResult _BlockGroups(string spaceKey) { long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (UserContext.CurrentUser == null || (UserContext.CurrentUser.UserId != userId && authorizer.IsAdministrator(new TenantTypeService().Get(TenantTypeIds.Instance().Group()).ApplicationId))) return Content(string.Empty); IEnumerable<UserBlockedObject> blockedGroups = new UserBlockService().GetBlockedGroups(userId); List<UserBlockedObjectViewModel> blockedObjectes = new List<UserBlockedObjectViewModel>(); if (blockedGroups != null && blockedGroups.Count() > 0) { groupService.GetGroupEntitiesByIds(blockedGroups.Select(n => n.ObjectId)); foreach (var item in blockedGroups) { GroupEntity group = groupService.Get(item.ObjectId); if (group == null) continue; UserBlockedObjectViewModel entitiy = item.AsViewModel(); entitiy.Logo = group.Logo; blockedObjectes.Add(entitiy); } } return View(blockedObjectes); }
public ActionResult BlockGroups(string spaceKey, List<long> groupIds) { int addCount = 0; long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); UserBlockService service = new UserBlockService(); if (userId > 0 && groupIds != null && groupIds.Count > 0) foreach (var groupId in groupIds) { GroupEntity group = groupService.Get(groupId); if (group == null || service.IsBlockedGroup(userId, groupId)) continue; service.BlockGroup(userId, group.GroupId, group.GroupName); addCount++; } if (addCount > 0) TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, string.Format("成功添加{0}个群组添加到屏蔽列表", addCount)); else TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "没有任何群组被添加到屏蔽列表中"); return Redirect(SiteUrls.Instance().BlockGroups(spaceKey)); }
public ActionResult BlockTopics(string spaceKey, List<long> topicIds) { int addCount = 0; long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); UserBlockService service = new UserBlockService(); if (userId > 0 && topicIds != null && topicIds.Count > 0) foreach (var topicId in topicIds) { TopicEntity topic = topicService.Get(topicId); if (topic == null || service.IsBlockedTopic(userId, topicId)) continue; service.BlockTopic(userId, topic.TopicId, topic.TopicName); addCount++; } if (addCount > 0) TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, string.Format("成功添加{0}个专题添加到屏蔽列表", addCount)); else TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "没有任何专题被添加到屏蔽列表中"); return Redirect(SiteUrls.Instance().BlockGroups(spaceKey)); }