/// <summary> /// 更新动态的私有状态 /// </summary> public void UpdatePrivateStatus(long activityId, bool isPrivate, bool isPublic = true) { //仅isPrivate发生变化才执行以下操作: //1、从false->true:参考Generate()中创建用户收件箱、站点收件箱 (注意不要让同一用户及站点收件箱的ActivityId重复) //2、从true->false:移除该ActivityId对应的用户收件箱(动态拥有者的收件箱除外)、站点收件箱; Activity activity = activityRepository.Get(activityId); if (activity == null) { return; } //若没有发生变化,则返回 if (isPrivate == activity.IsPrivate) { return; } activityRepository.UpdatePrivateStatus(activityId, isPrivate); if (isPrivate) { //保留动态操作者的收件箱 activityRepository.DeleteActivityFromUserInboxAndSiteInbox(activityId, activity.UserId); } else { //创建用户收件箱、站点收件箱 ActivityItem activityItem = GetActivityItem(activity.ActivityItemKey); if (activityItem == null) { return; } if (!activityItem.IsUserReceived) { return; } IActivityReceiverGetter receiverGetter = DIContainer.ResolveNamed <IActivityReceiverGetter>(activity.OwnerType.ToString()); IEnumerable <long> receiverUserIds = receiverGetter.GetReceiverUserIds(this, activity); activityRepository.InsertUserInboxs(activity.ActivityId, receiverUserIds); if (isPublic) { //推送给站点动态 if (activityItem.IsSiteReceived && activity.OwnerType == ActivityOwnerTypes.Instance().User()) { activityRepository.InsertSiteInbox(activity.ActivityId); } } } }