|
|
|
@ -26,6 +26,7 @@ import org.session.libsession.utilities.Address
|
|
|
|
|
import org.session.libsession.utilities.ProfileKeyUtil
|
|
|
|
|
import org.session.libsession.utilities.ProfilePictureUtilities
|
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
|
|
|
import org.session.libsession.utilities.truncateIdForDisplay
|
|
|
|
|
import org.session.libsignal.utilities.ExternalStorageUtil.getImageDir
|
|
|
|
|
import org.session.libsignal.utilities.Log
|
|
|
|
@ -52,7 +53,7 @@ class SettingsViewModel @Inject constructor(
|
|
|
|
|
|
|
|
|
|
private var tempFile: File? = null
|
|
|
|
|
|
|
|
|
|
val hexEncodedPublicKey: String get() = prefs.getLocalNumber() ?: ""
|
|
|
|
|
val hexEncodedPublicKey: String = prefs.getLocalNumber() ?: ""
|
|
|
|
|
|
|
|
|
|
private val userAddress = Address.fromSerialized(hexEncodedPublicKey)
|
|
|
|
|
|
|
|
|
@ -70,6 +71,10 @@ class SettingsViewModel @Inject constructor(
|
|
|
|
|
val recoveryHidden: StateFlow<Boolean>
|
|
|
|
|
get() = _recoveryHidden
|
|
|
|
|
|
|
|
|
|
private val _avatarData: MutableStateFlow<AvatarData?> = MutableStateFlow(null)
|
|
|
|
|
val avatarData: StateFlow<AvatarData?>
|
|
|
|
|
get() = _avatarData
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refreshes the avatar on the main settings page
|
|
|
|
|
*/
|
|
|
|
@ -77,6 +82,19 @@ class SettingsViewModel @Inject constructor(
|
|
|
|
|
val refreshAvatar: SharedFlow<Unit>
|
|
|
|
|
get() = _refreshAvatar.asSharedFlow()
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
viewModelScope.launch(Dispatchers.Default) {
|
|
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false)
|
|
|
|
|
_avatarData.update {
|
|
|
|
|
AvatarData(
|
|
|
|
|
publicKey = hexEncodedPublicKey,
|
|
|
|
|
displayName = getDisplayName(),
|
|
|
|
|
recipient = recipient
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getDisplayName(): String =
|
|
|
|
|
prefs.getProfileName() ?: truncateIdForDisplay(hexEncodedPublicKey)
|
|
|
|
|
|
|
|
|
@ -249,4 +267,10 @@ class SettingsViewModel @Inject constructor(
|
|
|
|
|
val hasAvatar: Boolean // true if the user has an avatar set already but is in this temp state because they are trying out a new avatar
|
|
|
|
|
) : AvatarDialogState()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data class AvatarData(
|
|
|
|
|
val publicKey: String,
|
|
|
|
|
val displayName: String,
|
|
|
|
|
val recipient: Recipient
|
|
|
|
|
)
|
|
|
|
|
}
|