Checks if the relay list in NIP-28 groups is empty and uses default when needed.

This commit is contained in:
Vitor Pamplona
2025-08-18 19:24:57 -04:00
parent f31fa4a9c6
commit 667c15b3a1
3 changed files with 12 additions and 9 deletions
@@ -29,7 +29,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip28PublicChat.admin.ChannelCreateEvent import com.vitorpamplona.quartz.nip28PublicChat.admin.ChannelCreateEvent
import com.vitorpamplona.quartz.utils.mapOfSet import com.vitorpamplona.quartz.utils.mapOfSet
fun filterFollowingPublicChats( fun filterFollowingPublicChatsCreationEvent(
followingChannels: Set<HexKey>, followingChannels: Set<HexKey>,
since: SincePerRelayMap?, since: SincePerRelayMap?,
): List<RelayBasedFilter>? { ): List<RelayBasedFilter>? {
@@ -38,13 +38,16 @@ fun filterFollowingPublicChats(
val relayRoomDTags = val relayRoomDTags =
mapOfSet { mapOfSet {
followingChannels.forEach { channelId -> followingChannels.forEach { channelId ->
val relays = val channel = LocalCache.getPublicChatChannelIfExists(channelId)
LocalCache.getPublicChatChannelIfExists(channelId)?.relays() if (channel?.event == null) {
?: LocalCache.relayHints.hintsForEvent(channelId).ifEmpty { null } val relays =
?: Constants.eventFinderRelays channel?.relays()?.ifEmpty { null }
?: LocalCache.relayHints.hintsForEvent(channelId).ifEmpty { null }
?: Constants.eventFinderRelays
relays.forEach { relayUrl -> relays.forEach { relayUrl ->
add(relayUrl, channelId) add(relayUrl, channelId)
}
} }
} }
} }
@@ -40,7 +40,7 @@ fun filterLastMessageFollowingPublicChats(
mapOfSet { mapOfSet {
followingChannels.forEach { channelId -> followingChannels.forEach { channelId ->
val relays = val relays =
LocalCache.getPublicChatChannelIfExists(channelId)?.relays() LocalCache.getPublicChatChannelIfExists(channelId)?.relays()?.ifEmpty { null }
?: LocalCache.relayHints.hintsForEvent(channelId).ifEmpty { null } ?: LocalCache.relayHints.hintsForEvent(channelId).ifEmpty { null }
?: Constants.eventFinderRelays ?: Constants.eventFinderRelays
@@ -43,7 +43,7 @@ class FollowingPublicChatSubAssembler(
): List<RelayBasedFilter>? = ): List<RelayBasedFilter>? =
listOfNotNull( listOfNotNull(
filterLastMessageFollowingPublicChats(key.account.publicChatList.flowSet.value, since), filterLastMessageFollowingPublicChats(key.account.publicChatList.flowSet.value, since),
filterFollowingPublicChats(key.account.publicChatList.flowSet.value, since), filterFollowingPublicChatsCreationEvent(key.account.publicChatList.flowSet.value, since),
).flatten() ).flatten()
override fun user(key: ChatroomListState) = key.account.userProfile() override fun user(key: ChatroomListState) = key.account.userProfile()