Improves list of visible authors on live stream bubbles

This commit is contained in:
Vitor Pamplona
2025-09-02 13:26:19 -04:00
parent 8db90728aa
commit fcd56fdb3a
3 changed files with 42 additions and 8 deletions

View File

@@ -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<NormalizedRelayUrl> =

View File

@@ -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<User> {
val users = mutableSetOf<User>()
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(

View File

@@ -89,6 +89,8 @@ class LiveActivitiesEvent(
fun totalParticipants() = tags.firstNotNullOfOrNull(TotalParticipantsTag::parse)
fun participantKeys(): List<HexKey> = tags.mapNotNull(ParticipantTag::parseKey)
fun participants() = tags.mapNotNull(ParticipantTag::parse)
fun relays() = tags.mapNotNull(RelayListTag::parse)