diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 20ca49cd8..6469b5b26 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -736,20 +736,24 @@ object LocalCache { note.addRelay(relay) } + val file = File(Amethyst.instance.applicationContext.externalCacheDir, "NIP95") + + if (!file.exists()) { + try { + val cachePath = File(Amethyst.instance.applicationContext.externalCacheDir, "NIP95") + cachePath.mkdirs() + val stream = FileOutputStream(File(cachePath, event.id)) + stream.write(event.decode()) + stream.close() + Log.e("EventLogger", "Saved to disk as ${File(cachePath, event.id).toUri()}") + } catch (e: IOException) { + Log.e("FileSotrageEvent", "FileStorageEvent save to disk error: " + event.id, e) + } + } + // Already processed this event. if (note.event != null) return - try { - val cachePath = File(Amethyst.instance.applicationContext.externalCacheDir, "NIP95") - cachePath.mkdirs() - val stream = FileOutputStream(File(cachePath, event.id)) - stream.write(event.decode()) - stream.close() - Log.e("EventLogger", "Saved to disk as ${File(cachePath, event.id).toUri()}") - } catch (e: IOException) { - Log.e("FileSotrageEvent", "FileStorageEvent save to disk error: " + event.id, e) - } - // this is an invalid event. But we don't need to keep the data in memory. val eventNoData = FileStorageEvent(event.id, event.pubKey, event.createdAt, event.tags, "", event.sig) 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 45bbb4f1b..aba906e2a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt @@ -75,7 +75,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { filter = JsonFilter( kinds = listOf(ReportEvent.kind), authors = listOf(account.userProfile().pubkeyHex), - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(account.defaultNotificationFollowList)?.relayList ) ) } @@ -96,12 +96,12 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { ), tags = mapOf("p" to listOf(account.userProfile().pubkeyHex)), limit = 400, - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(account.defaultNotificationFollowList)?.relayList ) ) val accountChannel = requestNewChannel { time, relayUrl -> - latestEOSEs.addOrUpdate(account.userProfile(), relayUrl, time) + latestEOSEs.addOrUpdate(account.userProfile(), account.defaultNotificationFollowList, relayUrl, time) } override fun updateChannelFilters() { 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 f89e79b77..bfa173826 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrChatroomListDataSource.kt @@ -15,13 +15,14 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { lateinit var account: Account val latestEOSEs = EOSEAccount() + val chatRoomList = "ChatroomList" fun createMessagesToMeFilter() = TypedFilter( types = setOf(FeedType.PRIVATE_DMS), filter = JsonFilter( kinds = listOf(PrivateDmEvent.kind), tags = mapOf("p" to listOf(account.userProfile().pubkeyHex)), - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList ) ) @@ -30,7 +31,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { filter = JsonFilter( kinds = listOf(PrivateDmEvent.kind), authors = listOf(account.userProfile().pubkeyHex), - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList ) ) @@ -39,7 +40,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { filter = JsonFilter( kinds = listOf(ChannelCreateEvent.kind, ChannelMetadataEvent.kind), authors = listOf(account.userProfile().pubkeyHex), - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList ) ) @@ -48,7 +49,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { filter = JsonFilter( kinds = listOf(ChannelCreateEvent.kind), ids = account.followingChannels.toList(), - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList ) ) @@ -72,7 +73,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { filter = JsonFilter( kinds = listOf(ChannelMessageEvent.kind), tags = mapOf("e" to listOf(it)), - since = latestEOSEs.users[account.userProfile()]?.relayList, + since = latestEOSEs.users[account.userProfile()]?.followList?.get(chatRoomList)?.relayList, limit = 25 // Remember to consider spam that is being removed from the UI ) ) @@ -80,7 +81,7 @@ object NostrChatroomListDataSource : NostrDataSource("MailBoxFeed") { } val chatroomListChannel = requestNewChannel { time, relayUrl -> - latestEOSEs.addOrUpdate(account.userProfile(), relayUrl, time) + latestEOSEs.addOrUpdate(account.userProfile(), chatRoomList, relayUrl, time) } override fun updateChannelFilters() { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt index a4b5e8232..d83151205 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt @@ -59,7 +59,7 @@ object NostrHomeDataSource : NostrDataSource("HomeFeed") { kinds = listOf(TextNoteEvent.kind, LongTextNoteEvent.kind, PollNoteEvent.kind, HighlightEvent.kind), authors = followSet, limit = 400, - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(account.defaultHomeFollowList)?.relayList ) ) } @@ -79,13 +79,13 @@ object NostrHomeDataSource : NostrDataSource("HomeFeed") { }.flatten() ), limit = 100, - since = latestEOSEs.users[account.userProfile()]?.relayList + since = latestEOSEs.users[account.userProfile()]?.followList?.get(account.defaultHomeFollowList)?.relayList ) ) } val followAccountChannel = requestNewChannel { time, relayUrl -> - latestEOSEs.addOrUpdate(account.userProfile(), relayUrl, time) + latestEOSEs.addOrUpdate(account.userProfile(), account.defaultHomeFollowList, relayUrl, time) } override fun updateChannelFilters() { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt index ba2193a97..19ed34f6d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt @@ -19,13 +19,28 @@ class EOSERelayList(var relayList: Map = emptyMap()) { } } -class EOSEAccount(var users: Map = emptyMap()) { - fun addOrUpdate(user: User, relayUrl: String, time: Long) { - val relayList = users[user] +class EOSEFollowList(var followList: Map = emptyMap()) { + fun addOrUpdate(listCode: String, relayUrl: String, time: Long) { + val relayList = followList[listCode] if (relayList == null) { - users = users + mapOf(user to EOSERelayList(mapOf(relayUrl to EOSETime(time)))) + val newList = EOSERelayList() + newList.addOrUpdate(relayUrl, time) + followList = followList + mapOf(listCode to newList) } else { relayList.addOrUpdate(relayUrl, time) } } } + +class EOSEAccount(var users: Map = emptyMap()) { + fun addOrUpdate(user: User, listCode: String, relayUrl: String, time: Long) { + val followList = users[user] + if (followList == null) { + val newList = EOSEFollowList() + newList.addOrUpdate(listCode, relayUrl, time) + users = users + mapOf(user to newList) + } else { + followList.addOrUpdate(listCode, relayUrl, time) + } + } +}