Browse Source

Prevent crash if call intent is null

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
6c5860ac97
1 changed files with 18 additions and 13 deletions
  1. 18 13
      app/src/main/java/com/nextcloud/talk/controllers/ChatController.java

+ 18 - 13
app/src/main/java/com/nextcloud/talk/controllers/ChatController.java

@@ -91,6 +91,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Objects;
 
 
 import javax.inject.Inject;
 import javax.inject.Inject;
 
 
@@ -566,10 +567,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
                 return true;
                 return true;
 
 
             case R.id.conversation_video_call:
             case R.id.conversation_video_call:
-                startActivity(getIntentForCall(false));
+                startActivity(Objects.requireNonNull(getIntentForCall(false)));
                 return true;
                 return true;
             case R.id.conversation_voice_call:
             case R.id.conversation_voice_call:
-                startActivity(getIntentForCall(true));
+                startActivity(Objects.requireNonNull(getIntentForCall(true)));
                 return true;
                 return true;
 
 
             default:
             default:
@@ -578,19 +579,23 @@ public class ChatController extends BaseController implements MessagesListAdapte
     }
     }
 
 
     private Intent getIntentForCall(boolean isVoiceOnlyCall) {
     private Intent getIntentForCall(boolean isVoiceOnlyCall) {
-        Bundle bundle = new Bundle();
-        bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
-        bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
-        bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId());
-
-        if (isVoiceOnlyCall) {
-            bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true);
-        }
+        if (currentCall != null && !TextUtils.isEmpty(currentCall.getSessionId())) {
+            Bundle bundle = new Bundle();
+            bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
+            bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(currentUser));
+            bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId());
+
+            if (isVoiceOnlyCall) {
+                bundle.putBoolean(BundleKeys.KEY_CALL_VOICE_ONLY, true);
+            }
 
 
-        Intent callIntent = new Intent(getActivity(), CallActivity.class);
-        callIntent.putExtras(bundle);
+            Intent callIntent = new Intent(getActivity(), CallActivity.class);
+            callIntent.putExtras(bundle);
 
 
-        return callIntent;
+            return callIntent;
+        } else {
+            return null;
+        }
     }
     }