Migrate recieving calls from requery to room

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-16 14:51:07 +02:00
parent cbe4658632
commit 4bdc2c1081
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
6 changed files with 59 additions and 80 deletions

View file

@ -189,26 +189,18 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
Log.d(TAG, this.toString())
timestamp = System.currentTimeMillis()
if (delete) {
cancelExistingNotificationWithId(
applicationContext,
signatureVerification!!.userEntity!!,
notificationId
)
cancelExistingNotificationWithId(applicationContext, signatureVerification!!.user!!, notificationId)
} else if (deleteAll) {
cancelAllNotificationsForAccount(applicationContext, signatureVerification!!.userEntity!!)
cancelAllNotificationsForAccount(applicationContext, signatureVerification!!.user!!)
} else if (deleteMultiple) {
notificationIds!!.forEach {
cancelExistingNotificationWithId(
applicationContext,
signatureVerification!!.userEntity!!,
it
)
cancelExistingNotificationWithId(applicationContext, signatureVerification!!.user!!, it)
}
} else if (type == "call") {
val fullScreenIntent = Intent(applicationContext, CallNotificationActivity::class.java)
val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_ID, decryptedPushMessage!!.id)
bundle.putParcelable(KEY_USER_ENTITY, signatureVerification!!.userEntity)
bundle.putParcelable(KEY_USER_ENTITY, signatureVerification!!.user)
bundle.putBoolean(KEY_FROM_NOTIFICATION_START_CALL, true)
fullScreenIntent.putExtras(bundle)
@ -226,7 +218,7 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
val soundUri = getCallRingtoneUri(applicationContext!!, appPreferences)
val notificationChannelId = NotificationUtils.NOTIFICATION_CHANNEL_CALLS_V4
val uri = Uri.parse(signatureVerification!!.userEntity!!.baseUrl)
val uri = Uri.parse(signatureVerification!!.user!!.baseUrl)
val baseUrl = uri.host
val notification =
@ -274,18 +266,18 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
var inCallOnDifferentDevice = false
val apiVersion = ApiUtils.getConversationApiVersion(
signatureVerification.userEntity,
signatureVerification.user,
intArrayOf(ApiUtils.APIv4, 1)
)
ncApi.getPeersForCall(
ApiUtils.getCredentials(
signatureVerification.userEntity!!.username,
signatureVerification.userEntity!!.token
signatureVerification.user!!.username,
signatureVerification.user!!.token
),
ApiUtils.getUrlForCall(
apiVersion,
signatureVerification.userEntity!!.baseUrl,
signatureVerification.user!!.baseUrl,
decryptedPushMessage.id
)
)
@ -303,7 +295,7 @@ class ChatAndCallMessagingService : FirebaseMessagingService() {
hasParticipantsInCall = participantList.isNotEmpty()
if (hasParticipantsInCall) {
for (participant in participantList) {
if (participant.actorId == signatureVerification.userEntity!!.userId &&
if (participant.actorId == signatureVerification.user!!.userId &&
participant.actorType == Participant.ActorType.USERS
) {
inCallOnDifferentDevice = true

View file

@ -46,10 +46,9 @@ import com.facebook.imagepipeline.request.ImageRequest;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.databinding.CallNotificationActivityBinding;
import com.nextcloud.talk.events.CallNotificationClick;
import com.nextcloud.talk.models.database.CapabilitiesUtil;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.conversations.Conversation;
import com.nextcloud.talk.models.json.conversations.RoomOverall;
import com.nextcloud.talk.models.json.participants.Participant;
@ -59,6 +58,7 @@ import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.DoNotDisturbUtils;
import com.nextcloud.talk.utils.NotificationUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
import com.nextcloud.talk.utils.preferences.AppPreferences;
import org.greenrobot.eventbus.EventBus;
@ -106,7 +106,7 @@ public class CallNotificationActivity extends CallBaseActivity {
private List<Disposable> disposablesList = new ArrayList<>();
private Bundle originalBundle;
private String roomId;
private UserEntity userBeingCalled;
private User userBeingCalled;
private String credentials;
private Conversation currentConversation;
private MediaPlayer mediaPlayer;
@ -285,8 +285,8 @@ public class CallNotificationActivity extends CallBaseActivity {
if (apiVersion >= 3) {
boolean hasCallFlags =
CapabilitiesUtil.hasSpreedFeatureCapability(userBeingCalled,
"conversation-call-flags");
CapabilitiesUtilNew.hasSpreedFeatureCapability(userBeingCalled,
"conversation-call-flags");
if (hasCallFlags) {
if (isInCallWithVideo(currentConversation.getCallFlag())) {
binding.incomingCallVoiceOrVideoTextView.setText(
@ -308,7 +308,7 @@ public class CallNotificationActivity extends CallBaseActivity {
@Override
public void onComplete() {
// unused atm
}
});
}

View file

@ -42,6 +42,7 @@ import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.activities.MainActivity;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.models.SignatureVerification;
import com.nextcloud.talk.models.database.ArbitraryStorageEntity;
import com.nextcloud.talk.models.database.UserEntity;
@ -130,20 +131,20 @@ public class NotificationWorker extends Worker {
}
private void showNotificationForCallWithNoPing(Intent intent) {
UserEntity userEntity = signatureVerification.getUserEntity();
User user = signatureVerification.getUser();
ArbitraryStorageEntity arbitraryStorageEntity;
if ((arbitraryStorageEntity = arbitraryStorageUtils.getStorageSetting(
userEntity.getId(),
user.getId(),
"important_conversation",
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN()))) != null) {
importantConversation = Boolean.parseBoolean(arbitraryStorageEntity.getValue());
}
int apiVersion = ApiUtils.getConversationApiVersion(userEntity, new int[] {ApiUtils.APIv4, 1});
int apiVersion = ApiUtils.getConversationApiVersion(user, new int[] {ApiUtils.APIv4, 1});
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, userEntity.getBaseUrl(),
ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, user.getBaseUrl(),
intent.getExtras().getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN())))
.blockingSubscribe(new Observer<RoomOverall>() {
@Override
@ -188,8 +189,8 @@ public class NotificationWorker extends Worker {
}
private void showNotificationWithObjectData(Intent intent) {
UserEntity userEntity = signatureVerification.getUserEntity();
ncApi.getNotification(credentials, ApiUtils.getUrlForNotificationWithId(userEntity.getBaseUrl(),
User user = signatureVerification.getUser();
ncApi.getNotification(credentials, ApiUtils.getUrlForNotificationWithId(user.getBaseUrl(),
Long.toString(decryptedPushMessage.getNotificationId())))
.blockingSubscribe(new Observer<NotificationOverall>() {
@Override
@ -309,7 +310,7 @@ public class NotificationWorker extends Worker {
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, intentFlag);
Uri uri = Uri.parse(signatureVerification.getUserEntity().getBaseUrl());
Uri uri = Uri.parse(signatureVerification.getUser().getBaseUrl());
String baseUrl = uri.getHost();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "1")
@ -339,7 +340,7 @@ public class NotificationWorker extends Worker {
Bundle notificationInfo = new Bundle();
notificationInfo.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(),
signatureVerification.getUserEntity().getId());
signatureVerification.getUser().getId());
// could be an ID or a TOKEN
notificationInfo.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(),
decryptedPushMessage.getId());
@ -358,12 +359,13 @@ public class NotificationWorker extends Worker {
notificationBuilder.setContentIntent(pendingIntent);
String groupName = signatureVerification.getUserEntity().getId() + "@" + decryptedPushMessage.getId();
String groupName = signatureVerification.getUser().getId() + "@" + decryptedPushMessage.getId();
notificationBuilder.setGroup(Long.toString(calculateCRC32(groupName)));
StatusBarNotification activeStatusBarNotification =
NotificationUtils.INSTANCE.findNotificationForRoom(context,
signatureVerification.getUserEntity(), decryptedPushMessage.getId());
signatureVerification.getUser(),
decryptedPushMessage.getId());
// NOTE - systemNotificationId is an internal ID used on the device only.
// It is NOT the same as the notification ID used in communication with the server.
@ -404,7 +406,7 @@ public class NotificationWorker extends Worker {
Person.Builder person =
new Person.Builder()
.setKey(signatureVerification.getUserEntity().getId() + "@" + notificationUser.getId())
.setKey(signatureVerification.getUser().getId() + "@" + notificationUser.getId())
.setName(EmojiCompat.get().process(notificationUser.getName()))
.setBot("bot".equals(userType));
@ -413,7 +415,7 @@ public class NotificationWorker extends Worker {
addMarkAsReadAction(notificationBuilder, systemNotificationId);
if ("user".equals(userType) || "guest".equals(userType)) {
String baseUrl = signatureVerification.getUserEntity().getBaseUrl();
String baseUrl = signatureVerification.getUser().getBaseUrl();
String avatarUrl = "user".equals(userType) ?
ApiUtils.getUrlForAvatar(baseUrl, notificationUser.getId(), false) :
ApiUtils.getUrlForGuestAvatar(baseUrl, notificationUser.getName(), false);
@ -430,7 +432,7 @@ public class NotificationWorker extends Worker {
// It is NOT the same as the notification ID used in communication with the server.
actualIntent.putExtra(BundleKeys.INSTANCE.getKEY_SYSTEM_NOTIFICATION_ID(), systemNotificationId);
actualIntent.putExtra(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(),
Objects.requireNonNull(signatureVerification.getUserEntity()).getId());
Objects.requireNonNull(signatureVerification.getUser()).getId());
actualIntent.putExtra(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), decryptedPushMessage.getId());
actualIntent.putExtra(BundleKeys.KEY_MESSAGE_ID, messageId);
@ -593,22 +595,22 @@ public class NotificationWorker extends Worker {
if (decryptedPushMessage.getDelete()) {
NotificationUtils.INSTANCE.cancelExistingNotificationWithId(
context,
signatureVerification.getUserEntity(),
signatureVerification.getUser(),
decryptedPushMessage.getNotificationId());
} else if (decryptedPushMessage.getDeleteAll()) {
NotificationUtils.INSTANCE.cancelAllNotificationsForAccount(
context,
signatureVerification.getUserEntity());
signatureVerification.getUser());
} else if (decryptedPushMessage.getDeleteMultiple()) {
for (long notificationId : decryptedPushMessage.getNotificationIds()) {
NotificationUtils.INSTANCE.cancelExistingNotificationWithId(
context,
signatureVerification.getUserEntity(),
signatureVerification.getUser(),
notificationId);
}
} else {
credentials = ApiUtils.getCredentials(signatureVerification.getUserEntity().getUsername(),
signatureVerification.getUserEntity().getToken());
credentials = ApiUtils.getCredentials(signatureVerification.getUser().getUsername(),
signatureVerification.getUser().getToken());
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
@ -632,7 +634,7 @@ public class NotificationWorker extends Worker {
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), decryptedPushMessage.getId());
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY(),
signatureVerification.getUserEntity());
signatureVerification.getUser());
bundle.putBoolean(BundleKeys.INSTANCE.getKEY_FROM_NOTIFICATION_START_CALL(),
startACall);

View file

@ -22,11 +22,11 @@
package com.nextcloud.talk.models
import android.os.Parcelable
import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.data.user.model.User
import kotlinx.android.parcel.Parcelize
@Parcelize
data class SignatureVerification(
var signatureValid: Boolean = false,
var userEntity: UserEntity? = null
var user: User? = null
) : Parcelable

View file

@ -43,7 +43,6 @@ import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.RingtoneSettings
import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.preferences.AppPreferences
import java.io.IOException
@ -218,20 +217,14 @@ object NotificationUtils {
}
}
fun cancelAllNotificationsForAccount(context: Context?, conversationUser: UserEntity) {
scanNotifications(
context,
LegacyUserEntityMapper.toModel(conversationUser)!!
) { notificationManager, statusBarNotification, _ ->
fun cancelAllNotificationsForAccount(context: Context?, conversationUser: User) {
scanNotifications(context, conversationUser) { notificationManager, statusBarNotification, _ ->
notificationManager.cancel(statusBarNotification.id)
}
}
fun cancelExistingNotificationWithId(context: Context?, conversationUser: UserEntity, notificationId: Long?) {
scanNotifications(
context,
LegacyUserEntityMapper.toModel(conversationUser)!!
) { notificationManager, statusBarNotification, notification ->
fun cancelExistingNotificationWithId(context: Context?, conversationUser: User, notificationId: Long?) {
scanNotifications(context, conversationUser) { notificationManager, statusBarNotification, notification ->
if (notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)) {
notificationManager.cancel(statusBarNotification.id)
}
@ -240,13 +233,10 @@ object NotificationUtils {
fun findNotificationForRoom(
context: Context?,
conversationUser: UserEntity,
conversationUser: User,
roomTokenOrId: String
): StatusBarNotification? {
scanNotifications(
context,
LegacyUserEntityMapper.toModel(conversationUser)!!
) { _, statusBarNotification, notification ->
scanNotifications(context, conversationUser) { _, statusBarNotification, notification ->
if (roomTokenOrId == notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)) {
return statusBarNotification
}
@ -254,11 +244,7 @@ object NotificationUtils {
return null
}
fun cancelExistingNotificationsForRoom(
context: Context?,
conversationUser: User,
roomTokenOrId: String
) {
fun cancelExistingNotificationsForRoom(context: Context?, conversationUser: User, roomTokenOrId: String) {
scanNotifications(context, conversationUser) { notificationManager, statusBarNotification, notification ->
if (roomTokenOrId == notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)) {
notificationManager.cancel(statusBarNotification.id)

View file

@ -31,11 +31,13 @@ import com.bluelinelabs.logansquare.LoganSquare;
import com.nextcloud.talk.R;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.events.EventStatus;
import com.nextcloud.talk.models.SignatureVerification;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.push.PushConfigurationState;
import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
import com.nextcloud.talk.users.UserManager;
import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences;
@ -78,6 +80,9 @@ public class PushUtils {
@Inject
UserUtils userUtils;
@Inject
UserManager userManager;
@Inject
AppPreferences appPreferences;
@ -103,27 +108,23 @@ public class PushUtils {
}
public SignatureVerification verifySignature(byte[] signatureBytes, byte[] subjectBytes) {
Signature signature = null;
PushConfigurationState pushConfigurationState;
PublicKey publicKey;
SignatureVerification signatureVerification = new SignatureVerification();
signatureVerification.setSignatureValid(false);
List<UserEntity> userEntities = userUtils.getUsers();
List<User> users = userManager.getUsers().blockingGet();
try {
signature = Signature.getInstance("SHA512withRSA");
if (userEntities != null && userEntities.size() > 0) {
for (UserEntity userEntity : userEntities) {
if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(),
PushConfigurationState.class);
Signature signature = Signature.getInstance("SHA512withRSA");
if (users != null && users.size() > 0) {
PublicKey publicKey;
for (User user : users) {
if (user.getPushConfigurationState() != null) {
publicKey = (PublicKey) readKeyFromString(true,
pushConfigurationState.getUserPublicKey());
user.getPushConfigurationState().getUserPublicKey());
signature.initVerify(publicKey);
signature.update(subjectBytes);
if (signature.verify(signatureBytes)) {
signatureVerification.setSignatureValid(true);
signatureVerification.setUserEntity(userEntity);
signatureVerification.setUser(user);
return signatureVerification;
}
}
@ -131,8 +132,6 @@ public class PushUtils {
}
} catch (NoSuchAlgorithmException e) {
Log.d(TAG, "No such algorithm");
} catch (IOException e) {
Log.d(TAG, "Error while trying to parse push configuration state");
} catch (InvalidKeyException e) {
Log.d(TAG, "Invalid key while trying to verify");
} catch (SignatureException e) {