kopia lustrzana https://github.com/vitorpamplona/amethyst
Removes the need to observe author changes to event.
rodzic
7eefbee0e3
commit
1123b3b3c1
|
@ -965,8 +965,6 @@ class NoteLiveSet(u: Note) {
|
|||
val relays = innerRelays.map { it }
|
||||
val zaps = innerZaps.map { it }
|
||||
|
||||
val authorChanges = innerMetadata.map { it.note.author }.distinctUntilChanged()
|
||||
|
||||
val hasEvent = innerMetadata.map { it.note.event != null }.distinctUntilChanged()
|
||||
|
||||
val hasReactions =
|
||||
|
@ -1004,7 +1002,6 @@ class NoteLiveSet(u: Note) {
|
|||
reports.hasObservers() ||
|
||||
relays.hasObservers() ||
|
||||
zaps.hasObservers() ||
|
||||
authorChanges.hasObservers() ||
|
||||
hasEvent.hasObservers() ||
|
||||
hasReactions.hasObservers() ||
|
||||
replyCount.hasObservers() ||
|
||||
|
|
|
@ -853,9 +853,7 @@ fun Gallery(
|
|||
|
||||
@Composable
|
||||
fun DisplayAuthorBanner(note: Note) {
|
||||
val authorState by note.live().authorChanges.observeAsState(note.author)
|
||||
|
||||
authorState?.let { author ->
|
||||
BannerImage(author, Modifier.fillMaxSize().clip(QuoteBorder))
|
||||
WatchAuthor(note) {
|
||||
BannerImage(it, Modifier.fillMaxSize().clip(QuoteBorder))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,12 +84,15 @@ fun ChatroomHeaderCompose(
|
|||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val hasEvent by baseNote.live().hasEvent.observeAsState(baseNote.event != null)
|
||||
|
||||
if (hasEvent) {
|
||||
if (baseNote.event != null) {
|
||||
ChatroomComposeChannelOrUser(baseNote, accountViewModel, nav)
|
||||
} else {
|
||||
BlankNote()
|
||||
val hasEvent by baseNote.live().hasEvent.observeAsState(baseNote.event != null)
|
||||
if (hasEvent) {
|
||||
ChatroomComposeChannelOrUser(baseNote, accountViewModel, nav)
|
||||
} else {
|
||||
BlankNote()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
package com.vitorpamplona.amethyst.ui.note
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
|
@ -494,13 +493,11 @@ private fun BoxedAuthor(
|
|||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
Box(modifier = Size35Modifier.clickable(onClick = { nav(authorRouteFor(note)) })) {
|
||||
WatchNoteAuthor(note) { targetAuthor ->
|
||||
Crossfade(targetState = targetAuthor, modifier = Size35Modifier) { author ->
|
||||
WatchUserMetadataAndFollowsAndRenderUserProfilePictureOrDefaultAuthor(
|
||||
author,
|
||||
accountViewModel,
|
||||
)
|
||||
}
|
||||
WatchAuthorWithBlank(note, Size35Modifier) { author ->
|
||||
WatchUserMetadataAndFollowsAndRenderUserProfilePictureOrDefaultAuthor(
|
||||
author,
|
||||
accountViewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -546,16 +543,6 @@ fun WatchUserMetadataAndFollowsAndRenderUserProfilePicture(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WatchNoteAuthor(
|
||||
baseNote: Note,
|
||||
onContent: @Composable (User?) -> Unit,
|
||||
) {
|
||||
val author by baseNote.live().authorChanges.observeAsState(baseNote.author)
|
||||
|
||||
onContent(author)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WatchUserMetadata(
|
||||
author: User,
|
||||
|
|
|
@ -60,6 +60,7 @@ import com.vitorpamplona.amethyst.ui.note.LoadStatuses
|
|||
import com.vitorpamplona.amethyst.ui.note.NIP05CheckingIcon
|
||||
import com.vitorpamplona.amethyst.ui.note.NIP05FailedVerification
|
||||
import com.vitorpamplona.amethyst.ui.note.NIP05VerifiedIcon
|
||||
import com.vitorpamplona.amethyst.ui.note.WatchAuthor
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
||||
import com.vitorpamplona.amethyst.ui.theme.NIP05IconSize
|
||||
|
@ -116,9 +117,9 @@ fun ObserveDisplayNip05Status(
|
|||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val author by baseNote.live().authorChanges.observeAsState()
|
||||
|
||||
author?.let { ObserveDisplayNip05Status(it, columnModifier, accountViewModel, nav) }
|
||||
WatchAuthor(baseNote = baseNote) {
|
||||
ObserveDisplayNip05Status(it, columnModifier, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
package com.vitorpamplona.amethyst.ui.note
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
|
@ -77,9 +76,7 @@ fun NoteAuthorPicture(
|
|||
modifier: Modifier = Modifier,
|
||||
onClick: ((User) -> Unit)? = null,
|
||||
) {
|
||||
val author by baseNote.live().authorChanges.observeAsState(baseNote.author)
|
||||
|
||||
Crossfade(targetState = author, label = "NoteAuthorPicture") {
|
||||
WatchAuthorWithBlank(baseNote) {
|
||||
if (it == null) {
|
||||
DisplayBlankAuthor(size, modifier)
|
||||
} else {
|
||||
|
|
|
@ -52,10 +52,43 @@ fun NoteUsernameDisplay(
|
|||
showPlayButton: Boolean = true,
|
||||
textColor: Color = Color.Unspecified,
|
||||
) {
|
||||
val authorState by baseNote.live().authorChanges.observeAsState(baseNote.author)
|
||||
WatchAuthor(baseNote) {
|
||||
UsernameDisplay(it, weight, showPlayButton, textColor = textColor)
|
||||
}
|
||||
}
|
||||
|
||||
Crossfade(targetState = authorState, modifier = weight, label = "NoteUsernameDisplay") {
|
||||
it?.let { UsernameDisplay(it, weight, showPlayButton, textColor = textColor) }
|
||||
@Composable
|
||||
fun WatchAuthor(
|
||||
baseNote: Note,
|
||||
inner: @Composable (User) -> Unit,
|
||||
) {
|
||||
val noteAuthor = baseNote.author
|
||||
if (noteAuthor != null) {
|
||||
inner(noteAuthor)
|
||||
} else {
|
||||
val authorState by baseNote.live().metadata.observeAsState()
|
||||
|
||||
authorState?.note?.author?.let {
|
||||
inner(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun WatchAuthorWithBlank(
|
||||
baseNote: Note,
|
||||
modifier: Modifier = Modifier,
|
||||
inner: @Composable (User?) -> Unit,
|
||||
) {
|
||||
val noteAuthor = baseNote.author
|
||||
if (noteAuthor != null) {
|
||||
inner(noteAuthor)
|
||||
} else {
|
||||
val authorState by baseNote.live().metadata.observeAsState()
|
||||
|
||||
Crossfade(targetState = authorState?.note?.author, modifier = modifier, label = "WatchAuthorWithBlank") { newAuthor ->
|
||||
inner(newAuthor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.vitorpamplona.amethyst.R
|
|||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
|
||||
import com.vitorpamplona.amethyst.ui.note.WatchAuthor
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size55dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader
|
||||
|
@ -47,14 +48,12 @@ fun DefaultImageHeader(
|
|||
note: Note,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
val authorState by note.live().authorChanges.observeAsState(note.author)
|
||||
|
||||
authorState?.let { author ->
|
||||
WatchAuthor(baseNote = note) {
|
||||
Box {
|
||||
BannerImage(author)
|
||||
BannerImage(it)
|
||||
|
||||
Box(authorNotePictureForImageHeader.align(Alignment.BottomStart)) {
|
||||
BaseUserPicture(author, Size55dp, accountViewModel, Modifier)
|
||||
BaseUserPicture(it, Size55dp, accountViewModel, Modifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue