public Comment GetCommentForEdit(int operatorID, int commentID) { if (ValidateUserID(operatorID) == false) { return(null); } if (commentID <= 0) { ThrowError(new InvalidParamError("commentID")); return(null); } Comment comment = CommentDao.Instance.GetComment(commentID); if (comment == null) { return(null); } if (CheckCommentEditPermission(operatorID, comment) == false) { return(null); } comment.Content = CommentUbbParser.ParseForEdit(comment.Content); return(comment); }
/// <summary> /// 评论编辑 /// </summary> /// <param name="commentID"></param> /// <param name="content"></param> /// <param name="type"></param> /// <returns></returns> public bool ModifyComment(int operatorUserID, int commentID, string content, CommentType type, out string newContent) { newContent = content; if (commentID <= 0) { ThrowError(new InvalidParamError("commentID")); return(false); } Comment comment = GetCommentByID(commentID); if (comment == null) { ThrowError <InvalidParamError>(new InvalidParamError("commentID")); return(false); } if (ValidateCommentEditPermission(operatorUserID, comment) == false) { return(false); } if (string.IsNullOrEmpty(content)) { Context.ThrowError(new EmptyCommentError("content")); return(false); } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } bool isApproved = true; string reverter, version; content = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords.Replace(content, out version, out reverter); string keyword = null; if (AllSettings.Current.ContentKeywordSettings.BannedKeywords.IsMatch(content, out keyword)) { Context.ThrowError(new KeywordBannedError("content", keyword)); return(false); } else if (AllSettings.Current.ContentKeywordSettings.ApprovedKeywords.IsMatch(content)) { isApproved = false; } content = CommentUbbParser.ParseForSave(content); if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int targetID; CommentDao.Instance.UpdateComment(commentID, operatorUserID, isApproved, content, reverter, out targetID); if (type == CommentType.Doing) { CacheUtil.RemoveBySearch("Doing/List/All"); } if (type == CommentType.Board) //更新留言所在用户缓存的数据而不是留言的用户! { CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, targetID, type)); } newContent = content; if (isApproved == false) { ThrowError <UnapprovedCommentError>(new UnapprovedCommentError()); return(false); } 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); }