Skip to content

SocialPostsLoadedNotification

Published before posts are returned by IPostService.ListAsync or GetAsync (and so by the management API’s list and get). Remove items to hide them.

The following properties are available within the notification

Property Name Type Use
Items List<SocialPost> (see SocialPost) The posts about to be returned, each with its targets and their channels.
  • The edition’s history window has already been applied: posts it hides aren’t in Items.
  • Removing a post from Items hides it from lists and from single reads alike. A single read of a hidden post returns null (404 in the management API).
  • Changes are for what is returned. They are never stored, and the publisher never reads through this notification.
  • It runs on every list and read, so keep handlers cheap.
HideInternalPosts.cs
using UmbSocial.Core.Notifications;
using Umbraco.Cms.Core.Events;
public sealed class HideInternalPosts : INotificationAsyncHandler<SocialPostsLoadedNotification>
{
public Task HandleAsync(SocialPostsLoadedNotification notification, CancellationToken cancellationToken)
{
notification.Items.RemoveAll(post => post.Text.StartsWith("[internal]", StringComparison.Ordinal));
return Task.CompletedTask;
}
}