Search in sources :

Example 16 with Message

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

the class NotificationTapReceiverTest method test_should_not_send_seen_report_message_ids_when_seen_on_tap_disabled.

@Test
public void test_should_not_send_seen_report_message_ids_when_seen_on_tap_disabled() {
    // Given
    PreferenceHelper.saveBoolean(context, MobileMessagingProperty.MARK_SEEN_ON_NOTIFICATION_TAP, false);
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    Intent givenIntent = givenIntent(givenMessage, notificationSettings.getIntentFlags());
    // When
    notificationTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(mobileMessagingCore, Mockito.never()).setMessagesSeen(Mockito.any(String[].class));
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

Example 17 with Message

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

the class NotificationTapReceiverTest method test_should_send_notification_tapped_event.

@Test
public void test_should_send_notification_tapped_event() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    Intent givenIntent = givenIntent(givenMessage, notificationSettings.getIntentFlags());
    // When
    notificationTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationTapped(messageArgumentCaptor.capture());
    assertJEquals(givenMessage, messageArgumentCaptor.getValue());
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

Example 18 with Message

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

the class MobileInteractiveImpl method messageFor.

private Message messageFor(final String categoryId, final NotificationAction action, final Message initialMessage) {
    Message message = new Message();
    message.setBody(categoryId + " " + action.getId());
    HashMap<String, String> map = new HashMap<>();
    map.put("initialMessageId", initialMessage.getMessageId());
    message.setInternalData(InternalDataMapper.mergeExistingInternalDataWithAnythingToJson(initialMessage.getInternalData(), map));
    return message;
}
Also used : Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap)

Example 19 with Message

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

the class NotificationActionTapReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle actionBundle = intent.getBundleExtra(EXTRA_TAPPED_ACTION);
    Bundle categoryBundle = intent.getBundleExtra(EXTRA_TAPPED_CATEGORY);
    int notificationId = intent.getIntExtra(BroadcastParameter.EXTRA_NOTIFICATION_ID, -1);
    Bundle messageBundle = intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE);
    Message message = Message.createFrom(messageBundle);
    NotificationCategory notificationCategory = NotificationCategory.createFrom(categoryBundle);
    NotificationAction notificationAction = NotificationAction.createFrom(actionBundle);
    String inputText = getInputTextFromIntent(intent, notificationAction);
    cancelNotification(context, notificationId);
    if (message == null) {
        MobileMessagingLogger.e("Received no message in NotificationActionTapReceiver");
        return;
    }
    if (notificationAction == null) {
        MobileMessagingLogger.e("Received no action in NotificationActionTapReceiver");
        return;
    }
    if (notificationCategory == null) {
        MobileMessagingLogger.e("Received no notification category in NotificationActionTapReceiver");
        return;
    }
    if (inputText != null) {
        notificationAction.setInputText(inputText);
    }
    broadcaster(context).notificationActionTapped(message, notificationCategory, notificationAction);
    mobileInteractive(context).triggerSdkActionsFor(notificationCategory.getCategoryId(), notificationAction, message);
    startCallbackActivity(context, intent, messageBundle, actionBundle, categoryBundle);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Bundle(android.os.Bundle) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory)

Example 20 with Message

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

the class GeoReportHelper method findSignalingMessagesAndAreas.

/**
 * Returns map of signaling messages and corresponding areas that match geofence and transition event
 *
 * @param messageStore message store to look messages for
 * @param requestIds   requestIds received from Google Location Services during transition event
 * @param event        transition event type
 * @return signaling messages with corresponding areas
 */
@NonNull
public static Map<Message, List<Area>> findSignalingMessagesAndAreas(Context context, MessageStore messageStore, Set<String> requestIds, @NonNull GeoEventType event) {
    Date now = Time.date();
    Map<Message, List<Area>> messagesAndAreas = new ArrayMap<>();
    for (Message message : messageStore.findAll(context)) {
        Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
        if (geo == null || geo.getAreasList() == null || geo.getAreasList().isEmpty()) {
            continue;
        }
        // don't trigger geo event before start date
        Date startDate = geo.getStartDate();
        if (startDate != null && startDate.after(now)) {
            continue;
        }
        List<Area> campaignAreas = geo.getAreasList();
        List<Area> triggeredAreas = new ArrayList<>();
        for (Area area : campaignAreas) {
            for (String requestId : requestIds) {
                if (!requestId.equalsIgnoreCase(area.getId())) {
                    continue;
                }
                if (!GeoNotificationHelper.shouldReportTransition(context, geo, event)) {
                    continue;
                }
                triggeredAreas.add(area);
            }
        }
        if (!triggeredAreas.isEmpty()) {
            messagesAndAreas.put(message, triggeredAreas);
        }
    }
    return filterOverlappingAreas(messagesAndAreas);
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) ArrayMap(android.support.v4.util.ArrayMap) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

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