Search in sources :

Example 86 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class GeoAreasHandler method saveMessages.

/**
 * Saves new geo notification messages into message store.
 *
 * @param generatedMessages generated messages to save to message store.
 */
private void saveMessages(Collection<Message> generatedMessages) {
    if (!mobileMessagingCore.isMessageStoreEnabled()) {
        return;
    }
    MessageStore messageStore = mobileMessagingCore.getMessageStore();
    messageStore.save(context, generatedMessages.toArray(new Message[generatedMessages.size()]));
}
Also used : MessageStore(org.infobip.mobile.messaging.storage.MessageStore) Message(org.infobip.mobile.messaging.Message)

Example 87 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class GeoAreasHandler method updateMessageStoreWithReportingResult.

/**
 * Updates ids of existing messages based on reporting result.
 * </p> Does nothing if message store is not enabled.
 *
 * @param reportingResult geo reporting result that contains mapping for new message ids
 */
private static void updateMessageStoreWithReportingResult(Context context, @NonNull GeoReportingResult reportingResult) {
    if (reportingResult.getMessageIds() == null || reportingResult.getMessageIds().isEmpty()) {
        return;
    }
    MobileMessagingCore mobileMessagingCore = MobileMessagingCore.getInstance(context);
    if (!mobileMessagingCore.isMessageStoreEnabled()) {
        return;
    }
    MessageStore messageStore = mobileMessagingCore.getMessageStore();
    // Code below is far from being effective but messageId is primary key
    // so we will have to remove messages with invalid keys
    List<Message> allMessages = messageStore.findAll(context);
    Map<String, String> messageIds = reportingResult.getMessageIds();
    for (Message message : allMessages) {
        String newMessageId = messageIds.get(message.getMessageId());
        if (newMessageId == null) {
            continue;
        }
        message.setMessageId(newMessageId);
    }
    messageStore.deleteAll(context);
    messageStore.save(context, allMessages.toArray(new Message[allMessages.size()]));
}
Also used : MessageStore(org.infobip.mobile.messaging.storage.MessageStore) Message(org.infobip.mobile.messaging.Message) MobileMessagingCore(org.infobip.mobile.messaging.MobileMessagingCore)

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