Fixes bug on string resources.

This commit is contained in:
Vitor Pamplona
2024-06-28 14:06:08 -04:00
parent f9c3ff22e3
commit f0044afeab
2 changed files with 24 additions and 5 deletions
@@ -205,38 +205,54 @@ class EventNotificationConsumer(
event: LnZapEvent, event: LnZapEvent,
acc: Account, acc: Account,
) { ) {
Log.d("EventNotificationConsumer", "Notify Start ${event.toNostrUri()}")
val noteZapEvent = LocalCache.getNoteIfExists(event.id) ?: return val noteZapEvent = LocalCache.getNoteIfExists(event.id) ?: return
Log.d("EventNotificationConsumer", "Notify Not Notified Yet")
// old event being re-broadcast // old event being re-broadcast
if (event.createdAt < TimeUtils.fifteenMinutesAgo()) return if (event.createdAt < TimeUtils.fifteenMinutesAgo()) return
Log.d("EventNotificationConsumer", "Notify Not an old event")
val noteZapRequest = event.zapRequest?.id?.let { LocalCache.checkGetOrCreateNote(it) } ?: return val noteZapRequest = event.zapRequest?.id?.let { LocalCache.checkGetOrCreateNote(it) } ?: return
val noteZapped = val noteZapped =
event.zappedPost().firstOrNull()?.let { LocalCache.checkGetOrCreateNote(it) } ?: return event.zappedPost().firstOrNull()?.let { LocalCache.checkGetOrCreateNote(it) } ?: return
Log.d("EventNotificationConsumer", "Notify ZapRequest $noteZapRequest zapped $noteZapped")
if ((event.amount ?: BigDecimal.ZERO) < BigDecimal.TEN) return if ((event.amount ?: BigDecimal.ZERO) < BigDecimal.TEN) return
Log.d("EventNotificationConsumer", "Notify Amount Bigger than 10")
if (event.isTaggedUser(acc.userProfile().pubkeyHex)) { if (event.isTaggedUser(acc.userProfile().pubkeyHex)) {
val amount = showAmount(event.amount) val amount = showAmount(event.amount)
Log.d("EventNotificationConsumer", "Notify Amount $amount")
(noteZapRequest.event as? LnZapRequestEvent)?.let { event -> (noteZapRequest.event as? LnZapRequestEvent)?.let { event ->
acc.decryptZapContentAuthor(noteZapRequest) { acc.decryptZapContentAuthor(noteZapRequest) {
Log.d("EventNotificationConsumer", "Notify Decrypted if Private Zap ${event.id}")
val author = LocalCache.getOrCreateUser(it.pubKey) val author = LocalCache.getOrCreateUser(it.pubKey)
val senderInfo = Pair(author, it.content.ifBlank { null }) val senderInfo = Pair(author, it.content.ifBlank { null })
acc.decryptContent(noteZapped) { acc.decryptContent(noteZapped) {
Log.d("EventNotificationConsumer", "Notify Decrypted if Private Note")
val zappedContent = it.split("\n").get(0) val zappedContent = it.split("\n").get(0)
val user = senderInfo.first.toBestDisplayName() val user = senderInfo.first.toBestDisplayName()
var title = var title = stringRes(applicationContext, R.string.app_notification_zaps_channel_message, amount)
stringRes(applicationContext, R.string.app_notification_zaps_channel_message, amount)
senderInfo.second?.ifBlank { null }?.let { title += " ($it)" } senderInfo.second?.ifBlank { null }?.let { title += " ($it)" }
var content = var content =
stringRes( stringRes(
applicationContext, applicationContext,
R.string.app_notification_zaps_channel_message_from, R.string.app_notification_zaps_channel_message_from,
user, user,
) )
zappedContent?.let { zappedContent.let {
content += content +=
" " + " " +
stringRes( stringRes(
@@ -247,6 +263,9 @@ class EventNotificationConsumer(
} }
val userPicture = senderInfo?.first?.profilePicture() val userPicture = senderInfo?.first?.profilePicture()
val noteUri = "nostr:Notifications" val noteUri = "nostr:Notifications"
Log.d("EventNotificationConsumer", "Notify ${event.id} $content $title $noteUri")
notificationManager() notificationManager()
.sendZapNotification( .sendZapNotification(
event.id, event.id,
@@ -73,7 +73,7 @@ fun stringRes(
return String return String
.format( .format(
res.configuration.locales.get(0), res.configuration.locales.get(0),
resourceCache.get(id) ?: res.getString(id), resourceCache.get(id) ?: res.getString(id).also { resourceCache.put(id, it) },
*args, *args,
).also { resourceCache.put(id, it) } )
} }