Пример #1
0
        /// <summary>
        /// 创建评论
        /// </summary>
        /// <param name="comment">待创建评论</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool Create(Comment comment)
        {
            //触发事件
            EventBus<Comment>.Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Create()));
            AuditService auditService = new AuditService();
            auditService.ChangeAuditStatusForCreate(comment.UserId, comment);

            //评论创建
            long commentId = Convert.ToInt64(commentRepository.Insert(comment));

            //更新父级ChildCount
            if (commentId > 0)
            {

                ICommentBodyProcessor commentBodyProcessor = DIContainer.Resolve<ICommentBodyProcessor>();
                comment.Body = commentBodyProcessor.Process(comment.Body, TenantTypeIds.Instance().Comment(), commentId, comment.UserId);
                commentRepository.Update(comment);

                commentRepository.UpdateChildCount(comment.ParentId, false);
                CountService countService = new CountService(comment.TenantTypeId);
                countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, 1, true);
                //触发事件
                EventBus<Comment>.Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<Comment, AuditEventArgs>.Instance().OnAfter(comment, new AuditEventArgs(null, comment.AuditStatus));

            }

            return commentId > 0;
        }
Пример #2
0
        /// <summary>
        /// 通知处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void CommentNoticeEventModule_After(Comment sender, AuditEventArgs eventArgs)
        {
            AuditService auditService = new AuditService();
            bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);
            if (auditDirection == true)
            {
                var urlGetter = CommentUrlGetterFactory.Get(sender.TenantTypeId);
                var commentedObject = urlGetter.GetCommentedObject(sender.CommentedObjectId);
                var senderUser = sender.User();
                if (urlGetter == null || commentedObject == null)
                    return;
                //日志有新评论时,自动通知原作者
                var toUserIds = new List<long>();
                //评论相关的atuserid
                List<long> userids = new AtUserService(TenantTypeIds.Instance().Comment()).GetAtUserIds(sender.Id);

                if (!userids.Contains(commentedObject.UserId))
                {
                    toUserIds.Add(commentedObject.UserId);
                }

                if (sender.ParentId > 0 && !userids.Contains(sender.ToUserId))
                {
                    toUserIds.Add(sender.ToUserId);
                }

                foreach (var toUserId in toUserIds)
                {
                    //通知的对象排除掉自己
                    if (toUserId == sender.UserId)
                    {
                        continue;
                    }

                    Notice notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = 0;
                    notice.TypeId = NoticeTypeIds.Instance().Reply();
                    notice.LeadingActor = senderUser != null ? senderUser.DisplayName : "匿名用户";
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserIdToUserNameDictionary.GetUserName(sender.UserId)));

                    notice.RelativeObjectName =StringUtility.Trim(commentedObject.Name, 60);
                    notice.RelativeObjectId = sender.Id;
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(urlGetter.GetCommentDetailUrl(sender.CommentedObjectId, sender.Id, commentedObject.UserId)) ?? string.Empty;
                    notice.TemplateName = sender.ParentId > 0 ? NoticeTemplateNames.Instance().NewReply() : NoticeTemplateNames.Instance().NewComment();
                    new NoticeService().Create(notice);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 评论的积分处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void CommentCreatAndDeleteEventModel_After(Comment sender, CommonEventArgs eventArgs)
        {
            PointService pointService = new PointService();
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_CreateComment"), sender.Author, sender.Subject);
                pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().CreateComment(), description, true);
            }

            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_DeleteComment"), sender.Author, sender.Subject);
                pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().DeleteComment(), description, true);
            }
        }
