diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index c1a43646c1..b7b92a2ced 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -1137,6 +1137,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private void becomeFriendsWithContact(String pubKey, boolean syncContact) { LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context); Recipient contactID = Recipient.from(context, Address.fromSerialized(pubKey), false); + if (contactID.isGroupRecipient()) return; + long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(contactID); LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID); if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) { return; } @@ -1172,6 +1174,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Recipient primaryDeviceRecipient = getMessagePrimaryDestination(content, message); LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context); + // Loki - Friend requests only work in direct chats + if (!originalRecipient.getAddress().isPhone()) { return; } + long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(originalRecipient); long primaryDeviceThreadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(primaryDeviceRecipient); LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID); diff --git a/src/org/thoughtcrime/securesms/loki/FriendRequestHandler.kt b/src/org/thoughtcrime/securesms/loki/FriendRequestHandler.kt index 732588d2a2..cc4ef0f273 100644 --- a/src/org/thoughtcrime/securesms/loki/FriendRequestHandler.kt +++ b/src/org/thoughtcrime/securesms/loki/FriendRequestHandler.kt @@ -16,20 +16,20 @@ object FriendRequestHandler { @JvmStatic fun updateFriendRequestState(context: Context, type: ActionType, messageId: Long, threadId: Long) { + if (threadId < 0) return + val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return + if (!recipient.address.isPhone) { return } + // Update thread status - // Note: Do we need to only update these if we're not friends? - if (threadId >= 0) { - val threadFriendStatus = when (type) { - ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING - ActionType.Failed -> LokiThreadFriendRequestStatus.NONE - ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT - } - DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus) + val threadFriendStatus = when (type) { + ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING + ActionType.Failed -> LokiThreadFriendRequestStatus.NONE + ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT } + DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus) // Update message status - val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) - if (recipient != null && messageId >= 0) { + if (messageId >= 0) { val messageDatabase = DatabaseFactory.getLokiMessageDatabase(context) val friendRequestStatus = messageDatabase.getFriendRequestStatus(messageId) if (type == ActionType.Sending) { @@ -73,6 +73,8 @@ object FriendRequestHandler { // We only want to update the last message status if we're not friends with any of their linked devices // This ensures that we don't spam the UI with accept/decline messages val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return + if (!recipient.address.isPhone) { return } + isFriendsWithAnyLinkedDevice(context, recipient).successUi { isFriends -> if (isFriends) { return@successUi } diff --git a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt index fffbeecd80..13e61721ac 100644 --- a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt @@ -61,6 +61,11 @@ fun getFriendCount(context: Context, devices: Set): Int { } fun shouldAutomaticallyBecomeFriendsWithDevice(publicKey: String, context: Context): Promise { + // Don't become friends if we're a group + if (!Address.fromSerialized(publicKey).isPhone) { + return Promise.of(false) + } + // If this public key is our primary device then we should become friends if (publicKey == TextSecurePreferences.getMasterHexEncodedPublicKey(context)) { return Promise.of(true)