mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 19:06:34 +02:00
Fixes follow/unfollow from hashtags and geohashes
This commit is contained in:
@@ -429,56 +429,47 @@ fun observeUserIsFollowing(
|
|||||||
return flow.collectAsStateWithLifecycle(user1.isFollowing(user2))
|
return flow.collectAsStateWithLifecycle(user1.isFollowing(user2))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StateFlowValueCalledInComposition")
|
||||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun observeUserIsFollowingHashtag(
|
fun observeUserIsFollowingHashtag(
|
||||||
user: User,
|
|
||||||
hashtag: String,
|
hashtag: String,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
): State<Boolean> {
|
): State<Boolean> {
|
||||||
// Subscribe in the relay for changes in the metadata of this user.
|
|
||||||
UserFinderFilterAssemblerSubscription(user, accountViewModel)
|
|
||||||
|
|
||||||
// Subscribe in the LocalCache for changes that arrive in the device
|
// Subscribe in the LocalCache for changes that arrive in the device
|
||||||
val flow =
|
val flow =
|
||||||
remember(user) {
|
remember(accountViewModel) {
|
||||||
user
|
accountViewModel.account.hashtagList.flow
|
||||||
.flow()
|
.mapLatest { hashtags ->
|
||||||
.follows.stateFlow
|
hashtag in hashtags
|
||||||
.sample(1000)
|
}.onStart {
|
||||||
.mapLatest { userState ->
|
emit(hashtag in accountViewModel.account.hashtagList.flow.value)
|
||||||
userState.user.isFollowingHashtag(hashtag)
|
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
return flow.collectAsStateWithLifecycle(user.isFollowingHashtag(hashtag))
|
return flow.collectAsStateWithLifecycle(hashtag in accountViewModel.account.hashtagList.flow.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StateFlowValueCalledInComposition")
|
||||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun observeUserIsFollowingGeohash(
|
fun observeUserIsFollowingGeohash(
|
||||||
user: User,
|
|
||||||
geohash: String,
|
geohash: String,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
): State<Boolean> {
|
): State<Boolean> {
|
||||||
// Subscribe in the relay for changes in the metadata of this user.
|
|
||||||
UserFinderFilterAssemblerSubscription(user, accountViewModel)
|
|
||||||
|
|
||||||
// Subscribe in the LocalCache for changes that arrive in the device
|
|
||||||
val flow =
|
val flow =
|
||||||
remember(user) {
|
remember(accountViewModel) {
|
||||||
user
|
accountViewModel.account.geohashList.flow
|
||||||
.flow()
|
.mapLatest { geohashes ->
|
||||||
.follows.stateFlow
|
geohash in geohashes
|
||||||
.sample(1000)
|
}.onStart {
|
||||||
.mapLatest { userState ->
|
emit(geohash in accountViewModel.account.geohashList.flow.value)
|
||||||
userState.user.isFollowingGeohash(geohash)
|
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
return flow.collectAsStateWithLifecycle(user.isFollowingGeohash(geohash))
|
return flow.collectAsStateWithLifecycle(geohash in accountViewModel.account.geohashList.flow.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||||
|
@@ -132,7 +132,7 @@ fun GeoHashActionOptions(
|
|||||||
tag: String,
|
tag: String,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
val isFollowingTag by observeUserIsFollowingGeohash(accountViewModel.userProfile(), tag, accountViewModel)
|
val isFollowingTag by observeUserIsFollowingGeohash(tag, accountViewModel)
|
||||||
|
|
||||||
if (isFollowingTag) {
|
if (isFollowingTag) {
|
||||||
UnfollowButton {
|
UnfollowButton {
|
||||||
|
@@ -145,7 +145,7 @@ fun HashtagActionOptions(
|
|||||||
tag: String,
|
tag: String,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
val isFollowingTag by observeUserIsFollowingHashtag(accountViewModel.userProfile(), tag, accountViewModel)
|
val isFollowingTag by observeUserIsFollowingHashtag(tag, accountViewModel)
|
||||||
|
|
||||||
if (isFollowingTag) {
|
if (isFollowingTag) {
|
||||||
UnfollowButton {
|
UnfollowButton {
|
||||||
|
Reference in New Issue
Block a user