Skip to content

extractNostrRefs function should add the event's author to pubkeys #137

@TheAwiteb

Description

@TheAwiteb

The Nostr nevent can contain the event's author, which should be added after verification. For URIs that don't contain the event author, wisp should search for the event author and add it if found.

https://github.com/barrydeen/wisp/blob/fd81e8f/app/src/main/kotlin/com/wisp/app/viewmodel/ComposeViewModel.kt#L453-L468

    private fun extractNostrRefs(content: String): Pair<Set<String>, Set<String>> {
        val pubkeys = mutableSetOf<String>()
        val eventIds = mutableSetOf<String>()
        for (match in NOSTR_URI_REGEX.findAll(content)) {
            val bech32 = match.groupValues[1]
            try {
                when (val data = Nip19.decodeNostrUri("nostr:$bech32")) {
                    is com.wisp.app.nostr.NostrUriData.ProfileRef -> pubkeys.add(data.pubkey)
                    is com.wisp.app.nostr.NostrUriData.NoteRef -> eventIds.add(data.eventId)
                    is com.wisp.app.nostr.NostrUriData.AddressRef -> {}
                    null -> {}
                }
            } catch (_: Exception) {}
        }
        return pubkeys to eventIds
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions