make editting nickname work

This commit is contained in:
ryanzhao 2021-05-12 15:11:09 +10:00
parent b43000bdd0
commit 4c63b724ee
4 changed files with 12 additions and 6 deletions

View File

@ -49,7 +49,10 @@ public class UserDetailsBottomSheet : BottomSheetDialogFragment() {
nameEditText.clearFocus()
nameTextViewContainer.visibility = View.VISIBLE
nameEditContainer.visibility = View.INVISIBLE
var newNickName = null
var newNickName: String? = null
if (!nameEditText.text.isEmpty()) {
newNickName = nameEditText.text.toString()
}
SSKEnvironment.shared.profileManager.setDisplayName(requireContext(), recipient, newNickName)
nameTextView.text = SSKEnvironment.shared.profileManager.getDisplayName(requireContext(), recipient) ?: "Anonymous"
}

View File

@ -9,6 +9,7 @@ import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.view_conversation.view.*
import network.loki.messenger.R
import org.session.libsession.utilities.SSKEnvironment
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded
@ -56,7 +57,7 @@ class ConversationView : LinearLayout {
}
profilePictureView.glide = glide
profilePictureView.update(thread.recipient, thread.threadId)
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else if (!thread.recipient.name.isNullOrEmpty()) thread.recipient.name else thread.recipient.address.toString()
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else SSKEnvironment.shared.profileManager.getDisplayName(context, thread.recipient) ?: thread.recipient.address.toString()
btnGroupNameDisplay.text = senderDisplayName
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)
muteIndicatorImageView.visibility = if (thread.recipient.isMuted) VISIBLE else GONE

View File

@ -9,10 +9,8 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
class ProfileManager: SSKEnvironment.ProfileManagerProtocol {
override fun setDisplayName(context: Context, recipient: Recipient, displayName: String) {
val database = DatabaseFactory.getLokiUserDatabase(context)
override fun setDisplayName(context: Context, recipient: Recipient, displayName: String?) {
val sessionID = recipient.address.serialize()
database.setDisplayName(sessionID, displayName)
// New API
val contactDatabase = DatabaseFactory.getSessionContactDatabase(context)
var contact = contactDatabase.getContactWithSessionID(sessionID)
@ -21,6 +19,10 @@ class ProfileManager: SSKEnvironment.ProfileManagerProtocol {
contact.nickname = displayName
contactDatabase.setContact(contact)
}
// Old API
if (displayName == null) return
val database = DatabaseFactory.getLokiUserDatabase(context)
database.setDisplayName(sessionID, displayName)
}
override fun setProfileName(context: Context, recipient: Recipient, profileName: String) {

View File

@ -30,7 +30,7 @@ class SSKEnvironment(
const val NAME_PADDED_LENGTH = 26
}
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 setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray)