From 07c3a3ffe5481b5b800be3cf4434d91dd4d730d6 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 24 Apr 2025 17:35:34 -0400 Subject: [PATCH] Fixes unchecked cast and other opt-in tags on observers --- .../reqCommand/channel/ChannelObservers.kt | 3 +++ .../reqCommand/event/EventObservers.kt | 12 ++++++++++ .../reqCommand/user/UserObservers.kt | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt index 1ed54ba0d..bef5df1a5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/channel/ChannelObservers.kt @@ -28,6 +28,7 @@ import com.vitorpamplona.amethyst.model.Channel import com.vitorpamplona.amethyst.model.ChannelState import com.vitorpamplona.amethyst.model.LiveActivitiesChannel import com.vitorpamplona.quartz.nip53LiveActivities.streaming.LiveActivitiesEvent +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.mapLatest @@ -38,6 +39,7 @@ fun observeChannel(baseChannel: Channel): State { return baseChannel.flow.stateFlow.collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeChannelPicture(baseChannel: Channel): State { // Subscribe in the relay for changes in the metadata of this user. @@ -55,6 +57,7 @@ fun observeChannelPicture(baseChannel: Channel): State { return flow.collectAsStateWithLifecycle(baseChannel.profilePicture()) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeChannelInfo(baseChannel: LiveActivitiesChannel): State { // Subscribe in the relay for changes in the metadata of this user. diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt index 8fedff387..e43f6129d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt @@ -29,6 +29,8 @@ import com.vitorpamplona.amethyst.model.NoteState import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.quartz.nip01Core.core.Event import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flowOn @@ -47,6 +49,8 @@ fun observeNote(note: Note): State { .collectAsStateWithLifecycle() } +@Suppress("UNCHECKED_CAST") +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteEvent(note: Note): State { // Subscribe in the relay for changes in this note. @@ -64,6 +68,7 @@ fun observeNoteEvent(note: Note): State { return flow.collectAsStateWithLifecycle(note.event as? T?) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteAndMap( note: Note, @@ -86,6 +91,8 @@ fun observeNoteAndMap( return flow.collectAsStateWithLifecycle(map(note)) } +@Suppress("UNCHECKED_CAST") +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteEventAndMap( note: Note, @@ -109,6 +116,7 @@ fun observeNoteEventAndMap( return flow.collectAsStateWithLifecycle((note.event as? T)?.let { map(it) }) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteHasEvent(note: Note): State { // Subscribe in the relay for changes in this note. @@ -139,6 +147,7 @@ fun observeNoteReplies(note: Note): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteReplyCount(note: Note): State { // Subscribe in the relay for changes in this note. @@ -170,6 +179,7 @@ fun observeNoteReactions(note: Note): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteReactionCount(note: Note): State { // Subscribe in the relay for changes in this note. @@ -215,6 +225,7 @@ fun observeNoteReposts(note: Note): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteRepostsBy( note: Note, @@ -237,6 +248,7 @@ fun observeNoteRepostsBy( return flow.collectAsStateWithLifecycle(note.isBoostedBy(user)) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteRepostCount(note: Note): State { // Subscribe in the relay for changes in this note. diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt index adea0737a..8904190fa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt @@ -36,6 +36,8 @@ import com.vitorpamplona.quartz.nip65RelayList.RelayUrlFormatter import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flowOn @@ -55,6 +57,7 @@ fun observeUser(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserName(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -73,6 +76,7 @@ fun observeUserName(user: User): State { return flow.collectAsStateWithLifecycle(user.toBestDisplayName()) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserNip05(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -91,6 +95,7 @@ fun observeUserNip05(user: User): State { return flow.collectAsStateWithLifecycle(user.info?.nip05) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserAboutMe(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -109,6 +114,7 @@ fun observeUserAboutMe(user: User): State { return flow.collectAsStateWithLifecycle(user.info?.about ?: "") } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserInfo(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -127,6 +133,7 @@ fun observeUserInfo(user: User): State { return flow.collectAsStateWithLifecycle(user.info) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserBanner(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -145,6 +152,7 @@ fun observeUserBanner(user: User): State { return flow.collectAsStateWithLifecycle(user.info?.banner) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserPicture(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -163,6 +171,7 @@ fun observeUserPicture(user: User): State { return flow.collectAsStateWithLifecycle(user.info?.picture) } +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeUserShortName(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -193,6 +202,7 @@ fun observeUserFollows(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserFollowCount(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -214,6 +224,7 @@ fun observeUserFollowCount(user: User): State { return flow.collectAsStateWithLifecycle(0) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserTagFollows(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -247,6 +258,7 @@ fun observeUserBookmarks(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserBookmarkCount(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -280,6 +292,7 @@ fun observeUserFollowers(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserFollowerCount(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -301,6 +314,7 @@ fun observeUserFollowerCount(user: User): State { return flow.collectAsStateWithLifecycle(0) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserIsFollowing( user1: User, @@ -325,6 +339,7 @@ fun observeUserIsFollowing( return flow.collectAsStateWithLifecycle(user1.isFollowing(user2)) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserIsFollowingHashtag( user: User, @@ -349,6 +364,7 @@ fun observeUserIsFollowingHashtag( return flow.collectAsStateWithLifecycle(user.isFollowingHashtag(hashtag)) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserIsFollowingGeohash( user: User, @@ -373,6 +389,7 @@ fun observeUserIsFollowingGeohash( return flow.collectAsStateWithLifecycle(user.isFollowingGeohash(geohash)) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserIsFollowingChannel( user: User, @@ -409,6 +426,7 @@ fun observeUserZaps(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserZapAmount(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -442,6 +460,7 @@ fun observeUserReports(user: User): State { .collectAsStateWithLifecycle() } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserReportCount(user: User): State { // Subscribe in the relay for changes in the metadata of this user. @@ -464,6 +483,7 @@ fun observeUserReportCount(user: User): State { return flow.collectAsStateWithLifecycle(0) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserStatuses(user: User): State> { // Subscribe in the relay for changes in the metadata of this user. @@ -486,6 +506,7 @@ fun observeUserStatuses(user: User): State> { return flow.collectAsStateWithLifecycle(persistentListOf()) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserRelayIntoList( user: User, @@ -513,6 +534,7 @@ fun observeUserRelayIntoList( return flow.collectAsStateWithLifecycle(false) } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserRoomSubject( user: User, @@ -543,6 +565,7 @@ data class RelayUsage( val userRelayList: List = emptyList(), ) +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeUserRelaysUsing(user: User): State { // Subscribe in the relay for changes in the metadata of this user.