Пример #4
0
        /// <summary>
        /// 评论日志动态处理程序
        /// </summary>
        /// <param name="comment"></param>
        /// <param name="eventArgs"></param>
        private void BlogCommentActivityEventModule_After(Comment comment, AuditEventArgs eventArgs)
        {
            NoticeService noticeService = new NoticeService();
            BlogThread blogThread = null;

            if (comment.TenantTypeId == TenantTypeIds.Instance().BlogThread())
            {
                //生成动态
                ActivityService activityService = new ActivityService();
                AuditService auditService = new AuditService();
                bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);
                if (auditDirection == true)
                {
                    //创建评论的动态[关注评论者的粉丝可以看到该评论]
                    Activity activity = Activity.New();
                    activity.ActivityItemKey = ActivityItemKeys.Instance().CreateBlogComment();
                    activity.ApplicationId = BlogConfig.Instance().ApplicationId;

                    BlogService blogService = new BlogService();
                    blogThread = blogService.Get(comment.CommentedObjectId);
                    if (blogThread == null || blogThread.UserId == comment.UserId)
                    {
                        return;
                    }
                    activity.IsOriginalThread = true;
                    activity.IsPrivate = false;
                    activity.OwnerId = comment.UserId;
                    activity.OwnerName = comment.Author;
                    activity.OwnerType = ActivityOwnerTypes.Instance().User();
                    activity.ReferenceId = blogThread.ThreadId;
                    activity.ReferenceTenantTypeId = TenantTypeIds.Instance().BlogThread();
                    activity.SourceId = comment.Id;
                    activity.TenantTypeId = TenantTypeIds.Instance().Comment();
                    activity.UserId = comment.UserId;

                    //是否是公开的(用于是否推送站点动态)
                    bool isPublic = blogThread.PrivacyStatus == PrivacyStatus.Public ? true : false;
                    activityService.Generate(activity, false, isPublic);

                    //创建评论的动态[关注该日志的用户可以看到该评论]
                    Activity activityOfBlogComment = Activity.New();
                    activityOfBlogComment.ActivityItemKey = activity.ActivityItemKey;
                    activityOfBlogComment.ApplicationId = activity.ApplicationId;
                    activityOfBlogComment.IsOriginalThread = activity.IsOriginalThread;
                    activityOfBlogComment.IsPrivate = activity.IsPrivate;
                    activityOfBlogComment.ReferenceId = activity.ReferenceId;
                    activityOfBlogComment.ReferenceTenantTypeId = activity.ReferenceTenantTypeId;
                    activityOfBlogComment.SourceId = activity.SourceId;
                    activityOfBlogComment.TenantTypeId = activity.TenantTypeId;
                    activityOfBlogComment.UserId = activity.UserId;

                    activityOfBlogComment.OwnerId = blogThread.ThreadId;
                    activityOfBlogComment.OwnerName = blogThread.ResolvedSubject;
                    activityOfBlogComment.OwnerType = ActivityOwnerTypes.Instance().Blog();

                    activityService.Generate(activityOfBlogComment, false, isPublic);
                }
                else if (auditDirection == false)
                {
                    activityService.DeleteSource(TenantTypeIds.Instance().Comment(), comment.Id);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 新建实体时使用
 /// </summary>
 public static Comment New()
 {
     Comment comment = new Comment()
     {
         Author = string.Empty,
         ToUserDisplayName = string.Empty,
         Subject = string.Empty,
         IP = WebUtility.GetIP(),
         DateCreated = DateTime.UtcNow
     };
     return comment;
 }
Пример #6
0
        /// <summary>
        /// 是否有权限查看评论
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public bool Comment_Show(Comment comment)
        {
            if (!comment.IsPrivate)
                return true;
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            if (comment.OwnerId == currentUser.UserId && comment.ParentId == 0)
                return true;

            if (comment.ToUserId != 0 && comment.ToUserId == currentUser.UserId)
                return true;
            if (comment.UserId == currentUser.UserId)
                return true;
            TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId);
            if (tenantType == null)
                return false;
            if (IsAdministrator(tenantType.ApplicationId))
                return true;
            if (AuthorizationService.IsTenantManager(currentUser, comment.TenantTypeId, comment.OwnerId))
                return true;
            return false;
        }
Пример #7
0
 /// <summary>
 /// 是否具有推荐评论的权限
 /// </summary>        
 /// <returns></returns>
 public bool Comment_Recommend(Comment comment)
 {
     IUser currentUser = UserContext.CurrentUser;
     if (currentUser == null)
         return false;
     TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId);
     if (tenantType == null)
         return false;
     if (IsAdministrator(tenantType.ApplicationId))
         return true;
     return false;
 }
Пример #8
0
 /// <summary>
 /// 是否具有删除评论的权限
 /// </summary>        
 /// <returns></returns>
 public bool Comment_Delete(Comment comment)
 {
     IUser currentUser = UserContext.CurrentUser;
     if (currentUser == null)
         return false;
     TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId);
     if (tenantType == null)
         return false;
     if (IsAdministrator(tenantType.ApplicationId))
         return true;
     if (AuthorizationService.IsOwner(currentUser, comment.UserId, comment.OwnerId))
         return true;
     if (AuthorizationService.IsTenantManager(currentUser, comment.TenantTypeId, comment.OwnerId))
         return true;
     return false;
 }
Пример #9
0
 public void Update(Comment comment)
 {
     commentRepository.Update(comment);
 }
Пример #10
0
 public void Update(Comment comment)
 {
     commentRepository.Update(comment);
 }