decode private zaps and show in notifications + show zap messages

This commit is contained in:
Believethehype 2023-04-23 22:48:53 +02:00
parent 37bd7e34a0
commit a13dbf2bda
5 changed files with 66 additions and 24 deletions

View File

@ -594,17 +594,6 @@ object LocalCache {
fun consume(event: LnZapEvent) { fun consume(event: LnZapEvent) {
val note = getOrCreateNote(event.id) val note = getOrCreateNote(event.id)
var decryptedContent = LnZapRequestEvent.checkForPrivateZap(event.zapRequest!!, account.loggedIn.privKey!!)
if (decryptedContent != null) {
Log.e(
"DC",
"Decrypted Content from Anon Tag: Sender: {${decryptedContent.pubKey}}, Message: {${decryptedContent.content}} "
// TODO Update Notification with this Sender and Message
)
}
// Already processed this event. // Already processed this event.
if (note.event != null) return if (note.event != null) return

View File

@ -19,7 +19,7 @@ open class Event(
@SerializedName("created_at") val createdAt: Long, @SerializedName("created_at") val createdAt: Long,
val kind: Int, val kind: Int,
val tags: List<List<String>>, val tags: List<List<String>>,
val content: String, var content: String,
val sig: HexKey val sig: HexKey
) : EventInterface { ) : EventInterface {
override fun id(): HexKey = id override fun id(): HexKey = id

View File

@ -36,8 +36,13 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
import com.vitorpamplona.amethyst.service.model.Event
import com.vitorpamplona.amethyst.service.model.LnZapEvent
import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
import com.vitorpamplona.amethyst.service.model.PrivateDmEvent import com.vitorpamplona.amethyst.service.model.PrivateDmEvent
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
@ -135,7 +140,16 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
) )
} }
AuthorGallery(multiSetCard.zapEvents.keys, navController, account) for (i in multiSetCard.zapEvents) {
var decryptedContent = (i.value.event as LnZapEvent).zapRequest?.let {
LnZapRequestEvent.checkForPrivateZap(it, NostrAccountDataSource.account.loggedIn.privKey!!)
}
if (decryptedContent != null) {
(i.key.event as Event).content = decryptedContent.content
i.key.author = LocalCache.getOrCreateUser(decryptedContent.pubKey)
}
}
AuthorGallery(multiSetCard.zapEvents.keys, navController, account, accountViewModel, "zap")
} }
} }
@ -156,7 +170,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
) )
} }
AuthorGallery(multiSetCard.boostEvents, navController, account) AuthorGallery(multiSetCard.boostEvents, navController, account, accountViewModel)
} }
} }
@ -177,7 +191,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
) )
} }
AuthorGallery(multiSetCard.likeEvents, navController, account) AuthorGallery(multiSetCard.likeEvents, navController, account, accountViewModel)
} }
} }
@ -211,7 +225,9 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
fun AuthorGallery( fun AuthorGallery(
authorNotes: Collection<Note>, authorNotes: Collection<Note>,
navController: NavController, navController: NavController,
account: Account account: Account,
accountViewModel: AccountViewModel,
kind: String = "nonzap"
) { ) {
val accountState by account.userProfile().live().follows.observeAsState() val accountState by account.userProfile().live().follows.observeAsState()
val accountUser = accountState?.user ?: return val accountUser = accountState?.user ?: return
@ -219,12 +235,39 @@ fun AuthorGallery(
Column(modifier = Modifier.padding(start = 10.dp)) { Column(modifier = Modifier.padding(start = 10.dp)) {
FlowRow() { FlowRow() {
authorNotes.forEach { authorNotes.forEach {
FastNoteAuthorPicture( if (it.event?.content() != "" && kind == "zap") {
note = it, Row(Modifier.fillMaxWidth()) {
navController = navController, FastNoteAuthorPicture(
userAccount = accountUser, note = it,
size = 35.dp navController = navController,
) userAccount = accountUser,
size = 35.dp
)
}
} else {
Row() {
FastNoteAuthorPicture(
note = it,
navController = navController,
userAccount = accountUser,
size = 35.dp
)
}
}
if (it.event?.content() != "" && kind == "zap") {
Row(Modifier.fillMaxWidth()) {
it.event?.let {
TranslatableRichTextViewer(
content = it.content(),
canPreview = true,
tags = null,
backgroundColor = MaterialTheme.colors.background,
accountViewModel = accountViewModel,
navController = navController
)
}
}
}
} }
} }
} }
@ -245,7 +288,6 @@ fun FastNoteAuthorPicture(
val user = userState?.user ?: return val user = userState?.user ?: return
val showFollowingMark = userAccount.isFollowingCached(user) || user === userAccount val showFollowingMark = userAccount.isFollowingCached(user) || user === userAccount
UserPicture( UserPicture(
userHex = user.pubkeyHex, userHex = user.pubkeyHex,
userPicture = user.profilePicture(), userPicture = user.profilePicture(),

View File

@ -164,7 +164,15 @@ fun ZapCustomDialog(onClose: () -> Unit, account: Account, accountViewModel: Acc
) { ) {
OutlinedTextField( OutlinedTextField(
// stringResource(R.string.new_amount_in_sats // stringResource(R.string.new_amount_in_sats
label = { Text(text = stringResource(id = R.string.custom_zaps_add_a_message)) }, label = {
if (selectedZapType == LnZapEvent.ZapType.PUBLIC || selectedZapType == LnZapEvent.ZapType.ANONYMOUS) {
Text(text = stringResource(id = R.string.custom_zaps_add_a_message))
} else if (selectedZapType == LnZapEvent.ZapType.PRIVATE) {
Text(text = stringResource(id = R.string.custom_zaps_add_a_message_private))
} else if (selectedZapType == LnZapEvent.ZapType.NONZAP) {
Text(text = stringResource(id = R.string.custom_zaps_add_a_message_nonzap))
}
},
value = postViewModel.customMessage, value = postViewModel.customMessage,
onValueChange = { onValueChange = {
postViewModel.customMessage = it postViewModel.customMessage = it

View File

@ -287,6 +287,9 @@
<string name="looking_for_event">"Looking for Event %1$s"</string> <string name="looking_for_event">"Looking for Event %1$s"</string>
<string name="custom_zaps_add_a_message">Add a public message</string> <string name="custom_zaps_add_a_message">Add a public message</string>
<string name="custom_zaps_add_a_message_private">Add a private message</string>
<string name="custom_zaps_add_a_message_nonzap">Add an invoice message</string>
<string name="custom_zaps_add_a_message_example">Thank you for all your work!</string> <string name="custom_zaps_add_a_message_example">Thank you for all your work!</string>
<string name="lightning_create_and_add_invoice">Create and Add</string> <string name="lightning_create_and_add_invoice">Create and Add</string>