use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class FCMMessageMapper method fromCloudBundle.
/**
* De-serializes Push message from the Bundle we receive from GCM/FCM
*
* @param bundle data from the intent
* @return deserialized message
*/
public static Message fromCloudBundle(Bundle bundle) {
if (bundle == null) {
return null;
}
boolean silent = "true".equals(bundle.getString(BundleField.SILENT.getKey()));
String messageId = bundle.getString(BundleField.MESSAGE_ID.getKey());
String icon = bundle.getString(BundleField.ICON.getKey());
String from = bundle.getString(BundleField.FROM.getKey());
long receivedTs = bundle.getLong(BundleField.RECEIVED_TIMESTAMP.getKey());
long seenTs = bundle.getLong(BundleField.SEEN_TIMESTAMP.getKey());
JSONObject customPayload = getJSON(bundle, BundleField.CUSTOM_PAYLOAD.getKey());
String internalDataJson = bundle.getString(BundleField.INTERNAL_DATA.getKey());
boolean vibrate = silent ? InternalDataMapper.getInternalDataVibrate(internalDataJson, true) : "true".equals(bundle.getString(BundleField.VIBRATE.getKey(), "true"));
String title = silent ? InternalDataMapper.getInternalDataTitle(internalDataJson) : bundle.getString(BundleField.TITLE.getKey());
String body = silent ? InternalDataMapper.getInternalDataBody(internalDataJson) : bundle.getString(BundleField.BODY.getKey());
String sound = silent ? InternalDataMapper.getInternalDataSound(internalDataJson) : bundle.getString(BundleField.SOUND2.getKey(), bundle.getString(BundleField.SOUND.getKey()));
String category = silent ? InternalDataMapper.getInternalDataCategory(internalDataJson) : bundle.getString(BundleField.CATEGORY.getKey());
String contentUrl = InternalDataMapper.getInternalDataContentUrl(internalDataJson);
long sentDateTime = InternalDataMapper.getInternalDataSendDateTime(internalDataJson);
String destination = bundle.getString(BundleField.DESTINATION.getKey());
String statusMessage = bundle.getString(BundleField.STATUS_MESSAGE.getKey());
Message.Status status = Message.Status.UNKNOWN;
try {
status = Message.Status.valueOf(bundle.getString(BundleField.STATUS.getKey()));
} catch (Exception ignored) {
}
return new Message(messageId, title, body, sound, vibrate, icon, silent, category, from, receivedTs, seenTs, sentDateTime, customPayload, internalDataJson, destination, status, statusMessage, contentUrl);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class SharedPreferencesMigrator method migrateMessages.
static void migrateMessages(Context context, SQLiteDatabase db) {
SharedPreferencesMessageStore sharedPreferencesMessageStore = new SharedPreferencesMessageStore();
List<Message> messages = sharedPreferencesMessageStore.findAll(context);
if (messages.isEmpty()) {
return;
}
for (Message message : messages) {
db.insert(SqliteMessage.getTable(), null, SqliteMessage.save(message));
}
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MessagesMapper method responseToMessage.
private static Message responseToMessage(MessageResponse response) {
JSONObject customPayload = null;
try {
customPayload = response.getCustomPayload() != null ? new JSONObject(response.getCustomPayload()) : null;
} catch (JSONException e) {
e.printStackTrace();
}
Message message = new Message(response.getMessageId(), response.getTitle(), response.getBody(), response.getSound(), !"false".equals(response.getVibrate()), null, "true".equals(response.getSilent()), response.getCategory(), null, Time.now(), 0, InternalDataMapper.getInternalDataSendDateTime(response.getInternalData()), customPayload, response.getInternalData(), null, Message.Status.UNKNOWN, null, InternalDataMapper.getInternalDataContentUrl(response.getInternalData()));
InternalDataMapper.updateMessageWithInternalData(message, response.getInternalData());
return message;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MoMessageMapper method body.
static MoMessagesBody body(String pushRegistrationId, Message[] messages) {
List<MoMessage> moMessages = new ArrayList<>();
for (Message message : messages) {
String customPayloadString = message.getCustomPayload() != null ? message.getCustomPayload().toString() : null;
Map customPayloadMap = serializer.deserialize(customPayloadString, Map.class);
String internalData = message.getInternalData();
moMessages.add(new MoMessage(message.getMessageId(), message.getDestination(), message.getBody(), InternalDataMapper.getInternalDataInitialMessageId(internalData), InternalDataMapper.getInternalDataBulkId(internalData), customPayloadMap));
}
MoMessagesBody moMessagesBody = new MoMessagesBody();
moMessagesBody.setFrom(pushRegistrationId);
moMessagesBody.setMessages(moMessages.toArray(new MoMessage[moMessages.size()]));
return moMessagesBody;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MoMessageMapper method messages.
static Message[] messages(MoMessagesResponse response) {
if (response == null || response.getMessages() == null || response.getMessages().length == 0) {
return new Message[0];
}
List<Message> messages = new ArrayList<>(response.getMessages().length);
for (MoMessageDelivery delivery : response.getMessages()) {
Message message = new Message();
message.setMessageId(delivery.getMessageId());
message.setDestination(delivery.getDestination());
message.setBody(delivery.getText());
message.setStatusMessage(delivery.getStatus());
message.setReceivedTimestamp(Time.now());
message.setSeenTimestamp(Time.now());
message.setCustomPayload(delivery.getCustomPayload() != null ? new JSONObject(delivery.getCustomPayload()) : null);
Message.Status status = Message.Status.UNKNOWN;
int statusCode = delivery.getStatusCode();
if (statusCode < Message.Status.values().length) {
status = Message.Status.values()[statusCode];
} else {
MobileMessagingLogger.e(delivery.getMessageId() + ":Unexpected status code: " + statusCode);
}
message.setStatus(status);
messages.add(message);
}
return messages.toArray(new Message[messages.size()]);
}
Aggregations