RE: Notifications in Liferay with no need to refresh or send any request.

Olaf Kock, modified 2 Years ago. New Member Posts: 3 Join Date: 6/30/23 Recent Posts

I was trying to send a notification to the user after he has succesfully done an action, using:

NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent(System.currentTimeMillis(), "com_liferay_document_library_web_portlet_DLPortlet", notificationEventJSONObject);
notificationEvent.setDeliveryType(10002);
List<User> allUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS,QueryUtil.ALL_POS);
try {
    for (User u : allUsers) {
        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(u.getUserId(), notificationEvent);
    }
} catch (PortalException e) {
    logger.error("Error occured during sending the portal notification to user", e);
}

This works as expected, however this notifications pop up in the receiver user after doing a request (eg, refrteshing the page). Is there a better way to inform users of something in Liferay without the need of them to refresh the page like a sort of push from server to the websocket?

PD: Moreoever I was wondering where can I consult the different available delivery types for the notification events.

Thank you very much in advance!

Alla Sapozhnikova, modified 1 Year ago. Junior Member Posts: 82 Join Date: 3/2/12 Recent Posts

Hi there, 

 

This is not an answer, just a follow-up. I am trying to do a similar thing. Did you figure out how to accoplish this task? Does anyone know how Liferay 7.2 or &.4 supports web push notifications? 

 

Thank you for any suggestions.

Alla

Jamie Sammons, modified 1 Year ago. New Member Posts: 3 Join Date: 6/30/23 Recent Posts

See this. We followed that combined with some javascript and AUI for the notification to appear when onMessage triggers. 

Jamie Sammons, modified 1 Year ago. New Member Posts: 3 Join Date: 6/30/23 Recent Posts

We ended up using the contents of this article to solve the issue.