Improves list of visible authors on live stream bubbles
This commit is contained in:
@@ -48,6 +48,8 @@ abstract class Channel : NotesGatherer {
|
|||||||
return new
|
return new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun participatingAuthors() = notes.mapNotNull { key, value -> value.author }
|
||||||
|
|
||||||
abstract fun toBestDisplayName(): String
|
abstract fun toBestDisplayName(): String
|
||||||
|
|
||||||
open fun relays(): Set<NormalizedRelayUrl> =
|
open fun relays(): Set<NormalizedRelayUrl> =
|
||||||
|
|||||||
+38
-8
@@ -26,6 +26,7 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.vitorpamplona.amethyst.model.Channel
|
import com.vitorpamplona.amethyst.model.Channel
|
||||||
import com.vitorpamplona.amethyst.model.ChannelState
|
import com.vitorpamplona.amethyst.model.ChannelState
|
||||||
|
import com.vitorpamplona.amethyst.model.LocalCache.notes
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.model.nip28PublicChats.PublicChatChannel
|
import com.vitorpamplona.amethyst.model.nip28PublicChats.PublicChatChannel
|
||||||
import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel
|
import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel
|
||||||
@@ -69,16 +70,10 @@ fun observeChannelNoteAuthors(
|
|||||||
.flow()
|
.flow()
|
||||||
.notes.stateFlow
|
.notes.stateFlow
|
||||||
.mapLatest {
|
.mapLatest {
|
||||||
it.channel.notes
|
channelToParticipatingUsers(it.channel, accountViewModel)
|
||||||
.mapNotNull { key, value -> value.author }
|
|
||||||
.toSet()
|
|
||||||
.toImmutableList()
|
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(
|
emit(
|
||||||
baseChannel.notes
|
channelToParticipatingUsers(baseChannel, accountViewModel),
|
||||||
.mapNotNull { key, value -> value.author }
|
|
||||||
.toSet()
|
|
||||||
.toImmutableList(),
|
|
||||||
)
|
)
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
@@ -87,6 +82,41 @@ fun observeChannelNoteAuthors(
|
|||||||
return flow.collectAsStateWithLifecycle(persistentListOf())
|
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)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun observeChannelPicture(
|
fun observeChannelPicture(
|
||||||
|
|||||||
+2
@@ -89,6 +89,8 @@ class LiveActivitiesEvent(
|
|||||||
|
|
||||||
fun totalParticipants() = tags.firstNotNullOfOrNull(TotalParticipantsTag::parse)
|
fun totalParticipants() = tags.firstNotNullOfOrNull(TotalParticipantsTag::parse)
|
||||||
|
|
||||||
|
fun participantKeys(): List<HexKey> = tags.mapNotNull(ParticipantTag::parseKey)
|
||||||
|
|
||||||
fun participants() = tags.mapNotNull(ParticipantTag::parse)
|
fun participants() = tags.mapNotNull(ParticipantTag::parse)
|
||||||
|
|
||||||
fun relays() = tags.mapNotNull(RelayListTag::parse)
|
fun relays() = tags.mapNotNull(RelayListTag::parse)
|
||||||
|
|||||||
Reference in New Issue
Block a user