use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReporter method prepareEventReportBody.
/**
* Creates event report request body based on provided geofencing report.
*
* @param geoMessageStore message store for geo
* @param geoReports map that contains original signaling messages as keys and related geo reports as values.
* @return request body for geo reporting.
*/
@NonNull
private static EventReportBody prepareEventReportBody(Context context, MessageStore geoMessageStore, @NonNull GeoReport[] geoReports) {
Set<MessagePayload> messagePayloads = new HashSet<>();
Set<EventReport> eventReports = new HashSet<>();
List<Message> messages = geoMessageStore.findAll(context);
for (GeoReport r : geoReports) {
Message m = GeoReportHelper.getSignalingMessageForReport(messages, r);
if (m == null) {
MobileMessagingLogger.e("Cannot find signaling message for id: " + r.getSignalingMessageId());
continue;
}
messagePayloads.add(new MessagePayload(m.getMessageId(), m.getTitle(), m.getBody(), m.getSound(), m.isVibrate(), m.getCategory(), m.isSilent(), m.getCustomPayload() != null ? m.getCustomPayload().toString() : null, InternalDataMapper.createInternalDataBasedOnMessageContents(m)));
Long timestampDelta = Time.now() - r.getTimestampOccurred();
Long timestampDeltaSeconds = TimeUnit.MILLISECONDS.toSeconds(timestampDelta);
eventReports.add(new EventReport(EventType.valueOf(r.getEvent().name()), r.getArea().getId(), r.getCampaignId(), r.getSignalingMessageId(), r.getMessageId(), timestampDeltaSeconds));
}
String deviceInstanceId = MobileMessagingCore.getInstance(context).getPushRegistrationId();
return new EventReportBody(messagePayloads, eventReports, deviceInstanceId);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandler method handleTransition.
/**
* Handles geofencing intent and reports corresponding areas to server
*
* @param transition resolved transition information
*/
@SuppressWarnings("WeakerAccess")
public void handleTransition(GeoTransition transition) {
MobileMessagingLogger.v("GEO TRANSITION", transition);
Map<Message, List<Area>> messagesAndAreas = GeoReportHelper.findSignalingMessagesAndAreas(context, geoMessageStore, transition.getRequestIds(), transition.getEventType());
if (messagesAndAreas.isEmpty()) {
MobileMessagingLogger.d(TAG, "No messages for triggered areas");
return;
}
logGeofences(messagesAndAreas.values(), transition.getEventType());
geofencingHelper.addUnreportedGeoEvents(GeoReportHelper.createReportsForMultipleMessages(context, messagesAndAreas, transition.getEventType(), transition.getTriggeringLocation()));
GeoReport[] unreportedEvents = geofencingHelper.removeUnreportedGeoEvents();
if (unreportedEvents.length == 0) {
MobileMessagingLogger.d(TAG, "No geofencing events to report at current time");
return;
}
try {
GeoReportingResult result = geoReporter.reportSync(unreportedEvents);
handleReportingResultWithNewMessagesAndNotifications(unreportedEvents, result);
} catch (Exception e) {
MobileMessagingLogger.e(TAG, "Failed to report geo events " + e.toString());
handleGeoReportingResult(context, new GeoReportingResult(e));
}
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MessagesMapper method mapResponseToMessages.
static List<Message> mapResponseToMessages(List<MessageResponse> payloads) {
if (payloads == null)
return Collections.emptyList();
List<Message> messages = new ArrayList<>(payloads.size());
for (MessageResponse payload : payloads) {
if (payload == null) {
continue;
}
Message message = responseToMessage(payload);
messages.add(message);
}
return messages;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MessagesSynchronizer method sync.
public void sync() {
if (!mobileMessagingCore.isPushRegistrationEnabled()) {
return;
}
final String[] unreportedMessageIds = mobileMessagingCore.getAndRemoveUnreportedMessageIds();
new MRetryableTask<Void, List<Message>>() {
@Override
public List<Message> run(Void[] objects) {
if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
MobileMessagingLogger.w("Can't sync messages without valid registration");
throw InternalSdkError.NO_VALID_REGISTRATION.getException();
}
String[] messageIds = mobileMessagingCore.getSyncMessagesIds();
SyncMessagesBody syncMessagesBody = SyncMessagesBody.make(messageIds, unreportedMessageIds);
MobileMessagingLogger.v("SYNC MESSAGES >>>", syncMessagesBody);
SyncMessagesResponse syncMessagesResponse = mobileApiMessages.sync(syncMessagesBody);
MobileMessagingLogger.v("SYNC MESSAGES <<<", syncMessagesResponse);
return MessagesMapper.mapResponseToMessages(syncMessagesResponse.getPayloads());
}
@Override
public void after(List<Message> messages) {
broadcaster.deliveryReported(unreportedMessageIds);
if (messages == null || messages.isEmpty()) {
return;
}
for (Message message : messages) {
mobileMessageHandler.handleMessage(message);
}
}
@Override
public void error(Throwable error) {
mobileMessagingCore.addUnreportedMessageIds(unreportedMessageIds);
mobileMessagingCore.setLastHttpException(error);
MobileMessagingLogger.e("MobileMessaging API returned error (synchronizing messages)! ", error);
stats.reportError(MobileMessagingStatsError.SYNC_MESSAGES_ERROR);
if (!(error instanceof InternalSdkError.InternalSdkException)) {
broadcaster.error(MobileMessagingError.createFrom(error));
}
}
}.retryWith(retryPolicy).execute(executor);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MobileMessagingGcmIntentService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
String action = intent.getAction();
if (action == null) {
return;
}
switch(action) {
case ACTION_GCM_MESSAGE_RECEIVE:
Message message = FCMMessageMapper.fromCloudBundle(intent.getExtras());
MobileMessagingLogger.v("RECEIVED MESSAGE FROM FCM", message);
mobileMessageHandler().handleMessage(message);
break;
case ACTION_TOKEN_CLEANUP:
registrationTokenHandler.handleRegistrationTokenCleanup(this, intent.getStringExtra(EXTRA_GCM_SENDER_ID));
break;
case ACTION_ACQUIRE_INSTANCE_ID:
registrationTokenHandler.handleRegistrationTokenUpdate(this);
break;
case ACTION_FCM_MESSAGE_RECEIVE:
MobileMessagingLogger.v("Received message event from Firebase SDK, ignoring to avoid duplicate notifications");
break;
}
}
Aggregations