mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
Simple refactoring of the zap author and comment calculator function
This commit is contained in:
parent
3a84595aac
commit
57dac276b2
@ -162,7 +162,6 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, showHi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Galeries(
|
private fun Galeries(
|
||||||
multiSetCard: MultiSetCard,
|
multiSetCard: MultiSetCard,
|
||||||
@ -259,7 +258,9 @@ fun RenderZapGallery(
|
|||||||
) {
|
) {
|
||||||
ZappedIcon(
|
ZappedIcon(
|
||||||
modifier = remember {
|
modifier = remember {
|
||||||
Modifier.size(Size25dp).align(Alignment.TopEnd)
|
Modifier
|
||||||
|
.size(Size25dp)
|
||||||
|
.align(Alignment.TopEnd)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -281,7 +282,11 @@ fun RenderBoostGallery(
|
|||||||
modifier = NotificationIconModifierSmaller
|
modifier = NotificationIconModifierSmaller
|
||||||
) {
|
) {
|
||||||
RepostedIcon(
|
RepostedIcon(
|
||||||
modifier = remember { Modifier.size(Size19dp).align(Alignment.TopEnd) }
|
modifier = remember {
|
||||||
|
Modifier
|
||||||
|
.size(Size19dp)
|
||||||
|
.align(Alignment.TopEnd)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,20 +349,9 @@ private fun ParseAuthorCommentAndAmount(
|
|||||||
|
|
||||||
LaunchedEffect(key1 = zapRequest.idHex, key2 = zapEvent?.idHex) {
|
LaunchedEffect(key1 = zapRequest.idHex, key2 = zapEvent?.idHex) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
(zapRequest.event as? LnZapRequestEvent)?.let {
|
val newState = loadAmountState(zapRequest, zapEvent, accountViewModel)
|
||||||
val decryptedContent = accountViewModel.decryptZap(zapRequest)
|
if (newState != null) {
|
||||||
val amount = (zapEvent?.event as? LnZapEvent)?.amount
|
content.value = newState
|
||||||
if (decryptedContent != null) {
|
|
||||||
val newAuthor = LocalCache.getOrCreateUser(decryptedContent.pubKey)
|
|
||||||
val newState = ZapAmountCommentNotification(newAuthor, decryptedContent.content.ifBlank { null }, showAmountAxis(amount))
|
|
||||||
|
|
||||||
launch(Dispatchers.Main) { content.value = newState }
|
|
||||||
} else {
|
|
||||||
if (!zapRequest.event?.content().isNullOrBlank() || amount != null) {
|
|
||||||
val newState = ZapAmountCommentNotification(zapRequest.author, zapRequest.event?.content()?.ifBlank { null }, showAmountAxis(amount))
|
|
||||||
launch(Dispatchers.Main) { content.value = newState }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -365,6 +359,34 @@ private fun ParseAuthorCommentAndAmount(
|
|||||||
onReady(content)
|
onReady(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun loadAmountState(
|
||||||
|
zapRequest: Note,
|
||||||
|
zapEvent: Note?,
|
||||||
|
accountViewModel: AccountViewModel
|
||||||
|
): ZapAmountCommentNotification? {
|
||||||
|
(zapRequest.event as? LnZapRequestEvent)?.let {
|
||||||
|
val decryptedContent = accountViewModel.decryptZap(zapRequest)
|
||||||
|
val amount = (zapEvent?.event as? LnZapEvent)?.amount
|
||||||
|
if (decryptedContent != null) {
|
||||||
|
val newAuthor = LocalCache.getOrCreateUser(decryptedContent.pubKey)
|
||||||
|
return ZapAmountCommentNotification(
|
||||||
|
newAuthor,
|
||||||
|
decryptedContent.content.ifBlank { null },
|
||||||
|
showAmountAxis(amount)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (!zapRequest.event?.content().isNullOrBlank() || amount != null) {
|
||||||
|
return ZapAmountCommentNotification(
|
||||||
|
zapRequest.author,
|
||||||
|
zapRequest.event?.content()?.ifBlank { null },
|
||||||
|
showAmountAxis(amount)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RenderState(
|
private fun RenderState(
|
||||||
content: MutableState<ZapAmountCommentNotification>,
|
content: MutableState<ZapAmountCommentNotification>,
|
||||||
|
Loading…
Reference in New Issue
Block a user