Add support for chat push

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-28 19:44:27 +02:00
parent 62cf45778e
commit 0d65cfbecd
4 changed files with 80 additions and 66 deletions

View File

@ -213,6 +213,7 @@ public class CallActivity extends AppCompatActivity {
private boolean audioOn = false; private boolean audioOn = false;
private boolean isMultiSession = false; private boolean isMultiSession = false;
private boolean hasChatSupport = false;
private boolean isVoiceOnlyCall = false; private boolean isVoiceOnlyCall = false;
private Handler handler = new Handler(); private Handler handler = new Handler();
@ -858,6 +859,14 @@ public class CallActivity extends AppCompatActivity {
.getCapabilities().getSpreedCapability() .getCapabilities().getSpreedCapability()
.getFeatures().contains("multi-room-users"); .getFeatures().contains("multi-room-users");
hasChatSupport = capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability() != null &&
capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability()
.getFeatures() != null && capabilitiesOverall.getOcs().getData()
.getCapabilities().getSpreedCapability()
.getFeatures().contains("chat-v2");
joinRoomAndCall(); joinRoomAndCall();
} }
@ -887,7 +896,7 @@ public class CallActivity extends AppCompatActivity {
@Override @Override
public void onNext(CallOverall callOverall) { public void onNext(CallOverall callOverall) {
performCall(callOverall.getOcs().getData().getSessionId()); performCall();
} }
@Override @Override
@ -901,11 +910,11 @@ public class CallActivity extends AppCompatActivity {
} }
}); });
} else { } else {
performCall(callSession); performCall();
} }
} }
private void performCall(@Nullable String callSessionId) { private void performCall() {
ncApi.joinCall(credentials, ncApi.joinCall(credentials,
ApiUtils.getUrlForCall(baseUrl, roomToken)) ApiUtils.getUrlForCall(baseUrl, roomToken))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
@ -922,33 +931,35 @@ public class CallActivity extends AppCompatActivity {
inCall = true; inCall = true;
// start pinging the call // start pinging the call
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken)) if (!hasChatSupport) {
.subscribeOn(Schedulers.newThread()) ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken))
.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.newThread())
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS)) .observeOn(AndroidSchedulers.mainThread())
.takeWhile(observable -> inCall) .repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
.retry(3, observable -> inCall) .takeWhile(observable -> inCall)
.subscribe(new Observer<GenericOverall>() { .retry(3, observable -> inCall)
@Override .subscribe(new Observer<GenericOverall>() {
public void onSubscribe(Disposable d) { @Override
pingDisposable = d; public void onSubscribe(Disposable d) {
} pingDisposable = d;
}
@Override @Override
public void onNext(GenericOverall genericOverall) { public void onNext(GenericOverall genericOverall) {
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
dispose(pingDisposable); dispose(pingDisposable);
} }
@Override @Override
public void onComplete() { public void onComplete() {
dispose(pingDisposable); dispose(pingDisposable);
} }
}); });
}
// Start pulling signaling messages // Start pulling signaling messages
String urlToken = null; String urlToken = null;

View File

