Search in sources :

Example 56 with Message

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

the class AndroidBroadcasterTest method test_should_send_mo_messages.

@Test
public void test_should_send_mo_messages() {
    // Given
    Message message = createMessage(context, "SomeMessageId", false);
    // When
    broadcastSender.messagesSent(Collections.singletonList(message));
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(Event.MESSAGES_SENT.getKey(), intent.getAction());
    List<Message> messagesAfter = Message.createFrom(intent.<Bundle>getParcelableArrayListExtra(BroadcastParameter.EXTRA_MESSAGES));
    assertEquals(1, messagesAfter.size());
    assertEquals("SomeMessageId", messagesAfter.get(0).getMessageId());
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

Example 57 with Message

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

the class MobileMessagingTestCase method createMessage.

/**
 * Generates messages with provided ids and geo campaign object
 *
 * @param saveToStorage set to true to save messages to message store
 * @param messageId     message id for a message
 * @return new message
 */
protected static Message createMessage(Context context, String messageId, boolean saveToStorage) {
    Message message = new Message();
    message.setMessageId(messageId);
    if (saveToStorage) {
        MobileMessagingCore.getInstance(context).getMessageStore().save(context, message);
    }
    return message;
}
Also used : Message(org.infobip.mobile.messaging.Message)

Example 58 with Message

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

the class GeoReportHelper method createMessagesToNotify.

/**
 * Creates new geo notification messages based on reporting result
 *
 * @param reportedEvents  events that were reported to server
 * @param reportingResult response from the server
 * @return map of messages and corresponding geo event types for each message
 */
public static Map<Message, GeoEventType> createMessagesToNotify(Context context, List<GeoReport> reportedEvents, @NonNull GeoReportingResult reportingResult) {
    GeofencingHelper geofencingHelper = new GeofencingHelper(context);
    List<Message> allMessages = geofencingHelper.getMessageStoreForGeo().findAll(context);
    Map<Message, GeoEventType> messages = new ArrayMap<>();
    for (GeoReport report : reportedEvents) {
        Message signalingMessage = GeoReportHelper.getSignalingMessageForReport(allMessages, report);
        if (signalingMessage == null) {
            MobileMessagingLogger.e("Cannot find signaling message for id: " + report.getSignalingMessageId());
            continue;
        }
        messages.put(createNewMessageForReport(report, reportingResult, signalingMessage), report.getEvent());
    }
    return messages;
}
Also used : GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) Message(org.infobip.mobile.messaging.Message) ArrayMap(android.support.v4.util.ArrayMap) GeoEventType(org.infobip.mobile.messaging.geo.GeoEventType)

Example 59 with Message

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

the class GeoReportHelper method createNewMessageForReport.

/**
 * Creates new message based on geofencing report
 *
 * @param report          geofencing report for any supported event
 * @param reportingResult result of reporting geo events to server
 * @param originalMessage original signaling message
 * @return new message based on triggering event, area and original signaling message
 */
private static Message createNewMessageForReport(@NonNull final GeoReport report, @NonNull GeoReportingResult reportingResult, @NonNull Message originalMessage) {
    GeoLatLng triggeringLocation = report.getTriggeringLocation();
    if (triggeringLocation == null) {
        triggeringLocation = new GeoLatLng(null, null);
    }
    List<Area> areas = new ArrayList<>();
    if (report.getArea() != null) {
        areas.add(report.getArea());
    }
    Geo geo;
    Geo originalMessageGeo = GeoDataMapper.geoFromInternalData(originalMessage.getInternalData());
    if (originalMessageGeo != null) {
        geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), originalMessageGeo.getDeliveryTime(), originalMessageGeo.getExpiryTime(), originalMessageGeo.getStartTime(), originalMessageGeo.getCampaignId(), areas, originalMessageGeo.getEvents(), originalMessage.getSentTimestamp(), originalMessage.getContentUrl());
    } else {
        geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), null, null, null, null, areas, null, Time.now(), originalMessage.getContentUrl());
    }
    String internalData = GeoDataMapper.geoToInternalData(geo);
    return new Message(getMessageIdFromReport(report, reportingResult), originalMessage.getTitle(), originalMessage.getBody(), originalMessage.getSound(), originalMessage.isVibrate(), originalMessage.getIcon(), // enforcing non-silent
    false, originalMessage.getCategory(), originalMessage.getFrom(), Time.now(), 0, Time.now(), originalMessage.getCustomPayload(), internalData, originalMessage.getDestination(), originalMessage.getStatus(), originalMessage.getStatusMessage(), originalMessage.getContentUrl());
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) GeoLatLng(org.infobip.mobile.messaging.geo.GeoLatLng) ArrayList(java.util.ArrayList)

Example 60 with Message

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

the class NotificationActionTapReceiverTest method test_should_trigger_sdk_actions_when_clicked_on_action_button.

@Test
public void test_should_trigger_sdk_actions_when_clicked_on_action_button() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
    NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
    Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, 1234, notificationSettings.getIntentFlags());
    // When
    notificationActionTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
    Message actualMessage = messageArgumentCaptor.getValue();
    NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
    NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
    Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

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