use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MoMessageSender method send.
public void send(final MobileMessaging.ResultListener<Message[]> listener, Message... messages) {
new Task() {
@Override
public void after(Message[] messages) {
messageStoreWrapper.upsert(messages);
broadcaster.messagesSent(Arrays.asList(messages));
if (listener != null) {
listener.onResult(messages);
}
}
@Override
public void error(Message[] messages, Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (sending message)!");
stats.reportError(MobileMessagingStatsError.MESSAGE_SEND_ERROR);
broadcaster.error(MobileMessagingError.createFrom(error));
for (Message message : messages) {
message.setStatus(Message.Status.ERROR);
message.setStatusMessage(error.getMessage());
}
after(messages);
}
}.retryWith(noRetryPolicy).execute(executor, messages);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MoMessageSender method excludeOutdatedMessages.
private Message[] excludeOutdatedMessages(Message[] messages) {
if (messages.length == 0) {
return new Message[0];
}
Date now = new Date();
List<Message> relevantMessages = new ArrayList<>();
for (Message message : messages) {
long expirationTimestamp = message.getReceivedTimestamp() + MESSAGE_MAX_RETRY_LIFETIME;
if (expirationTimestamp < now.getTime()) {
continue;
}
relevantMessages.add(message);
}
return relevantMessages.toArray(new Message[relevantMessages.size()]);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class NotificationTapReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Bundle messageBundle = intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE);
Message message = Message.createFrom(messageBundle);
if (message == null) {
MobileMessagingLogger.e("Received no message in NotificationTapReceiver");
return;
}
broadcaster(context).notificationTapped(message);
NotificationSettings notificationSettings = mobileMessagingCore(context).getNotificationSettings();
if (notificationSettings == null) {
return;
}
if (notificationSettings.markSeenOnTap()) {
mobileMessagingCore(context).setMessagesSeen(message.getMessageId());
}
Class callbackActivity = notificationSettings.getCallbackActivity();
if (callbackActivity == null) {
MobileMessagingLogger.e("Callback activity is not set, cannot proceed");
return;
}
int intentFlags = intent.getIntExtra(MobileMessagingProperty.EXTRA_INTENT_FLAGS.getKey(), (Integer) MobileMessagingProperty.INTENT_FLAGS.getDefaultValue());
Intent callbackIntent = new Intent(context, callbackActivity);
callbackIntent.setAction(Event.NOTIFICATION_TAPPED.getKey());
callbackIntent.putExtra(BroadcastParameter.EXTRA_MESSAGE, messageBundle);
// FLAG_ACTIVITY_NEW_TASK has to be here
// because we're starting activity outside of activity context
callbackIntent.addFlags(intentFlags | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callbackIntent);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MobileMessageHandlerTest method test_shouldSaveGeoMessagesToGeoStore.
@Test
public void test_shouldSaveGeoMessagesToGeoStore() throws Exception {
// Given
Message message = createMessage(context, "SomeMessageId", "SomeCampaignId", false, createArea("SomeAreaId"));
// When
pushMessageHandler.handleGeoMessage(context, message);
// Then
List<Message> messages = geoStore.findAll(context);
assertEquals(1, messages.size());
Message message1 = messages.get(0);
Geo geo = GeoDataMapper.geoFromInternalData(message1.getInternalData());
assertNotNull(geo);
assertEquals("SomeMessageId", message1.getMessageId());
assertEquals("SomeCampaignId", geo.getCampaignId());
assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());
assertEquals(0, commonStore.countAll(context));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MobileMessageHandlerTest method test_shouldSaveNonGeoMessagesToCommonStore.
@Test
public void test_shouldSaveNonGeoMessagesToCommonStore() throws Exception {
// Given
Message message = createMessage(context, "SomeMessageId", null, false);
// When
mobileMessageHandler.handleMessage(message);
// Then
List<Message> messages = commonStore.findAll(context);
assertEquals(1, messages.size());
assertEquals("SomeMessageId", messages.get(0).getMessageId());
assertEquals(0, geoStore.countAll(context));
}
Aggregations