diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt index 0af719319..798ffcfad 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt @@ -48,6 +48,8 @@ abstract class Channel : NotesGatherer { return new } + open fun participatingAuthors() = notes.mapNotNull { key, value -> value.author } + abstract fun toBestDisplayName(): String open fun relays(): Set = 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 7e83e7149..8977d67d4 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 @@ -26,6 +26,7 @@ import androidx.compose.runtime.remember import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.model.Channel import com.vitorpamplona.amethyst.model.ChannelState +import com.vitorpamplona.amethyst.model.LocalCache.notes import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.nip28PublicChats.PublicChatChannel import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel @@ -69,16 +70,10 @@ fun observeChannelNoteAuthors( .flow() .notes.stateFlow .mapLatest { - it.channel.notes - .mapNotNull { key, value -> value.author } - .toSet() - .toImmutableList() + channelToParticipatingUsers(it.channel, accountViewModel) }.onStart { emit( - baseChannel.notes - .mapNotNull { key, value -> value.author } - .toSet() - .toImmutableList(), + channelToParticipatingUsers(baseChannel, accountViewModel), ) }.distinctUntilChanged() .flowOn(Dispatchers.Default) @@ -87,6 +82,41 @@ fun observeChannelNoteAuthors( return flow.collectAsStateWithLifecycle(persistentListOf()) } +private fun channelToParticipatingUsers( + channel: Channel, + accountViewModel: AccountViewModel, +): ImmutableList { + val users = mutableSetOf() + + channel.participatingAuthors().forEach { + users.add(it) + } + + if (channel is LiveActivitiesChannel) { + val noteAuthor = channel.infoNote?.author + if (noteAuthor != null) { + users.add(noteAuthor) + } + + val pKeys = channel.info?.participantKeys() ?: emptyList() + + pKeys.forEach { + val u = accountViewModel.checkGetOrCreateUser(it) + if (u != null) { + users.add(u) + } + } + } + + return users + .sortedWith( + compareBy( + { !accountViewModel.isFollowing(it) }, + { it.pubkeyHex }, + ), + ).toImmutableList() +} + @OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeChannelPicture( diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt index 23c919fa6..b11a39483 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt @@ -89,6 +89,8 @@ class LiveActivitiesEvent( fun totalParticipants() = tags.firstNotNullOfOrNull(TotalParticipantsTag::parse) + fun participantKeys(): List = tags.mapNotNull(ParticipantTag::parseKey) + fun participants() = tags.mapNotNull(ParticipantTag::parse) fun relays() = tags.mapNotNull(RelayListTag::parse)