Exemple #1
0
        public void SaveComment(Comment comment, Post post)
        {
            CommunitySecurity.DemandPermissions(post, ASC.Blogs.Core.Constants.Action_AddComment);
            SaveComment(comment);

            var initiatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.UserID.ToString(), ""));

            try
            {
                NotifyClient.BeginSingleRecipientEvent("asc_blog_c");
                NotifyClient.AddInterceptor(initiatorInterceptor);

                List <ITagValue> tags = new List <ITagValue>
                {
                    new TagValue(ASC.Blogs.Core.Constants.TagPostSubject, post.Title),
                    new TagValue(ASC.Blogs.Core.Constants.TagPostPreview, post.GetPreviewText(500)),
                    new TagValue(ASC.Blogs.Core.Constants.TagUserName, DisplayUserSettings.GetFullUserName(comment.UserID)),
                    new TagValue(ASC.Blogs.Core.Constants.TagUserURL, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(comment.UserID, CommonLinkUtility.GetProductID()))),
                    new TagValue(ASC.Blogs.Core.Constants.TagDate, string.Format("{0:d} {0:t}", comment.Datetime)),
                    new TagValue(ASC.Blogs.Core.Constants.TagCommentBody, comment.Content),

                    new TagValue(ASC.Blogs.Core.Constants.TagURL, CommonLinkUtility.GetFullAbsolutePath(ASC.Blogs.Core.Constants.ViewBlogPageUrl + "?blogID=" + post.ID.ToString())),
                    new TagValue(ASC.Blogs.Core.Constants.TagCommentURL, CommonLinkUtility.GetFullAbsolutePath(ASC.Blogs.Core.Constants.ViewBlogPageUrl + "?blogID=" + post.ID.ToString() + "#" + comment.ID.ToString())),
                    GetReplyToTag(comment.ID, post)
                };

                NotifyClient.SendNoticeAsync(
                    ASC.Blogs.Core.Constants.NewComment,
                    post.ID.ToString(),
                    null,
                    tags.ToArray());

                NotifyClient.EndSingleRecipientEvent("asc_blog_c");
            }
            finally
            {
                NotifyClient.RemoveInterceptor(initiatorInterceptor.Name);
            }

            BlogUserActivityPublisher.AddComment(comment, post);

            ASC.Notify.Model.ISubscriptionProvider subscriptionProvider = NotifySource.GetSubscriptionProvider();

            if (!subscriptionProvider.IsUnsubscribe((IDirectRecipient)NotifySource.GetRecipientsProvider().
                                                    GetRecipient(SecurityContext.CurrentAccount.ID.ToString()), ASC.Blogs.Core.Constants.NewComment, post.ID.ToString()))
            {
                subscriptionProvider.Subscribe(
                    ASC.Blogs.Core.Constants.NewComment,
                    post.ID.ToString(),
                    NotifySource.GetRecipientsProvider().
                    GetRecipient(SecurityContext.CurrentAccount.ID.ToString())
                    );
            }
        }
Exemple #2
0
        public void SavePost(Post post, bool isNew, bool notifyComments)
        {
            if (isNew)
            {
                CommunitySecurity.DemandPermissions(
                    new PersonalBlogSecObject(CoreContext.UserManager.GetUsers(post.UserID)),
                    ASC.Blogs.Core.Constants.Action_AddPost);
            }
            else
            {
                CommunitySecurity.DemandPermissions(
                    new PersonalBlogSecObject(CoreContext.UserManager.GetUsers(post.UserID)),
                    Constants.Action_EditRemovePost);
            }

            _storage.GetPostDao().SavePost(post);
            if (isNew)
            {
                var initiatorInterceptor = new InitiatorInterceptor(new DirectRecipient(post.UserID.ToString(), ""));
                try
                {
                    NotifyClient.BeginSingleRecipientEvent("asc_blog");
                    NotifyClient.AddInterceptor(initiatorInterceptor);

                    List <ITagValue> tags = new List <ITagValue>
                    {
                        new TagValue(ASC.Blogs.Core.Constants.TagPostSubject, post.Title),
                        new TagValue(ASC.Blogs.Core.Constants.TagPostPreview,
                                     post.GetPreviewText(500)),
                        new TagValue(ASC.Blogs.Core.Constants.TagUserName,
                                     DisplayUserSettings.GetFullUserName(post.UserID)),
                        new TagValue(ASC.Blogs.Core.Constants.TagUserURL,
                                     CommonLinkUtility.GetFullAbsolutePath(
                                         CommonLinkUtility.GetUserProfile(post.UserID,
                                                                          CommonLinkUtility.GetProductID()))),
                        new TagValue(ASC.Blogs.Core.Constants.TagDate,
                                     string.Format("{0:d} {0:t}", post.Datetime)),
                        new TagValue(ASC.Blogs.Core.Constants.TagURL,
                                     CommonLinkUtility.GetFullAbsolutePath(
                                         ASC.Blogs.Core.Constants.ViewBlogPageUrl +
                                         "?blogid=" + post.ID.ToString())),
                        GetReplyToTag(Guid.Empty, post)
                    };

                    NotifyClient.SendNoticeAsync(
                        ASC.Blogs.Core.Constants.NewPost,
                        null,
                        null,
                        tags.ToArray());


                    NotifyClient.SendNoticeAsync(
                        ASC.Blogs.Core.Constants.NewPostByAuthor,
                        post.UserID.ToString(),
                        null,
                        tags.ToArray());

                    NotifyClient.EndSingleRecipientEvent("asc_blog");
                }
                finally
                {
                    NotifyClient.RemoveInterceptor(initiatorInterceptor.Name);
                }

                BlogUserActivityPublisher.AddPost(post); //TODO:
            }
            else
            {
                BlogUserActivityPublisher.EditPost(post, SecurityContext.CurrentAccount.ID);
            }
            if (notifyComments)
            {
                ASC.Notify.Model.ISubscriptionProvider subscriptionProvider = NotifySource.GetSubscriptionProvider();

                subscriptionProvider.Subscribe(
                    ASC.Blogs.Core.Constants.NewComment,
                    post.ID.ToString(),
                    NotifySource.GetRecipientsProvider().
                    GetRecipient(post.UserID.ToString())
                    );
            }
        }