diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt index 1dd93b5fe..ac4c5dc86 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt @@ -1,6 +1,7 @@ package com.vitorpamplona.amethyst.service import com.vitorpamplona.amethyst.model.Account +import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.service.model.* import com.vitorpamplona.amethyst.service.model.BadgeAwardEvent import com.vitorpamplona.amethyst.service.model.BadgeProfilesEvent @@ -111,16 +112,51 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { ) ) + fun createGiftWrapsToMeFilter() = TypedFilter( + types = COMMON_FEED_TYPES, + filter = JsonFilter( + kinds = listOf(GiftWrapEvent.kind), + tags = mapOf("p" to listOf(account.userProfile().pubkeyHex)) + ) + ) + val accountChannel = requestNewChannel { time, relayUrl -> latestEOSEs.addOrUpdate(account.userProfile(), account.defaultNotificationFollowList, relayUrl, time) } + override fun consume(event: Event, relay: Relay) { + if (LocalCache.justVerify(event)) { + if (event is GiftWrapEvent) { + val privateKey = NostrChatroomListDataSource.account.keyPair.privKey + if (privateKey != null) { + event.cachedGift(privateKey)?.let { + this.consume(it, relay) + } + } + } + + if (event is SealedGossipEvent) { + val privateKey = NostrChatroomListDataSource.account.keyPair.privKey + if (privateKey != null) { + event.cachedGossip(privateKey)?.let { + LocalCache.justConsume(it, relay) + } + } + + // Don't store sealed gossips to avoid rebroadcasting by mistake. + } else { + LocalCache.justConsume(event, relay) + } + } + } + override fun updateChannelFilters() { // gets everthing about the user logged in accountChannel.typedFilters = listOf( createAccountMetadataFilter(), createAccountContactListFilter(), createNotificationFilter(), + createGiftWrapsToMeFilter(), createAccountReportsFilter(), createAccountAcceptedAwardsFilter(), createAccountBookmarkListFilter(), diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt index 162390165..5e0f92f44 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt @@ -1,19 +1,14 @@ package com.vitorpamplona.amethyst.service import com.vitorpamplona.amethyst.model.Account -import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent -import com.vitorpamplona.amethyst.service.model.Event -import com.vitorpamplona.amethyst.service.model.GiftWrapEvent import com.vitorpamplona.amethyst.service.model.PrivateDmEvent -import com.vitorpamplona.amethyst.service.model.SealedGossipEvent import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES import com.vitorpamplona.amethyst.service.relays.EOSEAccount import com.vitorpamplona.amethyst.service.relays.FeedType import com.vitorpamplona.amethyst.service.relays.JsonFilter -import com.vitorpamplona.amethyst.service.relays.Relay import com.vitorpamplona.amethyst.service.relays.TypedFilter object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { @@ -25,7 +20,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { fun createMessagesToMeFilter() = TypedFilter( types = setOf(FeedType.PRIVATE_DMS), filter = JsonFilter( - kinds = listOf(PrivateDmEvent.kind, GiftWrapEvent.kind), + kinds = listOf(PrivateDmEvent.kind), tags = mapOf("p" to listOf(account.userProfile().pubkeyHex)), since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList ) @@ -97,32 +92,6 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { latestEOSEs.addOrUpdate(account.userProfile(), chatRoomList, relayUrl, time) } - override fun consume(event: Event, relay: Relay) { - if (LocalCache.justVerify(event)) { - if (event is GiftWrapEvent) { - val privateKey = account.keyPair.privKey - if (privateKey != null) { - event.cachedGift(privateKey)?.let { - this.consume(it, relay) - } - } - } - - if (event is SealedGossipEvent) { - val privateKey = account.keyPair.privKey - if (privateKey != null) { - event.cachedGossip(privateKey)?.let { - LocalCache.justConsume(it, relay) - } - } - - // Don't store sealed gossips to avoid rebroadcasting by mistake. - } else { - LocalCache.justConsume(event, relay) - } - } - } - override fun updateChannelFilters() { val list = listOf( createMessagesToMeFilter(),