Bugfix for channel metadata messages show up before channel creation packages

This commit is contained in:
Vitor Pamplona
2023-05-17 17:01:07 -04:00
parent 323e71c7cb
commit e41df98920
6 changed files with 44 additions and 27 deletions
@@ -553,17 +553,20 @@ object LocalCache {
// Log.d("MT", "New Event ${event.content} ${event.id.toHex()}") // Log.d("MT", "New Event ${event.content} ${event.id.toHex()}")
val oldChannel = getOrCreateChannel(event.id) val oldChannel = getOrCreateChannel(event.id)
val author = getOrCreateUser(event.pubKey) val author = getOrCreateUser(event.pubKey)
val note = getOrCreateNote(event.id)
if (note.event == null) {
oldChannel.addNote(note)
note.loadEvent(event, author, emptyList())
refreshObservers(note)
}
if (event.createdAt <= oldChannel.updatedMetadataAt) { if (event.createdAt <= oldChannel.updatedMetadataAt) {
return // older data, does nothing return // older data, does nothing
} }
if (oldChannel.creator == null || oldChannel.creator == author) { if (oldChannel.creator == null || oldChannel.creator == author) {
oldChannel.updateChannelInfo(author, event.channelInfo(), event.createdAt) oldChannel.updateChannelInfo(author, event.channelInfo(), event.createdAt)
val note = getOrCreateNote(event.id)
oldChannel.addNote(note)
note.loadEvent(event, author, emptyList())
refreshObservers(note)
} }
} }
@@ -578,16 +581,18 @@ object LocalCache {
if (event.createdAt > oldChannel.updatedMetadataAt) { if (event.createdAt > oldChannel.updatedMetadataAt) {
if (oldChannel.creator == null || oldChannel.creator == author) { if (oldChannel.creator == null || oldChannel.creator == author) {
oldChannel.updateChannelInfo(author, event.channelInfo(), event.createdAt) oldChannel.updateChannelInfo(author, event.channelInfo(), event.createdAt)
val note = getOrCreateNote(event.id)
oldChannel.addNote(note)
note.loadEvent(event, author, emptyList())
refreshObservers(note)
} }
} else { } else {
// Log.d("MT","Relay sent a previous Metadata Event ${oldUser.toBestDisplayName()} ${formattedDateTime(event.createdAt)} > ${formattedDateTime(oldUser.updatedAt)}") // Log.d("MT","Relay sent a previous Metadata Event ${oldUser.toBestDisplayName()} ${formattedDateTime(event.createdAt)} > ${formattedDateTime(oldUser.updatedAt)}")
} }
val note = getOrCreateNote(event.id)
if (note.event == null) {
oldChannel.addNote(note)
note.loadEvent(event, author, emptyList())
refreshObservers(note)
}
} }
fun consume(event: ChannelMessageEvent, relay: Relay?) { fun consume(event: ChannelMessageEvent, relay: Relay?) {
@@ -24,7 +24,7 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
@Composable @Composable
fun BlankNote(modifier: Modifier = Modifier, isQuote: Boolean = false) { fun BlankNote(modifier: Modifier = Modifier, isQuote: Boolean = false, idHex: String? = null) {
Column(modifier = modifier) { Column(modifier = modifier) {
Row(modifier = Modifier.padding(horizontal = if (!isQuote) 12.dp else 6.dp)) { Row(modifier = Modifier.padding(horizontal = if (!isQuote) 12.dp else 6.dp)) {
Column(modifier = Modifier.padding(start = if (!isQuote) 10.dp else 5.dp)) { Column(modifier = Modifier.padding(start = if (!isQuote) 10.dp else 5.dp)) {
@@ -39,7 +39,7 @@ fun BlankNote(modifier: Modifier = Modifier, isQuote: Boolean = false) {
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
Text( Text(
text = stringResource(R.string.post_not_found), text = stringResource(R.string.post_not_found) + if (idHex != null) ": $idHex" else "",
modifier = Modifier.padding(30.dp), modifier = Modifier.padding(30.dp),
color = Color.Gray color = Color.Gray
) )
@@ -90,12 +90,12 @@ fun ChatroomMessageCompose(
val loggedIn = remember(accountState) { accountState?.account?.userProfile() } ?: return val loggedIn = remember(accountState) { accountState?.account?.userProfile() } ?: return
val noteState by baseNote.live().metadata.observeAsState() val noteState by baseNote.live().metadata.observeAsState()
val note = remember(noteState) { noteState?.note } val note = remember(noteState) { noteState?.note } ?: return
val noteReportsState by baseNote.live().reports.observeAsState() val noteReportsState by baseNote.live().reports.observeAsState()
val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return
val noteEvent = note?.event val noteEvent = remember(noteState) { note.event }
var popupExpanded by remember { mutableStateOf(false) } var popupExpanded by remember { mutableStateOf(false) }
@@ -107,7 +107,7 @@ fun ChatroomMessageCompose(
) )
) )
note?.let { note.let {
NoteQuickActionMenu(it, popupExpanded, { popupExpanded = false }, accountViewModel) NoteQuickActionMenu(it, popupExpanded, { popupExpanded = false }, accountViewModel)
} }
} else if (account.isHidden(noteForReports.author!!)) { } else if (account.isHidden(noteForReports.author!!)) {
@@ -209,7 +209,11 @@ fun ChatroomMessageCompose(
shape = shape, shape = shape,
modifier = Modifier modifier = Modifier
.combinedClickable( .combinedClickable(
onClick = { }, onClick = {
if (noteEvent is ChannelCreateEvent) {
navController.navigate("Channel/${note.idHex}")
}
},
onLongClick = { popupExpanded = true } onLongClick = { popupExpanded = true }
) )
) { ) {
@@ -228,12 +232,14 @@ fun ChatroomMessageCompose(
alignment, alignment,
navController navController
) )
} else {
Spacer(modifier = Modifier.height(5.dp))
} }
val replyTo = note.replyTo val replyTo = note.replyTo
if (!innerQuote && !replyTo.isNullOrEmpty()) { if (!innerQuote && !replyTo.isNullOrEmpty()) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
replyTo.toSet().mapIndexed { _, note -> replyTo.lastOrNull()?.let { note ->
ChatroomMessageCompose( ChatroomMessageCompose(
note, note,
null, null,
@@ -196,13 +196,13 @@ fun NoteComposeInner(
val loggedIn = remember(accountState) { accountState?.account?.userProfile() } ?: return val loggedIn = remember(accountState) { accountState?.account?.userProfile() } ?: return
val noteState by baseNote.live().metadata.observeAsState() val noteState by baseNote.live().metadata.observeAsState()
val note = remember(noteState) { noteState?.note } val note = remember(noteState) { noteState?.note } ?: return
val noteReportsState by baseNote.live().reports.observeAsState() val noteReportsState by baseNote.live().reports.observeAsState()
val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return
val noteEvent = note?.event val noteEvent = remember(noteState) { note.event }
val baseChannel = note?.channel() val baseChannel = remember(noteState) { note.channel() }
var popupExpanded by remember { mutableStateOf(false) } var popupExpanded by remember { mutableStateOf(false) }
@@ -217,7 +217,7 @@ fun NoteComposeInner(
isBoostedNote isBoostedNote
) )
note?.let { note.let {
NoteQuickActionMenu(it, popupExpanded, { popupExpanded = false }, accountViewModel) NoteQuickActionMenu(it, popupExpanded, { popupExpanded = false }, accountViewModel)
} }
} else if (account.isHidden(noteForReports.author!!)) { } else if (account.isHidden(noteForReports.author!!)) {
@@ -217,10 +217,11 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
VerticalDivider(primaryLight) VerticalDivider(primaryLight)
NoteQuickActionItem( NoteQuickActionItem(
icon = ImageVector.vectorResource(id = R.drawable.text_select_move_forward_character), icon = ImageVector.vectorResource(id = R.drawable.relays),
label = stringResource(R.string.quick_action_select) label = stringResource(R.string.broadcast)
) { ) {
showSelectTextDialog = true accountViewModel.broadcast(note)
// showSelectTextDialog = true
onDismiss() onDismiss()
} }
VerticalDivider(primaryLight) VerticalDivider(primaryLight)
@@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn
import android.widget.Toast import android.widget.Toast
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
@@ -253,7 +254,11 @@ fun ChannelHeader(baseChannel: Channel, account: Account, navController: NavCont
val context = LocalContext.current.applicationContext val context = LocalContext.current.applicationContext
Column() { Column(
Modifier.clickable {
navController.navigate("Channel/${baseChannel.idHex}")
}
) {
Column(modifier = Modifier.padding(12.dp)) { Column(modifier = Modifier.padding(12.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
RobohashAsyncImageProxy( RobohashAsyncImageProxy(