@ -21,6 +21,7 @@
package com.nextcloud.talk.activities; package com.nextcloud.talk.activities;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -33,7 +34,6 @@ import com.bluelinelabs.conductor.Conductor;
import com.bluelinelabs.conductor.Router; import com.bluelinelabs.conductor.Router;
import com.bluelinelabs.conductor.RouterTransaction; import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.ChatController; import com.nextcloud.talk.controllers.ChatController;
@ -53,6 +53,7 @@ import org.greenrobot.eventbus.ThreadMode;
import java.security.cert.CertificateParsingException; import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@ -108,37 +109,47 @@ public final class MainActivity extends AppCompatActivity implements ActionBarPr
} }
if (getIntent().hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { if (getIntent().hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
router.setRoot(RouterTransaction.with(new MagicBottomNavigationController()) onNewIntent(getIntent());
.pushChangeHandler(new NoOpControllerChangeHandler()) } else if (!router.hasRootController()) {
.popChangeHandler(new NoOpControllerChangeHandler())); if (hasDb) {
if (userUtils.anyUserExists()) {
router.pushController(RouterTransaction.with(new ChatController(getIntent().getExtras())) router.setRoot(RouterTransaction.with(new MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} else {
if (!router.hasRootController()) {
if (hasDb) {
if (userUtils.anyUserExists()) {
router.setRoot(RouterTransaction.with(new MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else {
router.setRoot(RouterTransaction.with(new ServerSelectionController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
}
} else { } else {
router.setRoot(RouterTransaction.with(new ServerSelectionController()) router.setRoot(RouterTransaction.with(new ServerSelectionController())
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new HorizontalChangeHandler()));
} }
} else {
router.setRoot(RouterTransaction.with(new ServerSelectionController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} }
} }
} }
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
List<RouterTransaction> newBackstack = new ArrayList<>();
newBackstack.add(RouterTransaction.with(new MagicBottomNavigationController())
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
router.setBackstack(newBackstack, new HorizontalChangeHandler());
router.pushController(RouterTransaction.with(new ChatController(intent.getExtras()))
.pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
}
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (!router.handleBack()) { if (!router.handleBack()) {

View File

@ -164,7 +164,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
UserEntity currentUser = userUtils.getCurrentUser(); UserEntity currentUser = userUtils.getCurrentUser();
this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME); this.conversationName = args.getString(BundleKeys.KEY_CONVERSATION_NAME, "");
if (args.containsKey(BundleKeys.KEY_USER_ENTITY)) { if (args.containsKey(BundleKeys.KEY_USER_ENTITY)) {
this.conversationUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY)); this.conversationUser = Parcels.unwrap(args.getParcelable(BundleKeys.KEY_USER_ENTITY));
} else { } else {
@ -213,6 +213,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
for (Room room : roomsOverall.getOcs().getData()) { for (Room room : roomsOverall.getOcs().getData()) {
if (roomToken.equals(room.getRoomId())) { if (roomToken.equals(room.getRoomId())) {
roomToken = room.getToken(); roomToken = room.getToken();
conversationName = room.getDisplayName();
setTitle();
break; break;
} }
} }

View File

@ -93,6 +93,9 @@ public class NotificationJob extends Job {
DecryptedPushMessage decryptedPushMessage = LoganSquare.parse(new String(decryptedSubject), DecryptedPushMessage decryptedPushMessage = LoganSquare.parse(new String(decryptedSubject),
DecryptedPushMessage.class); DecryptedPushMessage.class);
boolean hasChatSupport = signatureVerification.getUserEntity().hasSpreedCapabilityWithName
("chat-v2");
if (decryptedPushMessage.getApp().equals("spreed")) { if (decryptedPushMessage.getApp().equals("spreed")) {
int smallIcon; int smallIcon;
Bitmap largeIcon; Bitmap largeIcon;
@ -103,8 +106,6 @@ public class NotificationJob extends Job {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
boolean hasChatSupport = signatureVerification.getUserEntity().hasSpreedCapabilityWithName
("chat-v2");
if (hasChatSupport) { if (hasChatSupport) {
intent = new Intent(context, MainActivity.class); intent = new Intent(context, MainActivity.class);
@ -118,21 +119,13 @@ public class NotificationJob extends Job {
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(signatureVerification bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(signatureVerification
.getUserEntity())); .getUserEntity()));
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL,
if (hasChatSupport) { decryptedPushMessage.getType().equals("call") || !hasChatSupport);
if (decryptedPushMessage.getType().equals("call")) {
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, true);
} else {
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false);
}
} else {
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, true);
}
intent.putExtras(bundle); intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(context, PendingIntent pendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
@ -150,9 +143,6 @@ public class NotificationJob extends Job {
priority = Notification.PRIORITY_HIGH; priority = Notification.PRIORITY_HIGH;
break; break;
case "chat": case "chat":
if (hasChatSupport) {
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false);
}
smallIcon = R.drawable.ic_chat_black_24dp; smallIcon = R.drawable.ic_chat_black_24dp;
category = Notification.CATEGORY_MESSAGE; category = Notification.CATEGORY_MESSAGE;
break; break;