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()]));
}
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()]));
}
Aggregations