Exemplo n.º 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())
                    );
            }
        }
Exemplo n.º 2
0
        private void NotifyAlbumSave(Album currentAlbum, IEnumerable <AlbumItem> newItems)
        {
            var initiatorInterceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));

            try
            {
                NotifyClient.AddInterceptor(initiatorInterceptor);
                NotifyClient.BeginSingleRecipientEvent("photo uploaded");

                var albumUrl = UrlHelper.GetAbsoluteAlbumUrl(currentAlbum.Id);
                var eventUrl = UrlHelper.GetAbsoluteEventUrl(currentAlbum.Event.Id);
                var userName = DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID);
                var userUrl  = CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID, ASC.Web.Community.Product.CommunityProduct.ID));

                NotifyClient.SendNoticeAsync(
                    PhotoConst.NewPhotoUploaded,
                    null,
                    null,
                    new[] {
                    new TagValue(PhotoConst.TagEventName, currentAlbum.Event.Name),
                    new TagValue(PhotoConst.TagUserName, userName),
                    new TagValue(PhotoConst.TagUserURL, userUrl),
                    new TagValue(PhotoConst.TagPhotoCount, newItems.Count()),
                    new TagValue(PhotoConst.TagDate, string.Format("{0:d} {0:t}", TenantUtil.DateTimeNow())),
                    new TagValue(PhotoConst.TagURL, albumUrl),
                    new TagValue(PhotoConst.TagEventUrl, eventUrl),
                    new TagValue("PHOTO_UPLOAD", true)
                });
            }
            finally
            {
                NotifyClient.EndSingleRecipientEvent("photo uploaded");
                NotifyClient.RemoveInterceptor(initiatorInterceptor.Name);
            }

            PhotoUserActivityPublisher.AddPhoto(currentAlbum, SecurityContext.CurrentAccount.ID, newItems.ToList());
        }
Exemplo n.º 3
0
        public void SavePost(Post post, bool isNew, bool notifyComments)
        {
            CommunitySecurity.DemandPermissions(
                new PersonalBlogSecObject(CoreContext.UserManager.GetUsers(post.UserID)),
                isNew ? Constants.Action_AddPost : 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);

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

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


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

                    NotifyClient.EndSingleRecipientEvent("asc_blog");
                }
                finally
                {
                    NotifyClient.RemoveInterceptor(initiatorInterceptor.Name);
                }
            }
            if (!notifyComments)
            {
                return;
            }

            var subscriptionProvider = NotifySource.GetSubscriptionProvider();

            subscriptionProvider.Subscribe(
                Constants.NewComment,
                post.ID.ToString(),
                NotifySource.GetRecipientsProvider().
                GetRecipient(post.UserID.ToString())
                );
        }
Exemplo n.º 4
0
        public void SaveComment(Comment comment, Post post)
        {
            CommunitySecurity.DemandPermissions(post, Constants.Action_AddComment);
            SaveComment(comment);

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

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

                var tags = new ITagValue[]
                {
                    new TagValue(Constants.TagPostSubject, post.Title),
                    new TagValue(Constants.TagPostPreview, post.GetPreviewText(500)),
                    new TagValue(Constants.TagUserName, DisplayUserSettings.GetFullUserName(comment.UserID)),
                    new TagValue(Constants.TagUserURL, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(comment.UserID))),
                    new TagValue(Constants.TagDate, string.Format("{0:d} {0:t}", comment.Datetime)),
                    new TagValue(Constants.TagCommentBody, comment.Content),
                    new TagValue(Constants.TagURL, CommonLinkUtility.GetFullAbsolutePath(Constants.ViewBlogPageUrl + "?blogid=" + post.ID.ToString())),
                    new TagValue(Constants.TagCommentURL, CommonLinkUtility.GetFullAbsolutePath(Constants.ViewBlogPageUrl + "?blogid=" + post.ID.ToString() + "#container_" + comment.ID.ToString()))
                };

                var mentionedUsers   = MentionProvider.GetMentionedUsers(comment.Content);
                var mentionedUserIds = mentionedUsers.Select(u => u.ID.ToString());

                var provider = _notifySource.GetSubscriptionProvider();

                var objectID = post.ID.ToString();

                var recipients = provider
                                 .GetRecipients(Constants.NewComment, objectID)
                                 .Where(r => !mentionedUserIds.Contains(r.ID))
                                 .ToArray();

                NotifyClient.SendNoticeToAsync(Constants.NewComment, objectID, recipients, false, tags);

                if (mentionedUsers.Length > 0)
                {
                    NotifyClient.SendNoticeToAsync(Constants.MentionForPostComment, objectID, mentionedUsers, false, tags);
                }

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

            var subscriptionProvider = NotifySource.GetSubscriptionProvider();

            if (!subscriptionProvider.IsUnsubscribe((IDirectRecipient)NotifySource.GetRecipientsProvider().
                                                    GetRecipient(SecurityContext.CurrentAccount.ID.ToString()), Constants.NewComment, post.ID.ToString()))
            {
                subscriptionProvider.Subscribe(
                    Constants.NewComment,
                    post.ID.ToString(),
                    NotifySource.GetRecipientsProvider().
                    GetRecipient(SecurityContext.CurrentAccount.ID.ToString())
                    );
            }
        }