Fixes community join/leave issue

This commit is contained in:
Vitor Pamplona
2025-08-21 14:06:47 -04:00
parent 1ef9902ece
commit 816de5bf03
5 changed files with 24 additions and 29 deletions

View File

@@ -22,9 +22,12 @@ package com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.community
import androidx.compose.runtime.Immutable
import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavPerRelayFilter
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
@Immutable
class SingleCommunityTopNavPerRelayFilter(
val community: String,
val authors: Set<String>?,
) : IFeedTopNavPerRelayFilter
) : IFeedTopNavPerRelayFilter {
val communityAddress = Address.parse(community)
}

View File

@@ -54,7 +54,6 @@ import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNoteEvent
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.navigation.navs.EmptyNav.scope
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
import com.vitorpamplona.amethyst.ui.navigation.routes.routeFor
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
@@ -87,8 +86,6 @@ import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefiniti
import com.vitorpamplona.quartz.nip72ModCommunities.definition.tags.ModeratorTag
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Locale
@Composable
@@ -362,10 +359,10 @@ fun WatchAddressableNoteFollows(
accountViewModel: AccountViewModel,
onFollowChanges: @Composable (Boolean) -> Unit,
) {
val state by accountViewModel.account.kind3FollowList.flow
val state by accountViewModel.account.communityList.flowSet
.collectAsStateWithLifecycle()
onFollowChanges(state.communities.contains(note.idHex))
onFollowChanges(state.contains(note.idHex))
}
@Composable
@@ -376,16 +373,9 @@ fun JoinCommunityButton(
) {
Button(
modifier = Modifier.padding(horizontal = 3.dp),
onClick = {
scope.launch(Dispatchers.IO) {
accountViewModel.follow(note)
}
},
onClick = { accountViewModel.follow(note) },
shape = ButtonBorder,
colors =
ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primary,
),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary),
contentPadding = ButtonPadding,
) {
Text(text = stringRes(R.string.join), color = Color.White)
@@ -402,7 +392,7 @@ fun LeaveCommunityButton(
Button(
modifier = Modifier.padding(horizontal = 3.dp),
onClick = { scope.launch(Dispatchers.IO) { accountViewModel.account.unfollow(note) } },
onClick = { accountViewModel.unfollow(note) },
shape = ButtonBorder,
colors =
ButtonDefaults.buttonColors(

View File

@@ -42,7 +42,7 @@ fun filterCommunitiesAllCommunities(
filter =
Filter(
kinds = CommunityPostApprovalEvent.KIND_LIST,
ids = communityList,
tags = mapOf("a" to communityList),
limit = 300,
since = since,
),

View File

@@ -25,11 +25,12 @@ import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent
fun filterClassifiedsByCommunity(
relay: NormalizedRelayUrl,
community: String,
community: Address,
authors: Set<String>?,
since: Long? = null,
): List<RelayBasedFilter> {
@@ -40,9 +41,9 @@ fun filterClassifiedsByCommunity(
relay = relay,
filter =
Filter(
authors = authors,
authors = listOf(community.pubKeyHex),
kinds = listOf(CommunityDefinitionEvent.KIND),
ids = listOf(community),
tags = mapOf("d" to listOf(community.dTag)),
limit = 300,
since = since,
),
@@ -59,11 +60,13 @@ fun filterCommunitiesByCommunity(
return communitySet.set
.mapNotNull {
filterClassifiedsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
it.value.communityAddress?.let { address ->
filterClassifiedsByCommunity(
relay = it.key,
community = address,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}

View File

@@ -25,7 +25,6 @@ import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip72ModCommunities.approval.CommunityPostApprovalEvent
import com.vitorpamplona.quartz.nip72ModCommunities.definition.CommunityDefinitionEvent
import com.vitorpamplona.quartz.utils.TimeUtils
fun filterCommunitiesGlobal(
@@ -42,7 +41,7 @@ fun filterCommunitiesGlobal(
relay = it.key,
filter =
Filter(
kinds = listOf(CommunityDefinitionEvent.KIND),
kinds = CommunityPostApprovalEvent.KIND_LIST,
limit = 100,
since = since,
),
@@ -51,7 +50,7 @@ fun filterCommunitiesGlobal(
relay = it.key,
filter =
Filter(
kinds = listOf(CommunityPostApprovalEvent.KIND),
kinds = CommunityPostApprovalEvent.KIND_LIST,
limit = 100,
since = since ?: TimeUtils.oneWeekAgo(),
),