Wiki Application subscriptions

Hi ,

We had a requirement for wiki application subscription as forum subscription.And using core_v2_applicationSubscription Script API we are trying to create subscriptions which were working fine.

So users who subscribed to wikis should be notified when a new wiki page is created, and when a  comment is added to the wiki. 

1) Do we need to use the Wiki Page After Create Event and retrieve the list of subscribers and send the notification?

2) And for comment do we need to use COmment After Create Event retrieve the list and send the notification? 

And individual page notification should not be fired , so that user wont receive the duplicate notification .

Please let me know what would be the best apporoach .

 

  • You will typically need to handle the Create, Update and Delete events when creating notifications:

    Create - you only want to create the notification when the content is create if it has been published and approved

    Update - create the notifications here when the content is now approved.

    Delete - to clean up notifications if the associated content has been deleted.

    Here is how the current Wiki Page Comments Notification defines its events.

    		public void Initialize()
    		{
    			 Apis.Get<IComments>().Events.AfterCreate += Events_AfterCreate;
    			 Apis.Get<IComments>().Events.BeforeUpdate += Events_BeforeUpdate;
    			 Apis.Get<IComments>().Events.BeforeDelete += Events_BeforeDelete;
    		}
    
    		void Events_AfterCreate(CommentAfterCreateEventArgs e)
    		{
    			if (e.Content.ContentTypeId != ContentTypes.WikiPage || !e.IsApproved)
    				return;
    
                Apis.Get<IProcess>().Events.AfterComplete += (ProcessAfterCompleteEventArgs args) =>
                {
                    var comment =  Apis.Get<IComments>().Get(e.CommentId);
                    if (comment == null || !comment.IsApproved)
                        return;
    
                    CreateNotification(comment);
                };
    		}
    
    		void Events_BeforeUpdate(CommentBeforeUpdateEventArgs e)
    		{
    			if (e.Content.ContentTypeId != ContentTypes.WikiPage || !e.IsApproved)
    				return;
    
                var existingComment =  Apis.Get<IComments>().Get(e.CommentId);
                Apis.Get<IProcess>().Events.AfterComplete += (ProcessAfterCompleteEventArgs args) =>
                {
                    var comment =  Apis.Get<IComments>().Get(e.CommentId);
                    if (existingComment == null || existingComment.IsApproved == comment.IsApproved)
                        return;
    
                    if (comment.IsApproved)
                        CreateNotification(comment);
                    else
                        DeleteNotification(comment);
                };
    		}
    
    		void Events_BeforeDelete(CommentBeforeDeleteEventArgs e)
    		{
    			if (e.Content.ContentTypeId != ContentTypes.WikiPage || !e.IsApproved)
    				return;
    
                var comment =  Apis.Get<IComments>().Get(e.CommentId);
                if (comment == null)
                    return;
    
                DeleteNotification(comment);
    		}

    When you have multiple subscriptions that could send out a notification to the same user, you would be responsible to ensure that both notifications are not sent.  In this case, I would disable the out of the box Wiki Page Comments subscription and have your NotificationType handle both instances (user subscribed to the wiki or the wikipage).  The ContentSubscriptions API List method already has an option to IncludeApplicationSubscriptions in its call.  Using that will return both users subscribed to the content that was commented on and its parent application.