Search in sources :

Example 11 with Notification

use of com.pratilipi.data.type.Notification in project pratilipi by Pratilipi.

the class NotificationDataUtil method sendFcm.

public static void sendFcm(Long notifId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Notification notif = dataAccessor.getNotification(notifId);
    if (!notif.isFcmPending())
        return;
    if (notif.getState() == NotificationState.UNREAD) {
        List<Notification> notifList = new ArrayList<>(1);
        notifList.add(notif);
        // TODO: Implement createNotificationData
        NotificationData notifData = createNotificationDataList(notifList, null, true).get(0);
        if (notifData.getMessage() != null) {
            // TODO: Cancel previously sent FCM if notifData.getMessage() == null
            List<String> fcmTokenList = dataAccessor.getFcmTokenList(notifData.getUserId());
            if (fcmTokenList.size() != 0) {
                String fcmResponse = FirebaseApi.sendCloudMessage2(fcmTokenList, notifData.getMessage(), // TODO: Remove Hack
                (((long) notifData.getId()) % Integer.MAX_VALUE) + "", notifData.getNotificationType().getAndroidHandler(), notifData.getSourceId(), notifData.getSourceImageUrl(), notifData.getDisplayImageUrl());
                if (notif.getFcmResponse() == null)
                    notif.setFcmResponse(fcmResponse);
                else
                    notif.setFcmResponse(notif.getFcmResponse() + "\n" + fcmResponse);
            }
        }
    }
    notif.setFcmPending(false);
    notif = dataAccessor.createOrUpdateNotification(notif);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Notification(com.pratilipi.data.type.Notification) NotificationData(com.pratilipi.data.client.NotificationData)

Aggregations

Notification (com.pratilipi.data.type.Notification)11 DataAccessor (com.pratilipi.data.DataAccessor)10 ArrayList (java.util.ArrayList)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)3 HashMap (java.util.HashMap)3 Gson (com.google.gson.Gson)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 NotificationData (com.pratilipi.data.client.NotificationData)2 LinkedList (java.util.LinkedList)2 TypeToken (com.google.gson.reflect.TypeToken)1 Get (com.pratilipi.api.annotation.Get)1 GenericResponse (com.pratilipi.api.shared.GenericResponse)1 Language (com.pratilipi.common.type.Language)1 NotificationState (com.pratilipi.common.type.NotificationState)1 NotificationType (com.pratilipi.common.type.NotificationType)1 Async (com.pratilipi.common.util.Async)1 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)1 DocAccessor (com.pratilipi.data.DocAccessor)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1