/// <summary> /// 添加记录 /// </summary> /// <param name="operatorID">操作者ID</param> /// <param name="operatorIP">操作者IP</param> /// <param name="content">记录内容</param> /// <returns></returns> public bool CreateDoing(int operatorID, string operatorIP, string content) { bool validated = ValidateUserID(operatorID) && ValidateUsePermission <NoPermissionUseDoingError>(operatorID) && ValidateDoingContent(content); if (validated == false) { return(validated); } //content = UbbUtil.UbbToHtml(content , ParserType.Simple); int todayCount = DoingDao.Instance.GetTodayPostDoingCount(operatorID, DateTimeUtil.Now.Date); int maxCount = AllSettings.Current.DoingSettings.EveryDayPostLimit.GetValue(operatorID); if (maxCount > 0 && todayCount >= maxCount) { ThrowError(new DoingPostCountLimitedError(maxCount)); return(false); } int doingID = 0; bool succeed = DoingPointAction.Instance.UpdateUserPoint(operatorID, DoingPointType.PostDoing, delegate(PointActionManager.TryUpdateUserPointState state) { if (state != PointActionManager.TryUpdateUserPointState.CheckSucceed) { return(false); } DoingDao.Instance.AddDoing(operatorID, operatorIP, content, out doingID); return(true); }); KeywordReplaceRegulation keywordReg = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords; content = keywordReg.Replace(content); FeedBO.Instance.CreateUpdateDoingFeed(operatorID, doingID, content); User user = UserBO.Instance.GetUserFromCache(operatorID); if (user != null) { user.Doing = content; user.DoingDate = DateTimeUtil.Now; } ClearCachedEveryoneData(); ClearCachedUserData(operatorID); #if !Passport if (Globals.PassportClient.EnablePassport) { try { Globals.PassportClient.PassportService.User_UpdateDoing(user.UserID, content); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); } } #endif return(true); }
/// <summary> /// 添加评论 并更新缓存 /// </summary> /// <param name="userID">评论者ID</param> /// <param name="targetID">被评论的记录、日志、相册的ID</param> /// <param name="commentID">被评论的评论ID</param> /// <param name="type">评论类型 记录、日志、相册</param> /// <param name="content"></param> /// <param name="createIP"></param> /// <returns></returns> public bool AddComment(AuthUser operatorUser, int targetID, int commentID, CommentType type, string content, string createIP, bool isReply, int replyTargetUserID, out int newCommentId, out string newCommentContent) { Notify notify; newCommentId = 0; newCommentContent = string.Empty; if (Permission.Can(operatorUser, SpacePermissionSet.Action.AddComment) == false) { ThrowError <NoPermissionAddCommentError>(new NoPermissionAddCommentError()); return(false); } if (targetID < 0) { ThrowError(new InvalidParamError("targetID")); return(false); } if (commentID < 0) { ThrowError(new InvalidParamError("commentID")); return(false); } if (string.IsNullOrEmpty(content)) { ThrowError(new EmptyCommentError("content")); return(false); } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int commentTargetUserID = GetCommentTargetUserID(targetID, type); if (FriendBO.Instance.MyInBlacklist(operatorUser.UserID, commentTargetUserID)) { ThrowError(new PrivacyError()); return(false); } bool isApproved = true; //string reverter, version; //content = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords.Replace(content, out version, out reverter); CommentPointType commentPointType = CommentPointType.AddApprovedComment; KeywordReplaceRegulation keywordReg = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords; content = keywordReg.Replace(content); string keyword = null; if (AllSettings.Current.ContentKeywordSettings.BannedKeywords.IsMatch(content, out keyword)) { Context.ThrowError(new KeywordBannedError("content", keyword)); return(false); } if (AllSettings.Current.ContentKeywordSettings.ApprovedKeywords.IsMatch(content)) { isApproved = false; commentPointType = CommentPointType.AddNoApprovedComment; } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int targetUserID = 0; int tempCommentID = 0; content = CommentUbbParser.ParseForSave(content); newCommentContent = content; bool success = CommentPointAction.Instance.UpdateUserPoint(operatorUser.UserID, commentPointType, delegate(PointActionManager.TryUpdateUserPointState state) { if (state != PointActionManager.TryUpdateUserPointState.CheckSucceed) { return(false); } else { //添加评论并发送动态与通知 switch (type) { case CommentType.Board: SimpleUser user = UserBO.Instance.GetSimpleUser(targetID); if (user == null) { ThrowError(new UserNotExistsError("targetID", targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); FeedBO.Instance.CreateLeveMessageFeed(operatorUser.UserID, targetID); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new BoardCommentNotify(operatorUser.UserID, tempCommentID, isReply, targetID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (targetID != operatorUser.UserID) { notify = new BoardCommentNotify(operatorUser.UserID, tempCommentID, false, targetID); notify.UserID = targetID; NotifyBO.Instance.AddNotify(operatorUser, notify); } CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, targetID, type)); break; case CommentType.Blog: BlogArticle article = BlogBO.Instance.GetBlogArticle(targetID); if (article == null) { ThrowError(new NotExistsAlbumError(targetID)); return(false); } if (!article.EnableComment) { ThrowError(new PrivacyError()); return(false); } else { if (article.UserID != operatorUser.UserID) //如果不是作者评论自己的 给作者加积分 { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); success = BlogPointAction.Instance.UpdateUserPoint(article.UserID, BlogPointType.ArticleWasCommented); if (success == false) { return(false); } } else { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); } } FeedBO.Instance.CreatBlogCommentFeed(operatorUser.UserID, article.UserID, targetID, article.Subject); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new BlogCommentNotify(operatorUser.UserID, article.Subject, targetID, tempCommentID, isReply, article.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (article.UserID != operatorUser.UserID) { notify = new BlogCommentNotify(operatorUser.UserID, article.Subject, targetID, tempCommentID, false, article.UserID); notify.UserID = article.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; case CommentType.Doing: Doing doing = DoingBO.Instance.GetDoing(targetID); if (doing == null) { ThrowError(new NotExistsDoingError(targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new DoingPostNotify(operatorUser.UserID, doing.Content, doing.ID, tempCommentID, isReply, doing.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (doing.UserID != operatorUser.UserID) { notify = new DoingPostNotify(operatorUser.UserID, doing.Content, doing.ID, tempCommentID, false, doing.UserID); notify.UserID = doing.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } DoingBO.Instance.ClearCachedEveryoneData(); break; case CommentType.Share: Share share = ShareBO.Instance.GetUserShare(targetID); if (share == null) { ThrowError(new NotExistsShareError(targetID)); return(false); } if (share.UserID != operatorUser.UserID) //如果不是分享作者评论自己的分享 给分享作者加积分 { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); success = SharePointAction.Instance.UpdateUserPoint(share.UserID, SharePointType.ShareWasCommeted); if (!success) { return(false); } } else { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); } ShareBO.Instance.ClearCachedEveryoneData(); FeedBO.Instance.CreatShareCommentFeed(operatorUser.UserID, share.UserID, targetID, share.Type); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new SharePostNotify(operatorUser.UserID, targetID, tempCommentID, isReply, share.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (share.UserID != operatorUser.UserID) { notify = new SharePostNotify(operatorUser.UserID, targetID, tempCommentID, false, share.UserID); notify.UserID = share.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; case CommentType.Photo: Photo photo = AlbumBO.Instance.GetPhoto(targetID); if (photo == null) { ThrowError(new NotExistsPhotoError(targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); FeedBO.Instance.CreatPictureCommentFeed(operatorUser.UserID, targetUserID, targetID, photo.ThumbSrc, photo.Name, content); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new PhotoCommentNotify(operatorUser.UserID, targetID, photo.Name, tempCommentID, isReply, photo.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (photo.UserID != operatorUser.UserID) { notify = new PhotoCommentNotify(operatorUser.UserID, targetID, photo.Name, tempCommentID, false, photo.UserID); notify.UserID = photo.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; } return(true); } }); if (success == false) { return(false); } newCommentId = tempCommentID; //更新热度 if (targetUserID != 0) { HotType hotType = HotType.Comment; if (type == CommentType.Board) { hotType = HotType.Messag; } FriendBO.Instance.UpdateFriendHot(operatorUser.UserID, hotType, targetUserID); } if (isApproved == false) { Context.ThrowError(new UnapprovedCommentError()); return(false); } return(true); }