Improve notifications while in conversation

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-28 20:44:11 +02:00
parent 0d65cfbecd
commit 31d2d29a1f
8 changed files with 115 additions and 4 deletions

View File

@ -74,6 +74,7 @@ import com.nextcloud.talk.models.json.signaling.SignalingOverall;
import com.nextcloud.talk.models.json.signaling.settings.IceServer; import com.nextcloud.talk.models.json.signaling.settings.IceServer;
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall; import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.ApplicationWideCurrentRoomHolder;
import com.nextcloud.talk.utils.animations.PulseAnimation; import com.nextcloud.talk.utils.animations.PulseAnimation;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
@ -223,6 +224,7 @@ public class CallActivity extends AppCompatActivity {
private View.OnClickListener videoOnClickListener; private View.OnClickListener videoOnClickListener;
private String baseUrl; private String baseUrl;
private String roomId;
private SpotlightView spotlightView; private SpotlightView spotlightView;
@ -259,6 +261,7 @@ public class CallActivity extends AppCompatActivity {
.setRepeatCount(PulseAnimation.INFINITE) .setRepeatCount(PulseAnimation.INFINITE)
.setRepeatMode(PulseAnimation.REVERSE); .setRepeatMode(PulseAnimation.REVERSE);
roomId = getIntent().getExtras().getString(BundleKeys.KEY_ROOM_ID, "");
roomToken = getIntent().getExtras().getString(BundleKeys.KEY_ROOM_TOKEN, ""); roomToken = getIntent().getExtras().getString(BundleKeys.KEY_ROOM_TOKEN, "");
userEntity = Parcels.unwrap(getIntent().getExtras().getParcelable(BundleKeys.KEY_USER_ENTITY)); userEntity = Parcels.unwrap(getIntent().getExtras().getParcelable(BundleKeys.KEY_USER_ENTITY));
@ -930,8 +933,13 @@ public class CallActivity extends AppCompatActivity {
public void onNext(GenericOverall genericOverall) { public void onNext(GenericOverall genericOverall) {
inCall = true; inCall = true;
// start pinging the call // start pinging the call
if (!hasChatSupport) { if (!hasChatSupport) {
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
ApplicationWideCurrentRoomHolder.getInstance().setInCall(true);
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(userEntity);
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken)) ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -959,6 +967,8 @@ public class CallActivity extends AppCompatActivity {
dispose(pingDisposable); dispose(pingDisposable);
} }
}); });
} else {
ApplicationWideCurrentRoomHolder.getInstance().setInCall(true);
} }
// Start pulling signaling messages // Start pulling signaling messages
@ -1416,6 +1426,12 @@ public class CallActivity extends AppCompatActivity {
if (inCall) { if (inCall) {
hangup(false); hangup(false);
} }
if (hasChatSupport) {
ApplicationWideCurrentRoomHolder.getInstance().setInCall(false);
} else {
ApplicationWideCurrentRoomHolder.getInstance().clear();
}
//this.unregisterReceiver(networkBroadcastReceier); //this.unregisterReceiver(networkBroadcastReceier);
rootEglBase.release(); rootEglBase.release();
super.onDestroy(); super.onDestroy();

View File

@ -494,6 +494,7 @@ public class CallsListController extends BaseController implements SearchView.On
Room room = callItem.getModel(); Room room = callItem.getModel();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, callItem.getModel().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, callItem.getModel().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, callItem.getModel().getRoomId());
if (room.hasPassword && (room.participantType.equals(Participant.ParticipantType.GUEST) || if (room.hasPassword && (room.participantType.equals(Participant.ParticipantType.GUEST) ||
room.participantType.equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) { room.participantType.equals(Participant.ParticipantType.USER_FOLLOWING_LINK))) {

View File

@ -56,6 +56,7 @@ import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.nextcloud.talk.utils.ApplicationWideCurrentRoomHolder;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.CallActivity; import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder; import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
@ -153,7 +154,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private int newMessagesCount = 0; private int newMessagesCount = 0;
private Boolean startCallFromNotification; private Boolean startCallFromNotification;
private String roomId;
/* /*
TODO: TODO:
- check push notifications - check push notifications
@ -171,6 +172,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
this.conversationUser = currentUser; this.conversationUser = currentUser;
} }
this.roomId = args.getString(BundleKeys.KEY_ROOM_ID, "");
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
ApplicationWideCurrentRoomHolder.getInstance().setInCall(false);
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, ""); this.roomToken = args.getString(BundleKeys.KEY_ROOM_TOKEN, "");
if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) { if (args.containsKey(BundleKeys.KEY_ACTIVE_CONVERSATION)) {
@ -211,7 +218,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override @Override
public void onNext(RoomsOverall roomsOverall) { public void onNext(RoomsOverall roomsOverall) {
for (Room room : roomsOverall.getOcs().getData()) { for (Room room : roomsOverall.getOcs().getData()) {
if (roomToken.equals(room.getRoomId())) { if (roomId.equals(room.getRoomId())) {
roomToken = room.getToken(); roomToken = room.getToken();
conversationName = room.getDisplayName(); conversationName = room.getDisplayName();
setTitle(); setTitle();
@ -393,6 +400,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
public void onDestroy() { public void onDestroy() {
inChat = false; inChat = false;
dispose(); dispose();
ApplicationWideCurrentRoomHolder.getInstance().clear();
super.onDestroy(); super.onDestroy();
} }
@ -745,6 +753,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (currentCall != null && !TextUtils.isEmpty(currentCall.getSessionId())) { if (currentCall != null && !TextUtils.isEmpty(currentCall.getSessionId())) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken);
bundle.putString(BundleKeys.KEY_ROOM_ID, roomId);
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser)); bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(conversationUser));
bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword); bundle.putString(BundleKeys.KEY_CONVERSATION_PASSWORD, roomPassword);
bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId()); bundle.putString(BundleKeys.KEY_CALL_SESSION, currentCall.getSessionId());

View File

@ -296,6 +296,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
Intent conversationIntent = new Intent(getActivity(), CallActivity.class); Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, bundle.putString(BundleKeys.KEY_CONVERSATION_NAME,
@ -826,6 +827,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
Intent conversationIntent = new Intent(getActivity(), CallActivity.class); Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId());
conversationIntent.putExtras(bundle); conversationIntent.putExtras(bundle);
if (currentUser.hasSpreedCapabilityWithName("chat-v2")) { if (currentUser.hasSpreedCapabilityWithName("chat-v2")) {

View File

@ -544,6 +544,7 @@ public class OperationsMenuController extends BaseController {
Intent conversationIntent = new Intent(getActivity(), CallActivity.class); Intent conversationIntent = new Intent(getActivity(), CallActivity.class);
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken()); bundle.putString(BundleKeys.KEY_ROOM_TOKEN, room.getToken());
bundle.putString(BundleKeys.KEY_ROOM_ID, room.getToken());
bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName()); bundle.putString(BundleKeys.KEY_CONVERSATION_NAME, room.getDisplayName());
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call)); bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(call));

View File

@ -39,6 +39,7 @@ import android.util.Log;
import com.bluelinelabs.logansquare.LoganSquare; import com.bluelinelabs.logansquare.LoganSquare;
import com.evernote.android.job.Job; import com.evernote.android.job.Job;
import com.evernote.android.job.util.support.PersistableBundleCompat; import com.evernote.android.job.util.support.PersistableBundleCompat;
import com.nextcloud.talk.utils.ApplicationWideCurrentRoomHolder;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.CallActivity; import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.activities.MainActivity; import com.nextcloud.talk.activities.MainActivity;
@ -48,6 +49,7 @@ import com.nextcloud.talk.models.json.push.DecryptedPushMessage;
import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.NotificationUtils;
import com.nextcloud.talk.utils.PushUtils; import com.nextcloud.talk.utils.PushUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils;
import org.parceler.Parcels; import org.parceler.Parcels;
@ -59,6 +61,7 @@ import java.util.zip.CRC32;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import javax.inject.Inject;
import autodagger.AutoInjector; import autodagger.AutoInjector;
@ -66,9 +69,14 @@ import autodagger.AutoInjector;
public class NotificationJob extends Job { public class NotificationJob extends Job {
public static final String TAG = "NotificationJob"; public static final String TAG = "NotificationJob";
@Inject
UserUtils userUtils;
@NonNull @NonNull
@Override @Override
protected Result onRunJob(Params params) { protected Result onRunJob(Params params) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
Context context = getContext(); Context context = getContext();
PersistableBundleCompat persistableBundleCompat = getParams().getExtras(); PersistableBundleCompat persistableBundleCompat = getParams().getExtras();
String subject = persistableBundleCompat.getString(BundleKeys.KEY_NOTIFICATION_SUBJECT, ""); String subject = persistableBundleCompat.getString(BundleKeys.KEY_NOTIFICATION_SUBJECT, "");
@ -96,7 +104,15 @@ public class NotificationJob extends Job {
boolean hasChatSupport = signatureVerification.getUserEntity().hasSpreedCapabilityWithName boolean hasChatSupport = signatureVerification.getUserEntity().hasSpreedCapabilityWithName
("chat-v2"); ("chat-v2");
if (decryptedPushMessage.getApp().equals("spreed")) { boolean isInTheSameRoomAsNotification = ApplicationWideCurrentRoomHolder.getInstance().
getCurrentRoomId().equals(decryptedPushMessage.getId()) &&
signatureVerification.getUserEntity().equals(ApplicationWideCurrentRoomHolder
.getInstance().getUserInRoom());
boolean shouldShowNotification = decryptedPushMessage.getApp().equals("spreed") &&
!(isInTheSameRoomAsNotification && !decryptedPushMessage.getType().equals("call"));
if (shouldShowNotification) {
int smallIcon; int smallIcon;
Bitmap largeIcon; Bitmap largeIcon;
String category = ""; String category = "";
@ -115,7 +131,7 @@ public class NotificationJob extends Job {
bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, true); bundle.putBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, true);
} }
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, decryptedPushMessage.getId()); bundle.putString(BundleKeys.KEY_ROOM_ID, decryptedPushMessage.getId());
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(signatureVerification bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(signatureVerification
.getUserEntity())); .getUserEntity()));

View File

@ -0,0 +1,65 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.utils;
import com.nextcloud.talk.models.database.UserEntity;
public class ApplicationWideCurrentRoomHolder {
private String currentRoomId = "";
private UserEntity userInRoom = new UserEntity();
private boolean inCall = false;
private static final ApplicationWideCurrentRoomHolder holder = new ApplicationWideCurrentRoomHolder();
public static ApplicationWideCurrentRoomHolder getInstance() {
return holder;
}
public void clear() {
currentRoomId = "";
userInRoom = new UserEntity();
inCall = false;
}
public String getCurrentRoomId() {
return currentRoomId;
}
public void setCurrentRoomId(String currentRoomId) {
this.currentRoomId = currentRoomId;
}
public UserEntity getUserInRoom() {
return userInRoom;
}
public void setUserInRoom(UserEntity userInRoom) {
this.userInRoom = userInRoom;
}
public boolean isInCall() {
return inCall;
}
public void setInCall(boolean inCall) {
this.inCall = inCall;
}
}

View File

@ -49,4 +49,5 @@ public class BundleKeys {
public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION"; public static final String KEY_ACTIVE_CONVERSATION = "KEY_ACTIVE_CONVERSATION";
public static final String KEY_SPREED_CAPABILITIES = "KEY_SPREED_CAPABILITIES"; public static final String KEY_SPREED_CAPABILITIES = "KEY_SPREED_CAPABILITIES";
public static final String KEY_FROM_NOTIFICATION_START_CALL = "KEY_FROM_NOTIFICATION_START_CALL"; public static final String KEY_FROM_NOTIFICATION_START_CALL = "KEY_FROM_NOTIFICATION_START_CALL";
public static final String KEY_ROOM_ID = "KEY_ROOM_ID";
} }