Showing notifications
Notification
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:
-
Inject
AppContext
orSubAppContext
into your class so that you can access the messaging convenience methods.
Alternatively, usegetAppContext
orgetSubAppContext
inside your App or SubApp classes. If you extend theBaseSubApp
you always have access togetAppContext
andgetSubAppContext
. -
Create a new Message object. Pass the 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: