mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 19:38:34 +00:00
Clean
This commit is contained in:
parent
e0c1456af4
commit
c0f894e1b2
@ -491,15 +491,6 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
return threadId
|
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? {
|
override fun getProfilePictureURL(publicKey: String): String? {
|
||||||
return DatabaseFactory.getLokiUserDatabase(context).getProfilePictureURL(publicKey)
|
return DatabaseFactory.getLokiUserDatabase(context).getProfilePictureURL(publicKey)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
|||||||
import org.thoughtcrime.securesms.loki.utilities.*
|
import org.thoughtcrime.securesms.loki.utilities.*
|
||||||
|
|
||||||
class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val sessionContactTable = "session_contact_database"
|
private const val sessionContactTable = "session_contact_database"
|
||||||
const val sessionID = "session_id"
|
const val sessionID = "session_id"
|
||||||
@ -22,19 +23,19 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
|
|||||||
const val isTrusted = "is_trusted"
|
const val isTrusted = "is_trusted"
|
||||||
@JvmStatic val createSessionContactTableCommand =
|
@JvmStatic val createSessionContactTableCommand =
|
||||||
"CREATE TABLE $sessionContactTable " +
|
"CREATE TABLE $sessionContactTable " +
|
||||||
"($sessionID STRING PRIMARY KEY, " +
|
"($sessionID STRING PRIMARY KEY, " +
|
||||||
"$name TEXT DEFAULT NULL, " +
|
"$name TEXT DEFAULT NULL, " +
|
||||||
"$nickname TEXT DEFAULT NULL, " +
|
"$nickname TEXT DEFAULT NULL, " +
|
||||||
"$profilePictureURL TEXT DEFAULT NULL, " +
|
"$profilePictureURL TEXT DEFAULT NULL, " +
|
||||||
"$profilePictureFileName TEXT DEFAULT NULL, " +
|
"$profilePictureFileName TEXT DEFAULT NULL, " +
|
||||||
"$profilePictureEncryptionKey BLOB DEFAULT NULL, " +
|
"$profilePictureEncryptionKey BLOB DEFAULT NULL, " +
|
||||||
"$threadID INTEGER DEFAULT -1, " +
|
"$threadID INTEGER DEFAULT -1, " +
|
||||||
"$isTrusted INTEGER DEFAULT 0);"
|
"$isTrusted INTEGER DEFAULT 0);"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContactWithSessionID(sessionID: String): Contact? {
|
fun getContactWithSessionID(sessionID: String): Contact? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
return database.get(sessionContactTable, "${SessionContactDatabase.sessionID} = ?", arrayOf(sessionID)) { cursor ->
|
return database.get(sessionContactTable, "${SessionContactDatabase.sessionID} = ?", arrayOf( sessionID )) { cursor ->
|
||||||
contactFromCursor(cursor)
|
contactFromCursor(cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
|
|||||||
}
|
}
|
||||||
contentValues.put(threadID, threadID)
|
contentValues.put(threadID, threadID)
|
||||||
contentValues.put(isTrusted, if (contact.isTrusted) 1 else 0)
|
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()
|
notifyConversationListListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import org.session.libsession.utilities.recipients.Recipient
|
|||||||
import org.session.libsession.utilities.SSKEnvironment
|
import org.session.libsession.utilities.SSKEnvironment
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
|
|
||||||
public class UserDetailsBottomSheet : BottomSheetDialogFragment() {
|
class UserDetailsBottomSheet : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_user_details_bottom_sheet, container, false)
|
return inflater.inflate(R.layout.fragment_user_details_bottom_sheet, container, false)
|
||||||
@ -75,7 +75,7 @@ public class UserDetailsBottomSheet : BottomSheetDialogFragment() {
|
|||||||
nameTextViewContainer.visibility = View.VISIBLE
|
nameTextViewContainer.visibility = View.VISIBLE
|
||||||
nameEditContainer.visibility = View.INVISIBLE
|
nameEditContainer.visibility = View.INVISIBLE
|
||||||
var newNickName: String? = null
|
var newNickName: String? = null
|
||||||
if (!nameEditText.text.isEmpty()) {
|
if (nameEditText.text.isNotEmpty()) {
|
||||||
newNickName = nameEditText.text.toString()
|
newNickName = nameEditText.text.toString()
|
||||||
}
|
}
|
||||||
SSKEnvironment.shared.profileManager.setDisplayName(requireContext(), recipient, newNickName)
|
SSKEnvironment.shared.profileManager.setDisplayName(requireContext(), recipient, newNickName)
|
||||||
|
@ -55,8 +55,7 @@ class UserView : LinearLayout {
|
|||||||
} else {
|
} else {
|
||||||
val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey)
|
val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey)
|
||||||
contact?.let {
|
contact?.let {
|
||||||
val contactContext = Contact.contextForRecipient(user)
|
return it.displayName(Contact.ContactContext.REGULAR)
|
||||||
return it.displayName(contactContext)
|
|
||||||
}
|
}
|
||||||
val result = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey)
|
val result = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey)
|
||||||
return result ?: publicKey
|
return result ?: publicKey
|
||||||
|
@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.ApplicationContext
|
|||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
|
||||||
|
|
||||||
class ProfileManager: SSKEnvironment.ProfileManagerProtocol {
|
class ProfileManager : SSKEnvironment.ProfileManagerProtocol {
|
||||||
|
|
||||||
override fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) {
|
override fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) {
|
||||||
val sessionID = recipient.address.serialize()
|
val sessionID = recipient.address.serialize()
|
||||||
|
@ -97,26 +97,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/cancelButtonContainer"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="18dp"
|
|
||||||
android:layout_height="18dp"
|
|
||||||
android:src="@drawable/ic_baseline_clear_24"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:layout_marginLeft="8dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
@ -3,28 +3,44 @@ package org.session.libsession.messaging.contacts
|
|||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
|
|
||||||
class Contact(val sessionID: String) {
|
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
|
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
|
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
|
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
|
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
|
var isTrusted = false
|
||||||
|
|
||||||
// region: Name
|
// 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).
|
/**
|
||||||
|
* 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
|
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
|
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? {
|
fun displayName(context: ContactContext): String? {
|
||||||
this.nickname?.let { return it }
|
this.nickname?.let { return it }
|
||||||
return when {
|
return when (context) {
|
||||||
context == ContactContext.REGULAR -> this.name
|
ContactContext.REGULAR -> this.name
|
||||||
context == ContactContext.OPEN_GROUP -> {
|
ContactContext.OPEN_GROUP -> {
|
||||||
// In open groups, where it's more likely that multiple users have the same name,
|
// 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.
|
// we display a bit of the Session ID after a user's display name for added context.
|
||||||
this.name?.let {
|
this.name?.let {
|
||||||
@ -32,10 +48,9 @@ class Contact(val sessionID: String) {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
else -> throw Exception("Unknown contact context!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//end region
|
// endregion
|
||||||
|
|
||||||
enum class ContactContext {
|
enum class ContactContext {
|
||||||
REGULAR, OPEN_GROUP
|
REGULAR, OPEN_GROUP
|
||||||
@ -48,11 +63,7 @@ class Contact(val sessionID: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return if (other is Contact) {
|
return this.sessionID == (other as? Contact)?.sessionID
|
||||||
other.sessionID == this.sessionID
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@ -64,9 +75,13 @@ class Contact(val sessionID: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun contextForRecipient(recipient: Recipient): ContactContext {
|
fun contextForRecipient(recipient: Recipient): ContactContext {
|
||||||
return if (recipient.isOpenGroupRecipient) { ContactContext.OPEN_GROUP }
|
return if (recipient.isOpenGroupRecipient) {
|
||||||
else { ContactContext.REGULAR }
|
ContactContext.OPEN_GROUP
|
||||||
|
} else {
|
||||||
|
ContactContext.REGULAR
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,7 +30,6 @@ class SSKEnvironment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) // Client-side Nickname
|
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 setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String)
|
||||||
fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray)
|
fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray)
|
||||||
fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)
|
fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user