From 7b8fbcea4e3531fbc7a3be211674f08720bdd141 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 14 Apr 2020 16:31:31 +1000 Subject: [PATCH 01/80] Added ContactUtilities. --- .../activities/CreateClosedGroupLoader.kt | 29 ++------ .../redesign/utilities/ContactUtilities.kt | 66 +++++++++++++++++++ 2 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt index 2c07fe0772..a10d1ac18f 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt @@ -1,33 +1,18 @@ package org.thoughtcrime.securesms.loki.redesign.activities import android.content.Context -import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.loki.redesign.utilities.ContactUtilities 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) { override fun loadInBackground(): List { - val threadDatabase = DatabaseFactory.getThreadDatabase(context) - val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context) - val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) - val deviceLinks = DatabaseFactory.getLokiAPIDatabase(context).getDeviceLinks(userHexEncodedPublicKey) - val userLinkedDeviceHexEncodedPublicKeys = deviceLinks.flatMap { - listOf( it.masterHexEncodedPublicKey.toLowerCase(), it.slaveHexEncodedPublicKey.toLowerCase() ) - }.toMutableSet() - userLinkedDeviceHexEncodedPublicKeys.add(userHexEncodedPublicKey.toLowerCase()) - val cursor = threadDatabase.conversationList - val reader = threadDatabase.readerFor(cursor) - val result = mutableListOf() - while (reader.next != null) { - val thread = reader.current - if (thread.recipient.isGroupRecipient) { continue } - if (lokiThreadDatabase.getFriendRequestStatus(thread.threadId) != LokiThreadFriendRequestStatus.FRIENDS) { continue } - val hexEncodedPublicKey = thread.recipient.address.toString().toLowerCase() - if (userLinkedDeviceHexEncodedPublicKeys.contains(hexEncodedPublicKey)) { continue } - result.add(hexEncodedPublicKey) + val contacts = ContactUtilities.getAllContacts(context) + // Only show the master device of the users we are friends with + return contacts.filter { contact -> + !contact.recipient.isGroupRecipient && contact.isFriend && !contact.isOurDevice && !contact.isSlave + }.map { + it.recipient.address.toPhoneString() } - return result } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt b/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt new file mode 100644 index 0000000000..c10aa3df6c --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt @@ -0,0 +1,66 @@ +package org.thoughtcrime.securesms.loki.redesign.utilities + +import android.content.Context +import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.recipients.Recipient +import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus + +data class Contact( + val recipient: Recipient, + val threadId: Long, + val isFriend: Boolean, + val isSlave: Boolean, + val isOurDevice: Boolean +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other?.javaClass != javaClass) return false + + other as Contact + + return recipient == other.recipient + } + + override fun hashCode(): Int { + return recipient.hashCode() + } +} + +object ContactUtilities { + + @JvmStatic + fun getAllContacts(context: Context): Set { + val threadDatabase = DatabaseFactory.getThreadDatabase(context) + val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context) + val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) + val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context) + + val ourDeviceLinks = lokiAPIDatabase.getDeviceLinks(userHexEncodedPublicKey) + val ourDevices = ourDeviceLinks.flatMap { + listOf( it.masterHexEncodedPublicKey.toLowerCase(), it.slaveHexEncodedPublicKey.toLowerCase() ) + }.toMutableSet() + ourDevices.add(userHexEncodedPublicKey.toLowerCase()) + + val cursor = threadDatabase.conversationList + val reader = threadDatabase.readerFor(cursor) + val result = mutableSetOf() + while (reader.next != null) { + val thread = reader.current + val recipient = thread.recipient + val hexEncodedPublicKey = recipient.address.serialize() + + val isFriend = lokiThreadDatabase.getFriendRequestStatus(thread.threadId) == LokiThreadFriendRequestStatus.FRIENDS + var isSlave = false + if (!recipient.isGroupRecipient) { + val deviceLinks = lokiAPIDatabase.getDeviceLinks(hexEncodedPublicKey) + isSlave = deviceLinks.find { it.slaveHexEncodedPublicKey == hexEncodedPublicKey } != null + } + val isOurDevice = ourDevices.contains(hexEncodedPublicKey) + + result.add(Contact(recipient, thread.threadId, isFriend, isSlave, isOurDevice)) + } + return result + } + +} \ No newline at end of file From 361dab24d6c9e733e0d6ee7a610570b24734720d Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 15 Apr 2020 12:52:23 +1000 Subject: [PATCH 02/80] Replaced signal ContactSelection things with loki ones. Fixed sharing in session (we can only share to one user at a time). --- res/layout/contact_selection_activity.xml | 2 +- .../contact_selection_list_fragment.xml | 122 +++---- res/layout/invite_activity.xml | 2 +- res/layout/share_activity.xml | 2 +- res/values/strings.xml | 6 +- .../securesms/ContactSelectionActivity.java | 12 +- .../ContactSelectionListFragment.java | 303 ------------------ .../securesms/GroupCreateActivity.java | 9 +- .../securesms/InviteActivity.java | 12 +- .../PushContactSelectionActivity.java | 2 + .../thoughtcrime/securesms/ShareActivity.java | 20 +- .../contacts/ContactSelectionListAdapter.java | 271 ---------------- .../activities/ContactSelectionListAdapter.kt | 85 +++++ .../activities/ContactSelectionListLoader.kt | 80 +++++ .../fragments/ContactSelectionListFragment.kt | 130 ++++++++ .../redesign/utilities/ContactUtilities.kt | 33 +- .../securesms/recipients/Recipient.java | 3 +- 17 files changed, 385 insertions(+), 709 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/ContactSelectionListFragment.java delete mode 100644 src/org/thoughtcrime/securesms/contacts/ContactSelectionListAdapter.java create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListAdapter.kt create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListLoader.kt create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/fragments/ContactSelectionListFragment.kt diff --git a/res/layout/contact_selection_activity.xml b/res/layout/contact_selection_activity.xml index 748fef44c0..1ad3e1343c 100644 --- a/res/layout/contact_selection_activity.xml +++ b/res/layout/contact_selection_activity.xml @@ -19,6 +19,6 @@ + android:name="org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment" /> \ No newline at end of file diff --git a/res/layout/contact_selection_list_fragment.xml b/res/layout/contact_selection_list_fragment.xml index 6d6536b6a7..ee9d18b434 100644 --- a/res/layout/contact_selection_list_fragment.xml +++ b/res/layout/contact_selection_list_fragment.xml @@ -1,92 +1,58 @@ - - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - - - - - - - + android:layout_centerInParent="true" + android:gravity="center_horizontal|center_vertical" + android:orientation="vertical"> - + + - + + - + - + + - - - - -