Skip to content

Post Presence Events

UmbSocial tells the composer who else has a post open with Umbraco’s backoffice server events (IServerEventRouter), not a channel of its own. Nothing is stored, and Umbraco carries the events between servers when the site is load balanced.

Umbraco’s server events carry only a source, a type and a key, so UmbSocial puts what happened and which post in the type, and who did it in the key:

Event source Event type Key
UmbSocial:Post Editing:{postKey} The key of the user who has the post open. Sent every 20 seconds while they do.
UmbSocial:Post Left:{postKey} The key of the user who closed the composer.
UmbSocial:Post Saved:{postKey} The key of the user who saved the post. Read the post again for its new version.

The constants are in UmbSocial.Core.Presence.SocialPostEvents. No post content is sent.

SocialPostEventAuthorizer (an IEventSourceAuthorizer) allows the UmbSocial:Post source for users with the View permission and nobody else.

Inject IPostPresence and call EditingAsync, LeftAsync or SavedAsync with the post’s key and the user’s key. A save made through IPostService already raises Saved for the signed-in backoffice user (from SocialPostSavedNotification); a save with nobody signed in, such as a job, raises nothing.

Observe the events from Umbraco’s server event context:

import { UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT } from "@umbraco-cms/backoffice/management-api";
this.consumeContext(UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT, (context) => {
this.observe(context?.events, (event) => {
if (event.eventSource !== "UmbSocial:Post") return;
const [what, postKey] = event.eventType.split(":");
// event.key is the user's key: look the name up with UmbUserItemRepository.
});
});