mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-22 11:20:54 +02:00
Improves list of visible authors on live stream bubbles
This commit is contained in:
@@ -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> =
|
||||
|
@@ -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(
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user