Search in sources :

Example 6 with MessageStore

use of org.infobip.mobile.messaging.storage.MessageStore 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 7 with MessageStore

use of org.infobip.mobile.messaging.storage.MessageStore 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

MessageStore (org.infobip.mobile.messaging.storage.MessageStore)7 Message (org.infobip.mobile.messaging.Message)3 GeofencingHelper (org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 MobileMessagingCore (org.infobip.mobile.messaging.MobileMessagingCore)1 JsonArray (org.infobip.mobile.messaging.api.shaded.google.gson.JsonArray)1 JsonObject (org.infobip.mobile.messaging.api.shaded.google.gson.JsonObject)1 GeoReporter (org.infobip.mobile.messaging.geo.report.GeoReporter)1 GeoAreasHandler (org.infobip.mobile.messaging.geo.transition.GeoAreasHandler)1 GeoNotificationHelper (org.infobip.mobile.messaging.geo.transition.GeoNotificationHelper)1 SQLiteMessageStore (org.infobip.mobile.messaging.storage.SQLiteMessageStore)1 SharedPreferencesMessageStore (org.infobip.mobile.messaging.storage.SharedPreferencesMessageStore)1 Test (org.junit.Test)1