From 7610314165eb2a0215c819ddad9dffe104baf6aa Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 31 Jan 2020 14:23:53 +1100 Subject: [PATCH] Exclude linked devices from group member options --- .../redesign/activities/CreateClosedGroupLoader.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt index 60f5ce9f41..620d47b5c6 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki.redesign.activities import android.content.Context import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.util.AsyncLoader +import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus class CreateClosedGroupLoader(context: Context) : AsyncLoader>(context) { @@ -10,6 +11,12 @@ class CreateClosedGroupLoader(context: Context) : AsyncLoader>(cont override fun loadInBackground(): List { val threadDatabase = DatabaseFactory.getThreadDatabase(context) val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context) + val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) + val deviceLinks = DatabaseFactory.getLokiAPIDatabase(context).getPairingAuthorisations(userHexEncodedPublicKey) + val userLinkedDeviceHexEncodedPublicKeys = deviceLinks.flatMap { + listOf( it.primaryDevicePublicKey.toLowerCase(), it.secondaryDevicePublicKey.toLowerCase() ) + }.toMutableSet() + userLinkedDeviceHexEncodedPublicKeys.add(userHexEncodedPublicKey.toLowerCase()) val cursor = threadDatabase.conversationList val reader = threadDatabase.readerFor(cursor) val result = mutableListOf() @@ -17,7 +24,9 @@ class CreateClosedGroupLoader(context: Context) : AsyncLoader>(cont val thread = reader.current if (thread.recipient.isGroupRecipient) { continue } if (lokiThreadDatabase.getFriendRequestStatus(thread.threadId) != LokiThreadFriendRequestStatus.FRIENDS) { continue } - result.add(thread.recipient.address.toString()) + val hexEncodedPublicKey = thread.recipient.address.toString().toLowerCase() + if (userLinkedDeviceHexEncodedPublicKeys.contains(hexEncodedPublicKey)) { continue } + result.add(hexEncodedPublicKey) } return result }