diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index fd1b4591d4..01ba805546 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -491,15 +491,6 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, return threadId } - override fun getDisplayName(publicKey: String): String? { - val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey) - contact?.let { - val contactContext = Contact.contextForRecipient(Recipient.from(context, fromSerialized(publicKey), false)) - return it.displayName(contactContext) - } - return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey) - } - override fun getProfilePictureURL(publicKey: String): String? { return DatabaseFactory.getLokiUserDatabase(context).getProfilePictureURL(publicKey) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionContactDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionContactDatabase.kt index 687046d5f6..7d5e93b502 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionContactDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionContactDatabase.kt @@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.loki.utilities.* class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { + companion object { private const val sessionContactTable = "session_contact_database" const val sessionID = "session_id" @@ -22,19 +23,19 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da const val isTrusted = "is_trusted" @JvmStatic val createSessionContactTableCommand = "CREATE TABLE $sessionContactTable " + - "($sessionID STRING PRIMARY KEY, " + - "$name TEXT DEFAULT NULL, " + - "$nickname TEXT DEFAULT NULL, " + - "$profilePictureURL TEXT DEFAULT NULL, " + - "$profilePictureFileName TEXT DEFAULT NULL, " + - "$profilePictureEncryptionKey BLOB DEFAULT NULL, " + - "$threadID INTEGER DEFAULT -1, " + - "$isTrusted INTEGER DEFAULT 0);" + "($sessionID STRING PRIMARY KEY, " + + "$name TEXT DEFAULT NULL, " + + "$nickname TEXT DEFAULT NULL, " + + "$profilePictureURL TEXT DEFAULT NULL, " + + "$profilePictureFileName TEXT DEFAULT NULL, " + + "$profilePictureEncryptionKey BLOB DEFAULT NULL, " + + "$threadID INTEGER DEFAULT -1, " + + "$isTrusted INTEGER DEFAULT 0);" } fun getContactWithSessionID(sessionID: String): Contact? { val database = databaseHelper.readableDatabase - return database.get(sessionContactTable, "${SessionContactDatabase.sessionID} = ?", arrayOf(sessionID)) { cursor -> + return database.get(sessionContactTable, "${SessionContactDatabase.sessionID} = ?", arrayOf( sessionID )) { cursor -> contactFromCursor(cursor) } } @@ -59,7 +60,7 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da } contentValues.put(threadID, threadID) contentValues.put(isTrusted, if (contact.isTrusted) 1 else 0) - database.insertOrUpdate(sessionContactTable, contentValues, "$sessionID = ?", arrayOf(contact.sessionID)) + database.insertOrUpdate(sessionContactTable, contentValues, "$sessionID = ?", arrayOf( contact.sessionID )) notifyConversationListListeners() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/UserDetailsBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/UserDetailsBottomSheet.kt index 17a085e0a9..db5bcc55ae 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/UserDetailsBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/UserDetailsBottomSheet.kt @@ -19,7 +19,7 @@ import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.SSKEnvironment import org.thoughtcrime.securesms.mms.GlideApp -public class UserDetailsBottomSheet : BottomSheetDialogFragment() { +class UserDetailsBottomSheet : BottomSheetDialogFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_user_details_bottom_sheet, container, false) @@ -75,7 +75,7 @@ public class UserDetailsBottomSheet : BottomSheetDialogFragment() { nameTextViewContainer.visibility = View.VISIBLE nameEditContainer.visibility = View.INVISIBLE var newNickName: String? = null - if (!nameEditText.text.isEmpty()) { + if (nameEditText.text.isNotEmpty()) { newNickName = nameEditText.text.toString() } SSKEnvironment.shared.profileManager.setDisplayName(requireContext(), recipient, newNickName) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/views/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/views/UserView.kt index b99a9d3b20..7a6ced6d85 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/views/UserView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/views/UserView.kt @@ -55,8 +55,7 @@ class UserView : LinearLayout { } else { val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey) contact?.let { - val contactContext = Contact.contextForRecipient(user) - return it.displayName(contactContext) + return it.displayName(Contact.ContactContext.REGULAR) } val result = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey) return result ?: publicKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt index cda261994b..af1f8e7cda 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt @@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob -class ProfileManager: SSKEnvironment.ProfileManagerProtocol { +class ProfileManager : SSKEnvironment.ProfileManagerProtocol { override fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) { val sessionID = recipient.address.serialize() diff --git a/app/src/main/res/layout/conversation_activity.xml b/app/src/main/res/layout/conversation_activity.xml index 742700a126..e261a8f384 100644 --- a/app/src/main/res/layout/conversation_activity.xml +++ b/app/src/main/res/layout/conversation_activity.xml @@ -97,26 +97,6 @@ android:layout_height="match_parent" android:layout_weight="1" /> - - - - - - - - diff --git a/libsession/src/main/java/org/session/libsession/messaging/contacts/Contact.kt b/libsession/src/main/java/org/session/libsession/messaging/contacts/Contact.kt index 771edb85a4..ea15d11f03 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/contacts/Contact.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/contacts/Contact.kt @@ -3,28 +3,44 @@ package org.session.libsession.messaging.contacts import org.session.libsession.utilities.recipients.Recipient class Contact(val sessionID: String) { - // The URL from which to fetch the contact's profile picture. + /** + * The URL from which to fetch the contact's profile picture. + */ var profilePictureURL: String? = null - // The file name of the contact's profile picture on local storage. + /** + * The file name of the contact's profile picture on local storage. + */ var profilePictureFileName: String? = null - // The key with which the profile picture is encrypted. + /** + * The key with which the profile picture is encrypted. + */ var profilePictureEncryptionKey: ByteArray? = null - // The ID of the thread associated with this contact. + /** + * The ID of the thread associated with this contact. + */ var threadID: Long? = null - // This flag is used to determine whether we should auto-download files sent by this contact. + /** + * This flag is used to determine whether we should auto-download files sent by this contact. + */ var isTrusted = false - // region: Name - // The name of the contact. Use this whenever you need the "real", underlying name of a user (e.g. when sending a message). + // region Name + /** + * The name of the contact. Use this whenever you need the "real", underlying name of a user (e.g. when sending a message). + */ var name: String? = null - // The contact's nickname, if the user set one. + /** + * The contact's nickname, if the user set one. + */ var nickname: String? = null - // The name to display in the UI. For local use only. + /** + * The name to display in the UI. For local use only. + */ fun displayName(context: ContactContext): String? { this.nickname?.let { return it } - return when { - context == ContactContext.REGULAR -> this.name - context == ContactContext.OPEN_GROUP -> { + return when (context) { + ContactContext.REGULAR -> this.name + ContactContext.OPEN_GROUP -> { // In open groups, where it's more likely that multiple users have the same name, // we display a bit of the Session ID after a user's display name for added context. this.name?.let { @@ -32,10 +48,9 @@ class Contact(val sessionID: String) { } return null } - else -> throw Exception("Unknown contact context!") } } - //end region + // endregion enum class ContactContext { REGULAR, OPEN_GROUP @@ -48,11 +63,7 @@ class Contact(val sessionID: String) { } override fun equals(other: Any?): Boolean { - return if (other is Contact) { - other.sessionID == this.sessionID - } else { - false - } + return this.sessionID == (other as? Contact)?.sessionID } override fun hashCode(): Int { @@ -64,9 +75,13 @@ class Contact(val sessionID: String) { } companion object { + fun contextForRecipient(recipient: Recipient): ContactContext { - return if (recipient.isOpenGroupRecipient) { ContactContext.OPEN_GROUP } - else { ContactContext.REGULAR } + return if (recipient.isOpenGroupRecipient) { + ContactContext.OPEN_GROUP + } else { + ContactContext.REGULAR + } } } } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/utilities/SSKEnvironment.kt b/libsession/src/main/java/org/session/libsession/utilities/SSKEnvironment.kt index 86af00a32d..f674df6f88 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/SSKEnvironment.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/SSKEnvironment.kt @@ -30,7 +30,6 @@ class SSKEnvironment( } fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) // Client-side Nickname - fun setProfileName(context: Context, recipient: Recipient, profileName: String) fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String) fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray) fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)