Skip to content

Commit

Permalink
re organizing the private dm composables
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Mar 7, 2025
1 parent 639e2bb commit 429f9f8
Show file tree
Hide file tree
Showing 29 changed files with 1,795 additions and 1,542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.LoadRedirectScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.NewPostScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarks.BookmarkListScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list.MessagesScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ChatroomScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ChatroomScreenByAuthor
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.ChatroomByAuthorScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.ChatroomScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.public.ChannelScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.communities.CommunityScreen
import com.vitorpamplona.amethyst.ui.screen.loggedIn.discover.DiscoverScreen
Expand Down Expand Up @@ -244,7 +244,7 @@ fun AppNavigation(
popEnterTransition = { scaleIn },
popExitTransition = { slideOutHorizontallyToEnd },
) {
ChatroomScreenByAuthor(it.id(), null, accountViewModel, nav)
ChatroomByAuthorScreen(it.id(), null, accountViewModel, nav)
}

composable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.vitorpamplona.amethyst.ui.components.GenericLoadable
import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.routeFor
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ChatroomHeader
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.header.ChatroomHeader
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.replyModifier
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.routeFor
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ChatroomHeader
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.header.ChatroomHeader
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.vitorpamplona.amethyst.ui.navigation.routeFor
import com.vitorpamplona.amethyst.ui.note.LoadDecryptedContent
import com.vitorpamplona.amethyst.ui.note.elements.DisplayUncitedHashtags
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ChatroomHeader
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.header.ChatroomHeader
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.placeholderText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
Expand Down Expand Up @@ -54,15 +53,12 @@ import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.map
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.FeatureSetType
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.layouts.ChatHeaderLayout
import com.vitorpamplona.amethyst.ui.navigation.INav
Expand All @@ -71,9 +67,9 @@ import com.vitorpamplona.amethyst.ui.note.LoadChannel
import com.vitorpamplona.amethyst.ui.note.LoadDecryptedContentOrNull
import com.vitorpamplona.amethyst.ui.note.NonClickableUserPictures
import com.vitorpamplona.amethyst.ui.note.ObserveDraftEvent
import com.vitorpamplona.amethyst.ui.note.UsernameDisplay
import com.vitorpamplona.amethyst.ui.note.timeAgo
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.header.RoomNameDisplay
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.AccountPictureModifier
import com.vitorpamplona.amethyst.ui.theme.Size55dp
Expand All @@ -85,7 +81,6 @@ import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKeyable
import com.vitorpamplona.quartz.nip28PublicChat.admin.ChannelCreateEvent
import com.vitorpamplona.quartz.nip28PublicChat.admin.ChannelMetadataEvent
import com.vitorpamplona.quartz.nip37Drafts.DraftEvent
import kotlin.math.min

@Composable
fun ChatroomHeaderCompose(
Expand Down Expand Up @@ -303,131 +298,6 @@ private fun UserRoomCompose(
)
}

@Composable
fun RoomNameDisplay(
room: ChatroomKey,
modifier: Modifier,
accountViewModel: AccountViewModel,
) {
val roomSubject by
accountViewModel
.userProfile()
.live()
.messages
.map { it.user.privateChatrooms[room]?.subject }
.distinctUntilChanged()
.observeAsState(accountViewModel.userProfile().privateChatrooms[room]?.subject)

CrossfadeIfEnabled(targetState = roomSubject, modifier, label = "RoomNameDisplay", accountViewModel = accountViewModel) {
if (!it.isNullOrBlank()) {
if (room.users.size > 1) {
DisplayRoomSubject(it)
} else {
DisplayUserAndSubject(room.users.first(), it, accountViewModel)
}
} else {
DisplayUserSetAsSubject(room, accountViewModel)
}
}
}

@Composable
private fun DisplayUserAndSubject(
user: HexKey,
subject: String,
accountViewModel: AccountViewModel,
) {
Row {
Text(
text = subject,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(
text = " - ",
fontWeight = FontWeight.Bold,
maxLines = 1,
)
LoadUser(baseUserHex = user, accountViewModel = accountViewModel) {
it?.let { UsernameDisplay(it, Modifier.weight(1f), accountViewModel = accountViewModel) }
}
}
}

@Composable
fun DisplayUserSetAsSubject(
room: ChatroomKey,
accountViewModel: AccountViewModel,
fontWeight: FontWeight = FontWeight.Bold,
) {
val userList = remember(room) { room.users.toList() }

if (userList.size == 1) {
// Regular Design
Row {
LoadUser(baseUserHex = userList[0], accountViewModel) {
it?.let { UsernameDisplay(it, Modifier.weight(1f), fontWeight = fontWeight, accountViewModel = accountViewModel) }
}
}
} else {
Row {
userList.take(4).forEachIndexed { index, value ->
LoadUser(baseUserHex = value, accountViewModel) {
it?.let { ShortUsernameDisplay(baseUser = it, fontWeight = fontWeight, accountViewModel = accountViewModel) }
}

if (min(userList.size, 4) - 1 != index) {
Text(
text = ", ",
fontWeight = fontWeight,
maxLines = 1,
)
}
}
}
}
}

@Composable
fun DisplayRoomSubject(
roomSubject: String,
fontWeight: FontWeight = FontWeight.Bold,
) {
Row {
Text(
text = roomSubject,
fontWeight = fontWeight,
maxLines = 1,
)
}
}

@Composable
fun ShortUsernameDisplay(
baseUser: User,
weight: Modifier = Modifier,
fontWeight: FontWeight = FontWeight.Bold,
accountViewModel: AccountViewModel,
) {
val userName by
baseUser
.live()
.metadata
.map { it.user.toBestShortFirstName() }
.distinctUntilChanged()
.observeAsState(baseUser.toBestShortFirstName())

CrossfadeIfEnabled(targetState = userName, modifier = weight, accountViewModel = accountViewModel) {
CreateTextWithEmoji(
text = it,
tags = baseUser.info?.tags,
fontWeight = fontWeight,
maxLines = 1,
)
}
}

@Composable
fun LoadUser(
baseUserHex: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.DisappearingScaffold
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list.ChannelFabColumn
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.Chatroom
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.Chatroom
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.public.Channel
import com.vitorpamplona.amethyst.ui.theme.Size20dp

Expand Down
Loading

0 comments on commit 429f9f8

Please sign in to comment.