Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        public AssociatedInfo GetAssociatedInfo(long associateId, string tenantTypeId = "")
        {
            Comment comment = new CommentService().Get(associateId);

            if (comment != null && comment.User() != null)
            {
                ICommentUrlGetter commentUrlGetter = CommentUrlGetterFactory.Get(comment.TenantTypeId);
                CommentedObject   commentObject    = commentUrlGetter.GetCommentedObject(comment.CommentedObjectId);
                return(new AssociatedInfo()
                {
                    DetailUrl = commentUrlGetter.GetCommentDetailUrl(comment.CommentedObjectId, comment.Id, commentObject.UserId),
                    Subject = Tunynet.Utilities.HtmlUtility.TrimHtml(comment.Body, 12)
                });
            }

            return(null);
        }