mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-10-01 17:30:50 +00:00
Removes the need to observe author changes to event.
This commit is contained in:
parent
7eefbee0e3
commit
1123b3b3c1
@ -965,8 +965,6 @@ class NoteLiveSet(u: Note) {
|
|||||||
val relays = innerRelays.map { it }
|
val relays = innerRelays.map { it }
|
||||||
val zaps = innerZaps.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 hasEvent = innerMetadata.map { it.note.event != null }.distinctUntilChanged()
|
||||||
|
|
||||||
val hasReactions =
|
val hasReactions =
|
||||||
@ -1004,7 +1002,6 @@ class NoteLiveSet(u: Note) {
|
|||||||
reports.hasObservers() ||
|
reports.hasObservers() ||
|
||||||
relays.hasObservers() ||
|
relays.hasObservers() ||
|
||||||
zaps.hasObservers() ||
|
zaps.hasObservers() ||
|
||||||
authorChanges.hasObservers() ||
|
|
||||||
hasEvent.hasObservers() ||
|
hasEvent.hasObservers() ||
|
||||||
hasReactions.hasObservers() ||
|
hasReactions.hasObservers() ||
|
||||||
replyCount.hasObservers() ||
|
replyCount.hasObservers() ||
|
||||||
|
@ -853,9 +853,7 @@ fun Gallery(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DisplayAuthorBanner(note: Note) {
|
fun DisplayAuthorBanner(note: Note) {
|
||||||
val authorState by note.live().authorChanges.observeAsState(note.author)
|
WatchAuthor(note) {
|
||||||
|
BannerImage(it, Modifier.fillMaxSize().clip(QuoteBorder))
|
||||||
authorState?.let { author ->
|
|
||||||
BannerImage(author, Modifier.fillMaxSize().clip(QuoteBorder))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,12 +84,15 @@ fun ChatroomHeaderCompose(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val hasEvent by baseNote.live().hasEvent.observeAsState(baseNote.event != null)
|
if (baseNote.event != null) {
|
||||||
|
|
||||||
if (hasEvent) {
|
|
||||||
ChatroomComposeChannelOrUser(baseNote, accountViewModel, nav)
|
ChatroomComposeChannelOrUser(baseNote, accountViewModel, nav)
|
||||||
} else {
|
} 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
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import androidx.compose.animation.Crossfade
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@ -494,13 +493,11 @@ private fun BoxedAuthor(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
Box(modifier = Size35Modifier.clickable(onClick = { nav(authorRouteFor(note)) })) {
|
Box(modifier = Size35Modifier.clickable(onClick = { nav(authorRouteFor(note)) })) {
|
||||||
WatchNoteAuthor(note) { targetAuthor ->
|
WatchAuthorWithBlank(note, Size35Modifier) { author ->
|
||||||
Crossfade(targetState = targetAuthor, modifier = Size35Modifier) { author ->
|
WatchUserMetadataAndFollowsAndRenderUserProfilePictureOrDefaultAuthor(
|
||||||
WatchUserMetadataAndFollowsAndRenderUserProfilePictureOrDefaultAuthor(
|
author,
|
||||||
author,
|
accountViewModel,
|
||||||
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
|
@Composable
|
||||||
private fun WatchUserMetadata(
|
private fun WatchUserMetadata(
|
||||||
author: User,
|
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.NIP05CheckingIcon
|
||||||
import com.vitorpamplona.amethyst.ui.note.NIP05FailedVerification
|
import com.vitorpamplona.amethyst.ui.note.NIP05FailedVerification
|
||||||
import com.vitorpamplona.amethyst.ui.note.NIP05VerifiedIcon
|
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.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
||||||
import com.vitorpamplona.amethyst.ui.theme.NIP05IconSize
|
import com.vitorpamplona.amethyst.ui.theme.NIP05IconSize
|
||||||
@ -116,9 +117,9 @@ fun ObserveDisplayNip05Status(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val author by baseNote.live().authorChanges.observeAsState()
|
WatchAuthor(baseNote = baseNote) {
|
||||||
|
ObserveDisplayNip05Status(it, columnModifier, accountViewModel, nav)
|
||||||
author?.let { ObserveDisplayNip05Status(it, columnModifier, accountViewModel, nav) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.Crossfade
|
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
@ -77,9 +76,7 @@ fun NoteAuthorPicture(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onClick: ((User) -> Unit)? = null,
|
onClick: ((User) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val author by baseNote.live().authorChanges.observeAsState(baseNote.author)
|
WatchAuthorWithBlank(baseNote) {
|
||||||
|
|
||||||
Crossfade(targetState = author, label = "NoteAuthorPicture") {
|
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
DisplayBlankAuthor(size, modifier)
|
DisplayBlankAuthor(size, modifier)
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,10 +52,43 @@ fun NoteUsernameDisplay(
|
|||||||
showPlayButton: Boolean = true,
|
showPlayButton: Boolean = true,
|
||||||
textColor: Color = Color.Unspecified,
|
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") {
|
@Composable
|
||||||
it?.let { UsernameDisplay(it, weight, showPlayButton, textColor = textColor) }
|
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.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
|
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.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size55dp
|
import com.vitorpamplona.amethyst.ui.theme.Size55dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader
|
import com.vitorpamplona.amethyst.ui.theme.authorNotePictureForImageHeader
|
||||||
@ -47,14 +48,12 @@ fun DefaultImageHeader(
|
|||||||
note: Note,
|
note: Note,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
) {
|
) {
|
||||||
val authorState by note.live().authorChanges.observeAsState(note.author)
|
WatchAuthor(baseNote = note) {
|
||||||
|
|
||||||
authorState?.let { author ->
|
|
||||||
Box {
|
Box {
|
||||||
BannerImage(author)
|
BannerImage(it)
|
||||||
|
|
||||||
Box(authorNotePictureForImageHeader.align(Alignment.BottomStart)) {
|
Box(authorNotePictureForImageHeader.align(Alignment.BottomStart)) {
|
||||||
BaseUserPicture(author, Size55dp, accountViewModel, Modifier)
|
BaseUserPicture(it, Size55dp, accountViewModel, Modifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user