2023-01-11 18:31:20 +00:00
|
|
|
package com.vitorpamplona.amethyst.ui.note
|
|
|
|
|
2023-02-22 15:26:05 +00:00
|
|
|
import androidx.compose.foundation.*
|
|
|
|
import androidx.compose.foundation.layout.*
|
2023-01-11 18:31:20 +00:00
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
2023-02-22 15:26:05 +00:00
|
|
|
import androidx.compose.material.*
|
2023-02-06 22:16:27 +00:00
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.filled.ExpandMore
|
|
|
|
import androidx.compose.material.icons.filled.MoreVert
|
2023-02-22 15:26:05 +00:00
|
|
|
import androidx.compose.runtime.*
|
2023-01-11 18:31:20 +00:00
|
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.draw.clip
|
2023-02-06 22:16:27 +00:00
|
|
|
import androidx.compose.ui.graphics.ColorFilter
|
|
|
|
import androidx.compose.ui.graphics.ColorMatrix
|
2023-02-14 19:25:26 +00:00
|
|
|
import androidx.compose.ui.graphics.painter.BitmapPainter
|
2023-01-13 15:20:54 +00:00
|
|
|
import androidx.compose.ui.platform.LocalClipboardManager
|
2023-01-24 19:59:21 +00:00
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2023-02-06 22:16:27 +00:00
|
|
|
import androidx.compose.ui.platform.LocalUriHandler
|
2023-01-26 16:16:57 +00:00
|
|
|
import androidx.compose.ui.res.painterResource
|
2023-01-13 15:20:54 +00:00
|
|
|
import androidx.compose.ui.text.AnnotatedString
|
2023-01-11 18:31:20 +00:00
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
2023-01-26 16:16:57 +00:00
|
|
|
import androidx.compose.ui.unit.Dp
|
2023-01-11 18:31:20 +00:00
|
|
|
import androidx.compose.ui.unit.dp
|
2023-01-12 17:47:31 +00:00
|
|
|
import androidx.navigation.NavController
|
2023-01-11 18:31:20 +00:00
|
|
|
import coil.compose.AsyncImage
|
2023-02-06 22:16:27 +00:00
|
|
|
import com.google.accompanist.flowlayout.FlowRow
|
2023-01-27 01:09:56 +00:00
|
|
|
import com.vitorpamplona.amethyst.NotificationCache
|
2023-01-26 16:16:57 +00:00
|
|
|
import com.vitorpamplona.amethyst.R
|
2023-02-10 22:13:25 +00:00
|
|
|
import com.vitorpamplona.amethyst.RoboHashCache
|
2023-01-11 18:31:20 +00:00
|
|
|
import com.vitorpamplona.amethyst.model.Note
|
2023-01-26 16:16:57 +00:00
|
|
|
import com.vitorpamplona.amethyst.model.User
|
2023-01-19 22:58:35 +00:00
|
|
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
2023-01-11 18:31:20 +00:00
|
|
|
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
2023-01-30 01:06:48 +00:00
|
|
|
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
2023-01-11 18:31:20 +00:00
|
|
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
2023-02-16 23:25:55 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy
|
|
|
|
import com.vitorpamplona.amethyst.ui.components.ResizeImage
|
2023-02-08 16:57:36 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer
|
2023-01-11 18:31:20 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
2023-01-26 16:16:57 +00:00
|
|
|
import com.vitorpamplona.amethyst.ui.theme.Following
|
2023-01-11 18:31:20 +00:00
|
|
|
import nostr.postr.events.TextNoteEvent
|
|
|
|
|
2023-01-13 15:20:54 +00:00
|
|
|
@OptIn(ExperimentalFoundationApi::class)
|
2023-01-11 18:31:20 +00:00
|
|
|
@Composable
|
2023-01-27 01:09:56 +00:00
|
|
|
fun NoteCompose(
|
|
|
|
baseNote: Note,
|
|
|
|
routeForLastRead: String? = null,
|
|
|
|
modifier: Modifier = Modifier,
|
2023-02-20 23:09:57 +00:00
|
|
|
isBoostedNote: Boolean = false,
|
|
|
|
isQuotedNote: Boolean = false,
|
2023-01-27 01:09:56 +00:00
|
|
|
accountViewModel: AccountViewModel,
|
|
|
|
navController: NavController
|
|
|
|
) {
|
2023-01-24 19:59:21 +00:00
|
|
|
val accountState by accountViewModel.accountLiveData.observeAsState()
|
2023-01-26 16:16:57 +00:00
|
|
|
val account = accountState?.account ?: return
|
2023-01-24 19:59:21 +00:00
|
|
|
|
2023-02-19 16:22:01 +00:00
|
|
|
val noteState by baseNote.live().metadata.observeAsState()
|
2023-01-11 18:31:20 +00:00
|
|
|
val note = noteState?.note
|
|
|
|
|
2023-02-19 16:22:01 +00:00
|
|
|
val noteReportsState by baseNote.live().reports.observeAsState()
|
2023-01-30 01:06:48 +00:00
|
|
|
val noteForReports = noteReportsState?.note ?: return
|
|
|
|
|
2023-01-13 15:20:54 +00:00
|
|
|
var popupExpanded by remember { mutableStateOf(false) }
|
2023-02-04 15:41:43 +00:00
|
|
|
var showHiddenNote by remember { mutableStateOf(false) }
|
2023-01-13 15:20:54 +00:00
|
|
|
|
2023-01-27 01:09:56 +00:00
|
|
|
val context = LocalContext.current.applicationContext
|
|
|
|
|
2023-02-12 23:23:02 +00:00
|
|
|
var moreActionsExpanded by remember { mutableStateOf(false) }
|
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
val noteEvent = note?.event
|
2023-02-12 23:23:02 +00:00
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent == null) {
|
2023-01-19 22:58:35 +00:00
|
|
|
BlankNote(modifier.combinedClickable(
|
|
|
|
onClick = { },
|
|
|
|
onLongClick = { popupExpanded = true },
|
2023-02-20 23:09:57 +00:00
|
|
|
), isBoostedNote)
|
2023-02-04 15:41:43 +00:00
|
|
|
} else if (!account.isAcceptable(noteForReports) && !showHiddenNote) {
|
|
|
|
HiddenNote(
|
|
|
|
account.getRelevantReports(noteForReports),
|
|
|
|
account.userProfile(),
|
|
|
|
modifier,
|
2023-02-20 23:09:57 +00:00
|
|
|
isBoostedNote,
|
2023-02-04 15:41:43 +00:00
|
|
|
navController,
|
|
|
|
onClick = { showHiddenNote = true }
|
|
|
|
)
|
2023-01-11 18:31:20 +00:00
|
|
|
} else {
|
2023-02-18 18:06:53 +00:00
|
|
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
2023-01-27 01:09:56 +00:00
|
|
|
|
2023-02-18 18:06:53 +00:00
|
|
|
LaunchedEffect(key1 = routeForLastRead) {
|
|
|
|
routeForLastRead?.let {
|
|
|
|
val lastTime = NotificationCache.load(it, context)
|
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
val createdAt = noteEvent.createdAt
|
2023-02-18 18:06:53 +00:00
|
|
|
if (createdAt != null) {
|
|
|
|
NotificationCache.markAsRead(it, createdAt, context)
|
|
|
|
isNew = createdAt > lastTime
|
|
|
|
}
|
2023-01-27 01:09:56 +00:00
|
|
|
}
|
2023-02-18 18:06:53 +00:00
|
|
|
}
|
2023-01-27 01:09:56 +00:00
|
|
|
|
2023-01-13 15:20:54 +00:00
|
|
|
Column(modifier =
|
|
|
|
modifier.combinedClickable(
|
2023-01-19 22:58:35 +00:00
|
|
|
onClick = {
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent !is ChannelMessageEvent) {
|
2023-01-25 16:39:19 +00:00
|
|
|
navController.navigate("Note/${note.idHex}"){
|
|
|
|
launchSingleTop = true
|
|
|
|
}
|
2023-01-19 22:58:35 +00:00
|
|
|
} else {
|
|
|
|
note.channel?.let {
|
|
|
|
navController.navigate("Channel/${it.idHex}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-01-27 01:09:56 +00:00
|
|
|
onLongClick = { popupExpanded = true }
|
|
|
|
).run {
|
|
|
|
if (isNew) {
|
|
|
|
this.background(MaterialTheme.colors.primary.copy(0.12f))
|
|
|
|
} else {
|
|
|
|
this
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:20:54 +00:00
|
|
|
) {
|
2023-01-12 17:47:31 +00:00
|
|
|
Row(
|
|
|
|
modifier = Modifier
|
|
|
|
.padding(
|
2023-02-20 23:09:57 +00:00
|
|
|
start = if (!isBoostedNote) 12.dp else 0.dp,
|
|
|
|
end = if (!isBoostedNote) 12.dp else 0.dp,
|
2023-01-12 17:47:31 +00:00
|
|
|
top = 10.dp)
|
|
|
|
) {
|
2023-01-11 18:31:20 +00:00
|
|
|
|
2023-02-20 23:09:57 +00:00
|
|
|
if (!isBoostedNote && !isQuotedNote) {
|
2023-02-06 22:16:27 +00:00
|
|
|
Column(Modifier.width(55.dp)) {
|
|
|
|
// Draws the boosted picture outside the boosted card.
|
|
|
|
Box(modifier = Modifier
|
|
|
|
.width(55.dp)
|
|
|
|
.padding(0.dp)) {
|
|
|
|
|
|
|
|
NoteAuthorPicture(note, navController, account.userProfile(), 55.dp)
|
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is RepostEvent) {
|
2023-02-06 22:16:27 +00:00
|
|
|
note.replyTo?.lastOrNull()?.let {
|
|
|
|
Box(
|
|
|
|
Modifier
|
|
|
|
.width(30.dp)
|
|
|
|
.height(30.dp)
|
|
|
|
.align(Alignment.BottomEnd)) {
|
|
|
|
NoteAuthorPicture(it, navController, account.userProfile(), 35.dp,
|
|
|
|
pictureModifier = Modifier.border(2.dp, MaterialTheme.colors.background, CircleShape)
|
|
|
|
)
|
|
|
|
}
|
2023-02-01 01:12:24 +00:00
|
|
|
}
|
2023-01-26 16:16:57 +00:00
|
|
|
}
|
2023-01-27 22:28:48 +00:00
|
|
|
|
2023-02-06 22:16:27 +00:00
|
|
|
// boosted picture
|
|
|
|
val baseChannel = note.channel
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is ChannelMessageEvent && baseChannel != null) {
|
2023-02-06 22:16:27 +00:00
|
|
|
val channelState by baseChannel.live.observeAsState()
|
|
|
|
val channel = channelState?.channel
|
|
|
|
|
|
|
|
if (channel != null) {
|
|
|
|
Box(
|
|
|
|
Modifier
|
2023-01-27 22:28:48 +00:00
|
|
|
.width(30.dp)
|
|
|
|
.height(30.dp)
|
2023-02-06 22:16:27 +00:00
|
|
|
.align(Alignment.BottomEnd)) {
|
2023-02-15 17:31:15 +00:00
|
|
|
AsyncImageProxy(
|
|
|
|
model = ResizeImage(channel.profilePicture(), 30.dp),
|
2023-02-14 19:25:26 +00:00
|
|
|
placeholder = BitmapPainter(RoboHashCache.get(context, channel.idHex)),
|
|
|
|
fallback = BitmapPainter(RoboHashCache.get(context, channel.idHex)),
|
|
|
|
error = BitmapPainter(RoboHashCache.get(context, channel.idHex)),
|
2023-02-06 22:16:27 +00:00
|
|
|
contentDescription = "Group Picture",
|
|
|
|
modifier = Modifier
|
|
|
|
.width(30.dp)
|
|
|
|
.height(30.dp)
|
|
|
|
.clip(shape = CircleShape)
|
|
|
|
.background(MaterialTheme.colors.background)
|
|
|
|
.border(
|
|
|
|
2.dp,
|
|
|
|
MaterialTheme.colors.background,
|
|
|
|
CircleShape
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2023-01-27 22:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-06 22:16:27 +00:00
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is RepostEvent) {
|
2023-02-06 22:16:27 +00:00
|
|
|
note.replyTo?.lastOrNull()?.let {
|
|
|
|
RelayBadges(it)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RelayBadges(baseNote)
|
|
|
|
}
|
2023-01-11 18:31:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 23:09:57 +00:00
|
|
|
Column(
|
|
|
|
modifier = Modifier.padding(start = if (!isBoostedNote && !isQuotedNote) 10.dp else 0.dp)
|
|
|
|
) {
|
2023-01-11 18:31:20 +00:00
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
2023-02-20 23:09:57 +00:00
|
|
|
if (isQuotedNote) {
|
|
|
|
NoteAuthorPicture(note, navController, account.userProfile(), 25.dp)
|
2023-02-21 20:48:57 +00:00
|
|
|
Spacer(Modifier.padding(horizontal = 5.dp))
|
|
|
|
NoteUsernameDisplay(note, Modifier.weight(1f))
|
2023-02-21 01:51:27 +00:00
|
|
|
} else {
|
|
|
|
NoteUsernameDisplay(note, Modifier.weight(1f))
|
2023-02-20 23:09:57 +00:00
|
|
|
}
|
2023-02-21 01:51:27 +00:00
|
|
|
|
2023-01-11 18:31:20 +00:00
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent !is RepostEvent) {
|
2023-01-11 18:31:20 +00:00
|
|
|
Text(
|
2023-02-19 00:14:52 +00:00
|
|
|
timeAgo(noteEvent.createdAt),
|
2023-01-19 22:57:43 +00:00
|
|
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
|
|
|
maxLines = 1
|
2023-01-11 18:31:20 +00:00
|
|
|
)
|
2023-02-12 23:23:02 +00:00
|
|
|
|
|
|
|
IconButton(
|
|
|
|
modifier = Modifier.then(Modifier.size(24.dp)),
|
|
|
|
onClick = { moreActionsExpanded = true }
|
|
|
|
) {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.Default.MoreVert,
|
|
|
|
null,
|
|
|
|
modifier = Modifier.size(15.dp),
|
|
|
|
tint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
|
|
|
)
|
|
|
|
|
|
|
|
NoteDropDownMenu(baseNote, moreActionsExpanded, { moreActionsExpanded = false }, accountViewModel)
|
|
|
|
}
|
2023-01-11 18:31:20 +00:00
|
|
|
} else {
|
|
|
|
Text(
|
|
|
|
" boosted",
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is TextNoteEvent && (note.replyTo != null || note.mentions != null)) {
|
2023-01-17 15:43:18 +00:00
|
|
|
ReplyInformation(note.replyTo, note.mentions, navController)
|
2023-02-19 00:14:52 +00:00
|
|
|
} else if (noteEvent is ChannelMessageEvent && (note.replyTo != null || note.mentions != null)) {
|
2023-01-19 22:58:35 +00:00
|
|
|
note.channel?.let {
|
|
|
|
ReplyInformationChannel(note.replyTo, note.mentions, it, navController)
|
|
|
|
}
|
2023-01-11 18:31:20 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is ReactionEvent || noteEvent is RepostEvent) {
|
2023-01-31 02:36:06 +00:00
|
|
|
note.replyTo?.lastOrNull()?.let {
|
2023-01-11 18:31:20 +00:00
|
|
|
NoteCompose(
|
2023-01-31 02:36:06 +00:00
|
|
|
it,
|
2023-01-25 13:46:14 +00:00
|
|
|
modifier = Modifier,
|
2023-02-20 23:09:57 +00:00
|
|
|
isBoostedNote = true,
|
2023-01-12 17:47:31 +00:00
|
|
|
accountViewModel = accountViewModel,
|
|
|
|
navController = navController
|
2023-01-11 18:31:20 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reposts have trash in their contents.
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent is ReactionEvent) {
|
2023-01-11 18:31:20 +00:00
|
|
|
val refactorReactionText =
|
2023-02-19 00:14:52 +00:00
|
|
|
if (noteEvent.content == "+") "❤" else noteEvent.content ?: " "
|
2023-01-11 18:31:20 +00:00
|
|
|
|
|
|
|
Text(
|
|
|
|
text = refactorReactionText
|
|
|
|
)
|
|
|
|
}
|
2023-02-19 00:14:52 +00:00
|
|
|
} else if (noteEvent is ReportEvent) {
|
|
|
|
val reportType = noteEvent.reportType.map {
|
|
|
|
when (it) {
|
|
|
|
ReportEvent.ReportType.EXPLICIT -> "Explicit Content"
|
|
|
|
ReportEvent.ReportType.SPAM -> "Spam"
|
|
|
|
ReportEvent.ReportType.IMPERSONATION -> "Impersonation"
|
|
|
|
ReportEvent.ReportType.ILLEGAL -> "Illegal Behavior"
|
|
|
|
else -> "Unkown"
|
|
|
|
}
|
|
|
|
}.joinToString(", ")
|
|
|
|
|
|
|
|
Text(
|
|
|
|
text = reportType
|
|
|
|
)
|
|
|
|
|
|
|
|
Divider(
|
|
|
|
modifier = Modifier.padding(top = 10.dp),
|
|
|
|
thickness = 0.25.dp
|
|
|
|
)
|
2023-01-11 18:31:20 +00:00
|
|
|
} else {
|
2023-02-19 00:14:52 +00:00
|
|
|
val eventContent = noteEvent.content
|
2023-02-05 23:12:11 +00:00
|
|
|
val canPreview = note.author == account.userProfile()
|
|
|
|
|| (note.author?.let { account.userProfile().isFollowing(it) } ?: true )
|
|
|
|
|| !noteForReports.hasAnyReports()
|
|
|
|
|
2023-01-30 01:06:48 +00:00
|
|
|
if (eventContent != null) {
|
2023-02-08 16:57:36 +00:00
|
|
|
TranslateableRichTextViewer(
|
|
|
|
eventContent,
|
|
|
|
canPreview,
|
2023-02-20 22:36:20 +00:00
|
|
|
Modifier.fillMaxWidth(),
|
2023-02-19 00:14:52 +00:00
|
|
|
noteEvent.tags,
|
2023-02-08 16:57:36 +00:00
|
|
|
accountViewModel,
|
|
|
|
navController
|
|
|
|
)
|
2023-01-30 01:06:48 +00:00
|
|
|
}
|
2023-01-31 02:36:06 +00:00
|
|
|
|
2023-01-27 18:50:17 +00:00
|
|
|
ReactionsRow(note, accountViewModel)
|
2023-01-11 18:31:20 +00:00
|
|
|
|
|
|
|
Divider(
|
2023-01-12 17:47:31 +00:00
|
|
|
modifier = Modifier.padding(top = 10.dp),
|
2023-01-11 18:31:20 +00:00
|
|
|
thickness = 0.25.dp
|
|
|
|
)
|
|
|
|
}
|
2023-01-13 15:20:54 +00:00
|
|
|
|
|
|
|
NoteDropDownMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel)
|
2023-01-11 18:31:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:20:54 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 22:16:27 +00:00
|
|
|
@Composable
|
|
|
|
private fun RelayBadges(baseNote: Note) {
|
2023-02-19 16:22:01 +00:00
|
|
|
val noteRelaysState by baseNote.live().relays.observeAsState()
|
2023-02-06 22:16:27 +00:00
|
|
|
val noteRelays = noteRelaysState?.note?.relays ?: emptySet()
|
|
|
|
|
|
|
|
var expanded by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
val relaysToDisplay = if (expanded) noteRelays else noteRelays.take(3)
|
|
|
|
|
|
|
|
val uri = LocalUriHandler.current
|
2023-02-10 22:13:25 +00:00
|
|
|
val ctx = LocalContext.current.applicationContext
|
2023-02-06 22:16:27 +00:00
|
|
|
|
|
|
|
FlowRow(Modifier.padding(top = 10.dp, start = 5.dp, end = 4.dp)) {
|
|
|
|
relaysToDisplay.forEach {
|
2023-02-14 15:58:42 +00:00
|
|
|
val url = it.removePrefix("wss://").removePrefix("ws://")
|
2023-02-12 23:23:02 +00:00
|
|
|
Box(
|
|
|
|
Modifier
|
|
|
|
.size(15.dp)
|
|
|
|
.padding(1.dp)) {
|
2023-02-17 00:41:50 +00:00
|
|
|
AsyncImage(
|
|
|
|
model = "https://${url}/favicon.ico",
|
2023-02-14 19:25:26 +00:00
|
|
|
placeholder = BitmapPainter(RoboHashCache.get(ctx, url)),
|
|
|
|
fallback = BitmapPainter(RoboHashCache.get(ctx, url)),
|
|
|
|
error = BitmapPainter(RoboHashCache.get(ctx, url)),
|
2023-02-06 22:16:27 +00:00
|
|
|
contentDescription = "Relay Icon",
|
|
|
|
colorFilter = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0f) }),
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize(1f)
|
|
|
|
.clip(shape = CircleShape)
|
|
|
|
.background(MaterialTheme.colors.background)
|
2023-02-12 23:23:02 +00:00
|
|
|
.clickable(onClick = { uri.openUri("https://" + url) })
|
2023-02-06 22:16:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noteRelays.size > 3 && !expanded) {
|
2023-02-12 23:23:02 +00:00
|
|
|
Row(
|
|
|
|
Modifier
|
|
|
|
.fillMaxWidth()
|
|
|
|
.height(25.dp), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.Top) {
|
2023-02-06 22:16:27 +00:00
|
|
|
IconButton(
|
|
|
|
modifier = Modifier.then(Modifier.size(24.dp)),
|
|
|
|
onClick = { expanded = true }
|
|
|
|
) {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.Default.ExpandMore,
|
|
|
|
null,
|
|
|
|
modifier = Modifier.size(15.dp),
|
|
|
|
tint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
|
2023-01-26 16:16:57 +00:00
|
|
|
@Composable
|
2023-02-01 01:12:24 +00:00
|
|
|
fun NoteAuthorPicture(
|
|
|
|
note: Note,
|
2023-01-26 16:16:57 +00:00
|
|
|
navController: NavController,
|
|
|
|
userAccount: User,
|
|
|
|
size: Dp,
|
|
|
|
pictureModifier: Modifier = Modifier
|
|
|
|
) {
|
2023-02-01 01:12:24 +00:00
|
|
|
NoteAuthorPicture(note, userAccount, size, pictureModifier) {
|
|
|
|
navController.navigate("User/${it.pubkeyHex}")
|
2023-01-26 16:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
|
2023-01-26 16:16:57 +00:00
|
|
|
@Composable
|
2023-02-01 01:12:24 +00:00
|
|
|
fun NoteAuthorPicture(
|
|
|
|
baseNote: Note,
|
|
|
|
baseUserAccount: User,
|
2023-01-26 16:16:57 +00:00
|
|
|
size: Dp,
|
|
|
|
pictureModifier: Modifier = Modifier,
|
2023-02-01 01:12:24 +00:00
|
|
|
onClick: ((User) -> Unit)? = null
|
2023-01-26 16:16:57 +00:00
|
|
|
) {
|
2023-02-19 16:22:01 +00:00
|
|
|
val noteState by baseNote.live().metadata.observeAsState()
|
2023-02-01 01:12:24 +00:00
|
|
|
val note = noteState?.note ?: return
|
|
|
|
|
|
|
|
val author = note.author
|
2023-01-28 01:05:22 +00:00
|
|
|
|
2023-02-10 22:13:25 +00:00
|
|
|
val ctx = LocalContext.current.applicationContext
|
|
|
|
|
2023-01-26 16:16:57 +00:00
|
|
|
Box(
|
|
|
|
Modifier
|
|
|
|
.width(size)
|
|
|
|
.height(size)) {
|
2023-02-01 01:12:24 +00:00
|
|
|
if (author == null) {
|
2023-02-13 13:45:32 +00:00
|
|
|
Image(
|
2023-02-14 19:25:26 +00:00
|
|
|
painter = BitmapPainter(RoboHashCache.get(ctx, "ohnothisauthorisnotfound")),
|
2023-02-01 01:12:24 +00:00
|
|
|
contentDescription = "Unknown Author",
|
2023-01-26 16:16:57 +00:00
|
|
|
modifier = pictureModifier
|
|
|
|
.fillMaxSize(1f)
|
|
|
|
.clip(shape = CircleShape)
|
|
|
|
.background(MaterialTheme.colors.background)
|
|
|
|
)
|
|
|
|
} else {
|
2023-02-01 01:12:24 +00:00
|
|
|
UserPicture(author, baseUserAccount, size, pictureModifier, onClick)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-28 01:05:22 +00:00
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
@Composable
|
|
|
|
fun UserPicture(
|
|
|
|
user: User,
|
|
|
|
navController: NavController,
|
|
|
|
userAccount: User,
|
|
|
|
size: Dp,
|
|
|
|
pictureModifier: Modifier = Modifier
|
|
|
|
) {
|
|
|
|
UserPicture(user, userAccount, size, pictureModifier) {
|
|
|
|
navController.navigate("User/${it.pubkeyHex}")
|
|
|
|
}
|
|
|
|
}
|
2023-01-26 16:16:57 +00:00
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
@Composable
|
|
|
|
fun UserPicture(
|
|
|
|
baseUser: User,
|
|
|
|
baseUserAccount: User,
|
|
|
|
size: Dp,
|
|
|
|
pictureModifier: Modifier = Modifier,
|
|
|
|
onClick: ((User) -> Unit)? = null
|
|
|
|
) {
|
2023-02-19 16:22:01 +00:00
|
|
|
val userState by baseUser.live().metadata.observeAsState()
|
2023-02-01 01:12:24 +00:00
|
|
|
val user = userState?.user ?: return
|
|
|
|
|
2023-02-10 22:13:25 +00:00
|
|
|
val ctx = LocalContext.current.applicationContext
|
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
Box(
|
|
|
|
Modifier
|
|
|
|
.width(size)
|
|
|
|
.height(size)) {
|
|
|
|
|
2023-02-15 17:31:15 +00:00
|
|
|
AsyncImageProxy(
|
|
|
|
model = ResizeImage(user.profilePicture(), size),
|
2023-02-01 01:12:24 +00:00
|
|
|
contentDescription = "Profile Image",
|
2023-02-14 19:25:26 +00:00
|
|
|
placeholder = BitmapPainter(RoboHashCache.get(ctx, user.pubkeyHex)),
|
|
|
|
fallback = BitmapPainter(RoboHashCache.get(ctx, user.pubkeyHex)),
|
|
|
|
error = BitmapPainter(RoboHashCache.get(ctx, user.pubkeyHex)),
|
2023-02-01 01:12:24 +00:00
|
|
|
modifier = pictureModifier
|
|
|
|
.fillMaxSize(1f)
|
|
|
|
.clip(shape = CircleShape)
|
|
|
|
.background(MaterialTheme.colors.background)
|
|
|
|
.run {
|
|
|
|
if (onClick != null)
|
|
|
|
this.clickable(onClick = { onClick(user) } )
|
|
|
|
else
|
|
|
|
this
|
2023-01-26 16:16:57 +00:00
|
|
|
}
|
2023-02-01 01:12:24 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
|
2023-02-19 16:22:01 +00:00
|
|
|
val accountState by baseUserAccount.live().follows.observeAsState()
|
2023-02-02 19:34:34 +00:00
|
|
|
val accountUser = accountState?.user ?: return
|
|
|
|
|
2023-02-01 01:12:24 +00:00
|
|
|
if (accountUser.isFollowing(user) || user == accountUser) {
|
|
|
|
Box(
|
|
|
|
Modifier
|
|
|
|
.width(size.div(3.5f))
|
|
|
|
.height(size.div(3.5f))
|
|
|
|
.align(Alignment.TopEnd),
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
) {
|
|
|
|
// Background for the transparent checkmark
|
2023-02-22 15:26:05 +00:00
|
|
|
Box(
|
2023-02-01 01:12:24 +00:00
|
|
|
Modifier
|
2023-02-22 15:26:05 +00:00
|
|
|
.clip(CircleShape)
|
|
|
|
.fillMaxSize(0.6f)
|
2023-02-01 01:12:24 +00:00
|
|
|
.align(Alignment.Center)
|
|
|
|
.background(MaterialTheme.colors.background)
|
|
|
|
)
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
painter = painterResource(R.drawable.ic_verified),
|
|
|
|
"Following",
|
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
|
tint = Following
|
|
|
|
)
|
2023-01-26 16:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-01 01:12:24 +00:00
|
|
|
|
2023-01-26 16:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:20:54 +00:00
|
|
|
@Composable
|
|
|
|
fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit, accountViewModel: AccountViewModel) {
|
|
|
|
val clipboardManager = LocalClipboardManager.current
|
2023-01-24 19:59:21 +00:00
|
|
|
val context = LocalContext.current.applicationContext
|
2023-01-13 15:20:54 +00:00
|
|
|
|
|
|
|
DropdownMenu(
|
|
|
|
expanded = popupExpanded,
|
|
|
|
onDismissRequest = onDismiss
|
|
|
|
) {
|
2023-01-18 20:55:10 +00:00
|
|
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(accountViewModel.decrypt(note) ?: "")); onDismiss() }) {
|
2023-01-13 15:20:54 +00:00
|
|
|
Text("Copy Text")
|
|
|
|
}
|
2023-02-19 16:22:01 +00:00
|
|
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(note.author?.pubkeyNpub() ?: "")); onDismiss() }) {
|
2023-01-30 01:06:48 +00:00
|
|
|
Text("Copy User PubKey")
|
2023-01-13 15:20:54 +00:00
|
|
|
}
|
2023-02-19 16:22:01 +00:00
|
|
|
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(note.idNote())); onDismiss() }) {
|
2023-01-13 15:20:54 +00:00
|
|
|
Text("Copy Note ID")
|
|
|
|
}
|
|
|
|
Divider()
|
|
|
|
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
|
|
|
|
Text("Broadcast")
|
|
|
|
}
|
2023-02-22 21:17:56 +00:00
|
|
|
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile) {
|
|
|
|
Divider()
|
|
|
|
DropdownMenuItem(onClick = {
|
|
|
|
note.author?.let {
|
|
|
|
accountViewModel.hide(
|
|
|
|
it,
|
|
|
|
context
|
|
|
|
)
|
|
|
|
}; onDismiss()
|
|
|
|
}) {
|
|
|
|
Text("Block & Hide User")
|
|
|
|
}
|
|
|
|
Divider()
|
|
|
|
DropdownMenuItem(onClick = {
|
|
|
|
accountViewModel.report(note, ReportEvent.ReportType.SPAM);
|
|
|
|
note.author?.let { accountViewModel.hide(it, context) }
|
|
|
|
onDismiss()
|
|
|
|
}) {
|
|
|
|
Text("Report Spam / Scam")
|
|
|
|
}
|
|
|
|
DropdownMenuItem(onClick = {
|
|
|
|
accountViewModel.report(note, ReportEvent.ReportType.IMPERSONATION);
|
|
|
|
note.author?.let { accountViewModel.hide(it, context) }
|
|
|
|
onDismiss()
|
|
|
|
}) {
|
|
|
|
Text("Report Impersonation")
|
|
|
|
}
|
|
|
|
DropdownMenuItem(onClick = {
|
|
|
|
accountViewModel.report(note, ReportEvent.ReportType.EXPLICIT);
|
|
|
|
note.author?.let { accountViewModel.hide(it, context) }
|
|
|
|
onDismiss()
|
|
|
|
}) {
|
|
|
|
Text("Report Explicit Content")
|
|
|
|
}
|
|
|
|
DropdownMenuItem(onClick = {
|
|
|
|
accountViewModel.report(note, ReportEvent.ReportType.ILLEGAL);
|
|
|
|
note.author?.let { accountViewModel.hide(it, context) }
|
|
|
|
onDismiss()
|
|
|
|
}) {
|
|
|
|
Text("Report Illegal Behaviour")
|
|
|
|
}
|
2023-01-30 01:06:48 +00:00
|
|
|
}
|
2023-01-13 15:20:54 +00:00
|
|
|
}
|
2023-01-11 18:31:20 +00:00
|
|
|
}
|