use of org.infobip.mobile.messaging.storage.MessageStore in project mobile-messaging-sdk-android by infobip.
the class SharedPreferencesMigrationTest method test_shouldMigrateAllMessagesToSqlite.
@Test
public void test_shouldMigrateAllMessagesToSqlite() throws Exception {
UUID uuid = UUID.randomUUID();
int numberOfMessages = 100;
JsonObject attachment = new JsonObject();
attachment.addProperty("url", "http://www.some-content.com.ru.hr");
JsonArray attachments = new JsonArray();
attachments.add(attachment);
JsonObject internalData = new JsonObject();
internalData.add("atts", attachments);
internalData.add("silent", new JsonObject());
for (int i = 0; i < numberOfMessages; i++) {
sharedPreferencesMessageStore.save(context, new Message(i + uuid.toString(), "SomeTitle" + i, "SomeBody" + i, "SomeSound" + i, true, "SomeIcon" + i, false, "SomeCategory" + i, "SomeFrom" + i, 0, 0, 0, null, internalData.toString(), "SomeDestination" + i, Message.Status.SUCCESS, "SomeStatusMessage" + i, "http://www.some-content.com.ru.hr"));
}
MessageStore store = new SQLiteMessageStore();
List<Message> messages = store.findAll(context);
HashMap<String, Message> map = new HashMap<>();
for (Message m : messages) map.put(m.getMessageId(), m);
// we are not removing messages from shared prefs
// in case user still uses SharedPreferencesMessageStore
Assert.assertEquals(numberOfMessages, sharedPreferencesMessageStore.findAll(context).size());
Assert.assertEquals(numberOfMessages, map.size());
for (int i = 0; i < numberOfMessages; i++) {
String id = i + uuid.toString();
Assert.assertEquals(id, map.get(id).getMessageId());
Assert.assertEquals("SomeTitle" + i, map.get(id).getTitle());
Assert.assertEquals("SomeBody" + i, map.get(id).getBody());
Assert.assertEquals("SomeSound" + i, map.get(id).getSound());
Assert.assertEquals(true, map.get(id).isVibrate());
Assert.assertEquals("SomeIcon" + i, map.get(id).getIcon());
Assert.assertEquals(false, map.get(id).isSilent());
Assert.assertEquals("SomeCategory" + i, map.get(id).getCategory());
Assert.assertEquals("SomeFrom" + i, map.get(id).getFrom());
Assert.assertEquals(0, map.get(id).getReceivedTimestamp());
Assert.assertEquals(0, map.get(id).getSeenTimestamp());
Assert.assertEquals(null, map.get(id).getCustomPayload());
JSONAssert.assertEquals(internalData.toString(), map.get(id).getInternalData(), false);
Assert.assertEquals("SomeDestination" + i, map.get(id).getDestination());
Assert.assertEquals(Message.Status.SUCCESS, map.get(id).getStatus());
Assert.assertEquals("SomeStatusMessage" + i, map.get(id).getStatusMessage());
Assert.assertEquals("http://www.some-content.com.ru.hr", map.get(id).getContentUrl());
}
}
use of org.infobip.mobile.messaging.storage.MessageStore in project mobile-messaging-sdk-android by infobip.
the class PushMessageHandler method handleGeoMessage.
public void handleGeoMessage(Context context, Message message) {
GeofencingHelper geofencingHelper = new GeofencingHelper(context);
MessageStore messageStoreForGeo = geofencingHelper.getMessageStoreForGeo();
try {
messageStoreForGeo.save(context, message);
GeofencingHelper.setAllActiveGeoAreasMonitored(context, false);
geofencingHelper.startGeoMonitoringIfNecessary();
} catch (Exception e) {
MobileMessagingLogger.e(TAG, InternalSdkError.ERROR_SAVING_MESSAGE.get(), e);
}
}
use of org.infobip.mobile.messaging.storage.MessageStore in project mobile-messaging-sdk-android by infobip.
the class MobileMessagingCore method updateStoredMessagesWithSeenStatus.
private void updateStoredMessagesWithSeenStatus(String[] messageIds) {
if (!isMessageStoreEnabled()) {
return;
}
MessageStore messageStore = getMessageStore();
List<String> messageIdList = Arrays.asList(messageIds);
for (Message m : new ArrayList<>(messageStore.findAll(context))) {
if (messageIdList.contains(m.getMessageId())) {
m.setSeenTimestamp(Time.now());
messageStore.save(context, m);
}
}
}
use of org.infobip.mobile.messaging.storage.MessageStore in project mobile-messaging-sdk-android by infobip.
the class ExpandableListAdapter method refreshDataSet.
private void refreshDataSet() {
MessageStore messageStore = MobileMessaging.getInstance(context).getMessageStore();
if (null == messageStore) {
this.messages = new ArrayList<>();
return;
}
this.messages = messageStore.findAll(context);
Collections.sort(messages);
}
use of org.infobip.mobile.messaging.storage.MessageStore in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
enableMessageStoreForReceivedMessages();
geoNotificationHelper = Mockito.mock(GeoNotificationHelper.class);
geoReporter = Mockito.mock(GeoReporter.class);
messageStore = Mockito.mock(MessageStore.class);
geoAreasHandler = new GeoAreasHandler(contextMock, mobileMessagingCore, geoNotificationHelper, geoReporter, new GeofencingHelper(context));
geoReportCaptor = ArgumentCaptor.forClass(GeoReport[].class);
geoNotificationCaptor = new ArgumentCaptor<>();
}
Aggregations