mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-01 00:33:43 +02:00
Fixes the PushNotification of GiftWrapped Messages
This commit is contained in:
@@ -26,7 +26,7 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class EventNotificationConsumer(private val applicationContext: Context) {
|
class EventNotificationConsumer(private val applicationContext: Context) {
|
||||||
fun unwrapAndConsume(event: Event) {
|
fun consume(event: Event) {
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.IO)
|
val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (LocalCache.notes[event.id] == null) {
|
if (LocalCache.notes[event.id] == null) {
|
||||||
@@ -48,6 +48,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
|
|
||||||
fun unwrapAndConsume(event: Event, account: Account): Event? {
|
fun unwrapAndConsume(event: Event, account: Account): Event? {
|
||||||
if (account.keyPair.privKey == null) return null
|
if (account.keyPair.privKey == null) return null
|
||||||
|
if (!LocalCache.justVerify(event)) return null
|
||||||
|
|
||||||
return when (event) {
|
return when (event) {
|
||||||
is GiftWrapEvent -> {
|
is GiftWrapEvent -> {
|
||||||
@@ -57,7 +58,9 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
}
|
}
|
||||||
is SealedGossipEvent -> {
|
is SealedGossipEvent -> {
|
||||||
event.cachedGossip(account.keyPair.privKey)?.let {
|
event.cachedGossip(account.keyPair.privKey)?.let {
|
||||||
unwrapAndConsume(it, account)
|
// this is not verifiable
|
||||||
|
LocalCache.justConsume(it, null)
|
||||||
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@@ -74,11 +77,11 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
val acc = LocalPreferences.loadFromEncryptedStorage(it.npub)
|
val acc = LocalPreferences.loadFromEncryptedStorage(it.npub)
|
||||||
|
|
||||||
if (acc != null && acc.userProfile().pubkeyHex == giftWrap.recipientPubKey()) {
|
if (acc != null && acc.userProfile().pubkeyHex == giftWrap.recipientPubKey()) {
|
||||||
val event = unwrapAndConsume(giftWrap, account = acc)
|
val chatEvent = unwrapAndConsume(giftWrap, account = acc)
|
||||||
|
|
||||||
if (event is ChatMessageEvent && acc.keyPair.privKey != null) {
|
if (chatEvent is ChatMessageEvent && acc.keyPair.privKey != null) {
|
||||||
val chatNote = LocalCache.notes[giftWrap.id] ?: return
|
val chatNote = LocalCache.notes[chatEvent.id] ?: return
|
||||||
val chatRoom = event.chatroomKey(acc.keyPair.privKey.toHexKey())
|
val chatRoom = chatEvent.chatroomKey(acc.keyPair.pubKey.toHexKey())
|
||||||
|
|
||||||
val followingKeySet = acc.followingKeySet()
|
val followingKeySet = acc.followingKeySet()
|
||||||
|
|
||||||
@@ -92,7 +95,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
val user = chatNote.author?.toBestDisplayName() ?: ""
|
val user = chatNote.author?.toBestDisplayName() ?: ""
|
||||||
val userPicture = chatNote.author?.profilePicture()
|
val userPicture = chatNote.author?.profilePicture()
|
||||||
val noteUri = chatNote.toNEvent()
|
val noteUri = chatNote.toNEvent()
|
||||||
notificationManager().sendDMNotification(event.id, content, user, userPicture, noteUri, applicationContext)
|
notificationManager().sendDMNotification(chatEvent.id, content, user, userPicture, noteUri, applicationContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notificationManager(): NotificationManager {
|
fun notificationManager(): NotificationManager {
|
||||||
return ContextCompat.getSystemService(applicationContext, NotificationManager::class.java) as NotificationManager
|
return ContextCompat.getSystemService(applicationContext, NotificationManager::class.java) as NotificationManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user