Notifications are banner-type messages that inform the user about system and app events. Notifications are displayed prominently at the top of the Magnolia UI. They capture the user's attention effectively but do not interrupt what the user is currently working on. Notifications are the only persistent message type. The user can safely close the notification banner and read the full message in the Notifications app later.

Showing a notification message in app code

To show a notification message:

  1. Inject AppContext or SubAppContext into your class so that you can access the messaging convenience methods. 
    Alternatively, use getAppContext or getSubAppContext inside your App or SubApp classes. If you extend the BaseSubApp you always have access to getAppContext and getSubAppContext.
  2. Create a new 
    $webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources") Message
    object. Pass the
    $webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources") MessageType
    only if you want to do your own message types.
@Inject
public MySubApp(SubAppContext subAppContext, MyView view) {
   super(subAppContext, view);
   view.setListener(this);
}
 
@Override
public void handleGroupMessage(final String group, final MessageType type, final String subject, final String message) {
   getAppContext().sendGroupMessage(group, new Message(type, subject, message));
}

Showing a notification to a named user

AppContext provides convenience methods for sending messages. The user will be notified instantly with a notification banner if they are currently signed in. In any case, the message is stored in the Notifications app.

void sendUserMessage(String user, Message message);

Showing a notification to all users in a group

The users in the group will be notified instantly with a notification banner if they are currently signed in. In any case, the message is stored in the Notifications app.

void sendGroupMessage(String group, Message message);

Showing a notification to the current user

The following code snippet does the same as shell.showNotification(messageText).

private void sendToCurrentUser(String messageText) {
   final Message message = new Message();
   message.setMessage(messageText);
   message.setType(MessageType.INFO);
   messagesManager.sendLocalMessage(message);
}

Broadcast a notification message to all users

The users will be notified instantly with a notification banner if they are currently signed in. In any case, the message will be stored in the Notifications app.

void broadcastMessage(Message message);

See MessagesMainSubapp.java for examples.

Sending a notification using the Messages app

The Messages app is a tool that allows you to send notifications to individual users, groups or all users. This app is only available to the superuser role by default, as configured in app launcher permissions.

The notification is then displayed in the Notifications app:

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))
  • No labels