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);
}
Aggregations