package org.tndata.android.compass.service;

import android.app.IntentService;
import android.content.Intent;

import org.tndata.android.compass.CompassApplication;
import org.tndata.android.compass.model.GcmMessage;
import org.tndata.android.compass.model.User;
import org.tndata.android.compass.parser.ParserMethods;
import org.tndata.android.compass.receiver.GcmBroadcastReceiver;
import org.tndata.android.compass.util.API;
import org.tndata.android.compass.util.NotificationUtil;


/**
 * An {@link IntentService} subclass for handling asynchronous task requests in
 * a service on a separate handler thread.
 * <p/>
 * <p/>
 * NOTE: Messages received from GCM will have a format like the following:
 * <p/>
 * {
 * "title":"Demo"
 * "message":"Don't forget to review your Notifications for today",
 * "object_id":32,
 * "object_type":"action",  // an Action
 * }
 */
public class GcmIntentService extends IntentService{
    private static final String TAG = "GcmIntentService";

    public static final String FROM_GCM_KEY = "org.tndata.Compass.GcmIntentService.FromGcm";
    public static final String MESSAGE_KEY = "org.tndata.Compass.GcmIntentService.Message";


    public GcmIntentService(){
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent){
        boolean isFromGcm = intent.getBooleanExtra(FROM_GCM_KEY, false);
        String gcmMessage = intent.getStringExtra(MESSAGE_KEY);

        //IntentServices are executed in the background, so it is safe to do this
        GcmMessage message = ParserMethods.sGson.fromJson(gcmMessage, GcmMessage.class);
        if (message.isProduction() == !API.STAGING){
            User user = ((CompassApplication)getApplicationContext()).getUser();
            if (user.getId() == message.getRecipient()){
                message.setGcmMessage(gcmMessage);
                NotificationUtil.generateNotification(this, message);
            }
        }

        if (isFromGcm){
            GcmBroadcastReceiver.completeWakefulIntent(intent);
        }
    }
}

@@ -102,16 +102,41 @@
 .Intent;
+%0Aimport android.util.Log;
 %0A%0Aimport
@@ -1943,24 +1943,527 @@
           %7D%0A
+            else%7B%0A                long recipient = message.getRecipient();%0A                long receiver = user.getId();%0A                Log.e(TAG, %22The message was intended for %22 + recipient + %22, received by %22 + receiver);%0A            %7D%0A        %7D%0A        else%7B%0A            String sender = message.isProduction() ? %22production%22 : %22staging%22;%0A            String running = API.STAGING ? %22staging%22 : %22production%22;%0A            Log.e(TAG, %22The message was delivered from %22 + sender + %22, running %22 + running);%0A
         %7D%0A%0A 

Add some logs