Search in sources :

Example 66 with Message

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);
}
Also used : MRetryableTask(org.infobip.mobile.messaging.mobile.common.MRetryableTask) Message(org.infobip.mobile.messaging.Message)

Example 67 with Message

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()]);
}
Also used : Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 68 with Message

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);
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle) NotificationSettings(org.infobip.mobile.messaging.NotificationSettings) Intent(android.content.Intent)

Example 69 with Message

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));
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 70 with Message

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));
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Aggregations

Message (org.infobip.mobile.messaging.Message)87 Test (org.junit.Test)44 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)10 Context (android.content.Context)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 JSONObject (org.json.JSONObject)7 List (java.util.List)6 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)6 Geo (org.infobip.mobile.messaging.geo.Geo)6 Map (java.util.Map)5 MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)5 Area (org.infobip.mobile.messaging.geo.Area)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Date (java.util.Date)4