Compare commits
3 Commits
master
...
fix-extern
| Author | SHA1 | Date | |
|---|---|---|---|
| 5142e2cbc1 | |||
| 4449242581 | |||
| 8e7a1e6d7c |
@@ -61,7 +61,7 @@ class AndroidExternalSigner(
|
||||
): String? {
|
||||
// Try Content Resolver first
|
||||
queryContentResolver(type, payload, pubkey, currentUser)?.let {
|
||||
return it.result
|
||||
return if (resultKey == "event") it.event else it.result
|
||||
}
|
||||
|
||||
// Fall back to Intent
|
||||
|
||||
@@ -4,22 +4,29 @@ import android.content.Intent
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ExternalSignerLauncher {
|
||||
private var launcher: ActivityResultLauncher<Intent>? = null
|
||||
private var pendingResult: CompletableDeferred<ActivityResult>? = null
|
||||
private val mutex = Mutex()
|
||||
|
||||
fun register(launcher: ActivityResultLauncher<Intent>) {
|
||||
this.launcher = launcher
|
||||
}
|
||||
|
||||
suspend fun launch(intent: Intent): ActivityResult {
|
||||
suspend fun launch(intent: Intent): ActivityResult = mutex.withLock {
|
||||
withContext(Dispatchers.Main) {
|
||||
val deferred = CompletableDeferred<ActivityResult>()
|
||||
pendingResult = deferred
|
||||
launcher?.launch(intent)
|
||||
?: throw IllegalStateException("ExternalSignerLauncher not registered")
|
||||
return deferred.await()
|
||||
launcher?.launch(intent) ?: throw IllegalStateException("Signer not registered")
|
||||
deferred.await()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun onResult(result: ActivityResult) {
|
||||
pendingResult?.complete(result)
|
||||
|
||||
@@ -110,9 +110,6 @@ fun ChatScreen(id: Long) {
|
||||
// Start loading spinner
|
||||
loading = true
|
||||
|
||||
// Get msg relays for each member
|
||||
viewModel.chatRoomConnect(id)
|
||||
|
||||
// Get messages
|
||||
val initialMessages = viewModel.getChatRoomMessages(id)
|
||||
messages.clear()
|
||||
@@ -121,6 +118,9 @@ fun ChatScreen(id: Long) {
|
||||
// Stop loading spinner
|
||||
loading = false
|
||||
|
||||
// Get msg relays for each member
|
||||
viewModel.chatRoomConnect(id)
|
||||
|
||||
// Handle new messages
|
||||
viewModel.newEvents.collect { event ->
|
||||
if (event.roomId() == id) {
|
||||
|
||||
@@ -379,9 +379,6 @@ class Nostr {
|
||||
|
||||
private suspend fun setCachedRumor(giftId: EventId, rumor: UnsignedEvent) {
|
||||
try {
|
||||
val currentUser =
|
||||
signer.currentUser ?: throw IllegalStateException("User not signed in")
|
||||
|
||||
// Construct the room id
|
||||
val roomId = rumor.roomId()
|
||||
|
||||
@@ -389,17 +386,17 @@ class Nostr {
|
||||
val tags = listOf(
|
||||
Tag.identifier(giftId.toHex()),
|
||||
Tag.event(rumor.id()!!),
|
||||
Tag.custom("a", listOf(roomId.toString())),
|
||||
Tag.custom("r", listOf(roomId.toString())),
|
||||
Tag.custom("k", listOf("14"))
|
||||
)
|
||||
|
||||
// Set event kind
|
||||
val kind = Kind.fromStd(KindStandard.APPLICATION_SPECIFIC_DATA);
|
||||
|
||||
// Construct event
|
||||
val event = EventBuilder(kind, rumor.asJson())
|
||||
.tags(tags)
|
||||
.finalizeUnsigned(currentUser)
|
||||
.signAsync(Keys.generate())
|
||||
.finalizeAsync(Keys.generate())
|
||||
|
||||
client?.database()?.saveEvent(event)
|
||||
} catch (e: Exception) {
|
||||
@@ -412,12 +409,7 @@ class Nostr {
|
||||
val cachedRumor = getCachedRumor(event.id())
|
||||
if (cachedRumor != null) return cachedRumor
|
||||
|
||||
// Get all signers
|
||||
val signers = listOfNotNull(signer, deviceSigner)
|
||||
if (signers.isEmpty()) return null
|
||||
|
||||
// Try to unwrap the gift with each signer
|
||||
for (signer in signers) {
|
||||
try {
|
||||
val gift = UnwrappedGift.fromGiftWrapAsync(signer = signer, giftWrap = event)
|
||||
val rumor = gift.rumor()
|
||||
@@ -427,8 +419,6 @@ class Nostr {
|
||||
return rumor
|
||||
} catch (e: Exception) {
|
||||
println("Failed to unwrap gift: ${e.message}")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user