Fixes unchecked cast and other opt-in tags on observers

This commit is contained in:
Vitor Pamplona
2025-04-24 17:35:34 -04:00
parent c0f486db82
commit 07c3a3ffe5
3 changed files with 38 additions and 0 deletions
@@ -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<ChannelState?> {
return baseChannel.flow.stateFlow.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeChannelPicture(baseChannel: Channel): State<String?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -55,6 +57,7 @@ fun observeChannelPicture(baseChannel: Channel): State<String?> {
return flow.collectAsStateWithLifecycle(baseChannel.profilePicture())
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeChannelInfo(baseChannel: LiveActivitiesChannel): State<LiveActivitiesEvent?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -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<NoteState> {
.collectAsStateWithLifecycle()
}
@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun <T : Event> observeNoteEvent(note: Note): State<T?> {
// Subscribe in the relay for changes in this note.
@@ -64,6 +68,7 @@ fun <T : Event> observeNoteEvent(note: Note): State<T?> {
return flow.collectAsStateWithLifecycle(note.event as? T?)
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun <T> observeNoteAndMap(
note: Note,
@@ -86,6 +91,8 @@ fun <T> observeNoteAndMap(
return flow.collectAsStateWithLifecycle(map(note))
}
@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun <T, U> observeNoteEventAndMap(
note: Note,
@@ -109,6 +116,7 @@ fun <T, U> observeNoteEventAndMap(
return flow.collectAsStateWithLifecycle((note.event as? T)?.let { map(it) })
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeNoteHasEvent(note: Note): State<Boolean> {
// Subscribe in the relay for changes in this note.
@@ -139,6 +147,7 @@ fun observeNoteReplies(note: Note): State<NoteState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeNoteReplyCount(note: Note): State<Int> {
// Subscribe in the relay for changes in this note.
@@ -170,6 +179,7 @@ fun observeNoteReactions(note: Note): State<NoteState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeNoteReactionCount(note: Note): State<Int> {
// Subscribe in the relay for changes in this note.
@@ -215,6 +225,7 @@ fun observeNoteReposts(note: Note): State<NoteState?> {
.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<Int> {
// Subscribe in the relay for changes in this note.
@@ -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<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserName(user: User): State<String> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -73,6 +76,7 @@ fun observeUserName(user: User): State<String> {
return flow.collectAsStateWithLifecycle(user.toBestDisplayName())
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserNip05(user: User): State<String?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -91,6 +95,7 @@ fun observeUserNip05(user: User): State<String?> {
return flow.collectAsStateWithLifecycle(user.info?.nip05)
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserAboutMe(user: User): State<String> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -109,6 +114,7 @@ fun observeUserAboutMe(user: User): State<String> {
return flow.collectAsStateWithLifecycle(user.info?.about ?: "")
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserInfo(user: User): State<UserMetadata?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -127,6 +133,7 @@ fun observeUserInfo(user: User): State<UserMetadata?> {
return flow.collectAsStateWithLifecycle(user.info)
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserBanner(user: User): State<String?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -145,6 +152,7 @@ fun observeUserBanner(user: User): State<String?> {
return flow.collectAsStateWithLifecycle(user.info?.banner)
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserPicture(user: User): State<String?> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -163,6 +171,7 @@ fun observeUserPicture(user: User): State<String?> {
return flow.collectAsStateWithLifecycle(user.info?.picture)
}
@OptIn(ExperimentalCoroutinesApi::class)
@Composable
fun observeUserShortName(user: User): State<String> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -193,6 +202,7 @@ fun observeUserFollows(user: User): State<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserFollowCount(user: User): State<Int> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -214,6 +224,7 @@ fun observeUserFollowCount(user: User): State<Int> {
return flow.collectAsStateWithLifecycle(0)
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserTagFollows(user: User): State<Int> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -247,6 +258,7 @@ fun observeUserBookmarks(user: User): State<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserBookmarkCount(user: User): State<Int> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -280,6 +292,7 @@ fun observeUserFollowers(user: User): State<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserFollowerCount(user: User): State<Int> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -301,6 +314,7 @@ fun observeUserFollowerCount(user: User): State<Int> {
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<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserZapAmount(user: User): State<BigDecimal> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -442,6 +460,7 @@ fun observeUserReports(user: User): State<UserState?> {
.collectAsStateWithLifecycle()
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserReportCount(user: User): State<Int> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -464,6 +483,7 @@ fun observeUserReportCount(user: User): State<Int> {
return flow.collectAsStateWithLifecycle(0)
}
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserStatuses(user: User): State<ImmutableList<AddressableNote>> {
// Subscribe in the relay for changes in the metadata of this user.
@@ -486,6 +506,7 @@ fun observeUserStatuses(user: User): State<ImmutableList<AddressableNote>> {
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<String> = emptyList(),
)
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Composable
fun observeUserRelaysUsing(user: User): State<RelayUsage> {
// Subscribe in the relay for changes in the metadata of this user.