Migrates the pubkeyHex from keypair to the signer.

This commit is contained in:
Vitor Pamplona
2024-08-16 15:58:23 -04:00
parent 990db68a4d
commit 0bff3462b1
3 changed files with 13 additions and 15 deletions

View File

@@ -431,7 +431,7 @@ class Account(
emit(
LiveFollowLists(
verifiedFollowingUsers,
verifiedFollowingUsers + keyPair.pubKeyHex,
verifiedFollowingUsers + signer.pubKey,
it.user.latestContactList
?.unverifiedFollowTagSet()
?.map { it.lowercase() }
@@ -446,7 +446,7 @@ class Account(
)
}
val liveKind3Follows = liveKind3FollowsFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
val liveKind3Follows = liveKind3FollowsFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
@OptIn(ExperimentalCoroutinesApi::class)
private val liveHomeList: Flow<ListNameNotePair> =
@@ -477,11 +477,11 @@ class Account(
} else if (peopleListFollows.listName == KIND3_FOLLOWS) {
emit(kind3Follows)
} else if (peopleListFollows.event == null) {
emit(LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
emit(LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
} else {
val result = waitToDecrypt(peopleListFollows.event)
if (result == null) {
emit(LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
emit(LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
} else {
emit(result)
}
@@ -493,7 +493,7 @@ class Account(
}
val liveHomeFollowLists: StateFlow<LiveFollowLists?> by lazy {
liveHomeFollowListFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
liveHomeFollowListFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
}
/**
@@ -605,7 +605,7 @@ class Account(
val liveNotificationFollowLists: StateFlow<LiveFollowLists?> by lazy {
combinePeopleListFlows(liveKind3FollowsFlow, liveNotificationList)
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
}
@OptIn(ExperimentalCoroutinesApi::class)
@@ -617,7 +617,7 @@ class Account(
val liveStoriesFollowLists: StateFlow<LiveFollowLists?> by lazy {
combinePeopleListFlows(liveKind3FollowsFlow, liveStoriesList)
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
}
@OptIn(ExperimentalCoroutinesApi::class)
@@ -654,7 +654,7 @@ class Account(
val liveDiscoveryFollowLists: StateFlow<LiveFollowLists?> by lazy {
combinePeopleListFlows(liveKind3FollowsFlow, liveDiscoveryList)
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))
.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(signer.pubKey)))
}
@OptIn(ExperimentalCoroutinesApi::class)
@@ -877,7 +877,7 @@ class Account(
suspend fun countFollowersOf(pubkey: HexKey): Int = LocalCache.users.count { _, it -> it.latestContactList?.isTaggedUser(pubkey) ?: false }
suspend fun followerCount(): Int = countFollowersOf(keyPair.pubKeyHex)
suspend fun followerCount(): Int = countFollowersOf(signer.pubKey)
fun sendNewUserMetadata(
name: String? = null,
@@ -3175,7 +3175,7 @@ class Account(
}
}
fun getAllPeopleLists(): List<AddressableNote> = getAllPeopleLists(keyPair.pubKeyHex)
fun getAllPeopleLists(): List<AddressableNote> = getAllPeopleLists(signer.pubKey)
fun getAllPeopleLists(pubkey: HexKey): List<AddressableNote> =
LocalCache.addressables

View File

@@ -804,7 +804,9 @@ class AccountViewModel(
viewModelScope.launch(Dispatchers.IO) { account.hideWord(word) }
}
fun isLoggedUser(user: User?): Boolean = account.userProfile().pubkeyHex == user?.pubkeyHex
fun isLoggedUser(pubkeyHex: HexKey?): Boolean = account.signer.pubKey == pubkeyHex
fun isLoggedUser(user: User?): Boolean = isLoggedUser(user?.pubkeyHex)
fun isFollowing(user: User?): Boolean {
if (user == null) return false

View File

@@ -20,7 +20,6 @@
*/
package com.vitorpamplona.quartz.crypto
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.toHexKey
class KeyPair(
@@ -30,7 +29,6 @@ class KeyPair(
) {
val privKey: ByteArray?
val pubKey: ByteArray
val pubKeyHex: HexKey
init {
if (privKey == null) {
@@ -54,8 +52,6 @@ class KeyPair(
this.pubKey = pubKey
}
}
this.pubKeyHex = this.pubKey.toHexKey().intern()
}
override fun toString(): String = "KeyPair(privateKey=${privKey?.toHexKey()}, publicKey=${pubKey.toHexKey()}"