Avoids parsing metadata events several times due to the json parser stopping coroutines.
This commit is contained in:
@@ -572,7 +572,7 @@ class Account(
|
||||
if (!isWriteable()) return
|
||||
|
||||
MetadataEvent.updateFromPast(
|
||||
latest = userProfile().info?.latestMetadata,
|
||||
latest = userProfile().latestMetadata,
|
||||
name = name,
|
||||
picture = picture,
|
||||
banner = banner,
|
||||
|
||||
@@ -304,15 +304,22 @@ object LocalCache {
|
||||
return note
|
||||
}
|
||||
|
||||
fun consume(event: MetadataEvent) {
|
||||
fun consume(
|
||||
event: MetadataEvent,
|
||||
relay: Relay?,
|
||||
) {
|
||||
// new event
|
||||
val oldUser = getOrCreateUser(event.pubKey)
|
||||
if (oldUser.info == null || event.createdAt > oldUser.info!!.updatedMetadataAt) {
|
||||
val currentMetadata = oldUser.latestMetadata
|
||||
|
||||
if (currentMetadata == null || event.createdAt > currentMetadata.createdAt) {
|
||||
oldUser.latestMetadata = event
|
||||
|
||||
val newUserMetadata = event.contactMetaData()
|
||||
if (newUserMetadata != null) {
|
||||
oldUser.updateUserInfo(newUserMetadata, event)
|
||||
}
|
||||
// Log.d("MT", "New User Metadata ${oldUser.pubkeyDisplayHex} ${oldUser.toBestDisplayName()}")
|
||||
// Log.d("MT", "New User Metadata ${oldUser.pubkeyDisplayHex()} ${oldUser.toBestDisplayName()} from ${relay?.url}")
|
||||
} else {
|
||||
// Log.d("MT","Relay sent a previous Metadata Event ${oldUser.toBestDisplayName()}
|
||||
// ${formattedDateTime(event.createdAt)} > ${formattedDateTime(oldUser.updatedAt)}")
|
||||
@@ -2099,7 +2106,7 @@ object LocalCache {
|
||||
is LnZapPaymentRequestEvent -> consume(event)
|
||||
is LnZapPaymentResponseEvent -> consume(event)
|
||||
is LongTextNoteEvent -> consume(event, relay)
|
||||
is MetadataEvent -> consume(event)
|
||||
is MetadataEvent -> consume(event, relay)
|
||||
is MuteListEvent -> consume(event, relay)
|
||||
is NNSEvent -> comsume(event, relay)
|
||||
is OtsEvent -> consume(event, relay)
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.math.BigDecimal
|
||||
class User(val pubkeyHex: String) {
|
||||
var info: UserMetadata? = null
|
||||
|
||||
var latestMetadata: MetadataEvent? = null
|
||||
var latestContactList: ContactListEvent? = null
|
||||
var latestBookmarkList: BookmarkListEvent? = null
|
||||
|
||||
@@ -307,8 +308,6 @@ class User(val pubkeyHex: String) {
|
||||
latestMetadata: MetadataEvent,
|
||||
) {
|
||||
info = newUserInfo
|
||||
info?.latestMetadata = latestMetadata
|
||||
info?.updatedMetadataAt = latestMetadata.createdAt
|
||||
info?.tags = latestMetadata.tags.toImmutableListOfLists()
|
||||
info?.cleanBlankNames()
|
||||
|
||||
|
||||
@@ -993,7 +993,7 @@ fun debugState(context: Context) {
|
||||
"Users: " +
|
||||
LocalCache.userListCache.filter { it.liveSet != null }.size +
|
||||
" / " +
|
||||
LocalCache.userListCache.filter { it.info?.latestMetadata != null }.size +
|
||||
LocalCache.userListCache.filter { it.latestMetadata != null }.size +
|
||||
" / " +
|
||||
LocalCache.userListCache.size,
|
||||
)
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.nip05
|
||||
import com.vitorpamplona.quartz.events.BaseTextNoteEvent
|
||||
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
||||
|
||||
@Composable
|
||||
fun ShowForkInformation(
|
||||
@@ -107,7 +106,7 @@ fun ForkInformationRowLightColor(
|
||||
val userState by author.live().metadata.observeAsState()
|
||||
val userDisplayName = remember(userState) { userState?.user?.toBestDisplayName() }
|
||||
val userTags =
|
||||
remember(userState) { userState?.user?.info?.latestMetadata?.tags?.toImmutableListOfLists() }
|
||||
remember(userState) { userState?.user?.info?.tags }
|
||||
|
||||
if (userDisplayName != null) {
|
||||
CreateClickableTextWithEmoji(
|
||||
|
||||
@@ -59,7 +59,6 @@ import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
||||
import com.vitorpamplona.quartz.events.UserMetadata
|
||||
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
@@ -135,7 +134,7 @@ fun ShowQRDialog(
|
||||
) {
|
||||
CreateTextWithEmoji(
|
||||
text = user.bestDisplayName() ?: user.bestUsername() ?: "",
|
||||
tags = user.info?.latestMetadata?.tags?.toImmutableListOfLists(),
|
||||
tags = user.info?.tags,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 18.sp,
|
||||
)
|
||||
|
||||
+1
-2
@@ -104,8 +104,7 @@ class SharedPreferencesViewModel : ViewModel() {
|
||||
fun init() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val savedSettings =
|
||||
LocalPreferences.loadSharedSettings()
|
||||
?: LocalPreferences.migrateOldSharedSettings() ?: Settings()
|
||||
LocalPreferences.loadSharedSettings() ?: Settings()
|
||||
|
||||
sharedPrefs.theme = savedSettings.theme
|
||||
sharedPrefs.language = savedSettings.preferredLanguage
|
||||
|
||||
@@ -176,7 +176,6 @@ import com.vitorpamplona.quartz.events.PayInvoiceSuccessResponse
|
||||
import com.vitorpamplona.quartz.events.ReportEvent
|
||||
import com.vitorpamplona.quartz.events.TelegramIdentity
|
||||
import com.vitorpamplona.quartz.events.TwitterIdentity
|
||||
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -961,8 +960,7 @@ private fun DrawAdditionalInfo(
|
||||
) {
|
||||
val userState by baseUser.live().metadata.observeAsState()
|
||||
val user = remember(userState) { userState?.user } ?: return
|
||||
val tags =
|
||||
remember(userState) { userState?.user?.info?.latestMetadata?.tags?.toImmutableListOfLists() }
|
||||
val tags = userState?.user?.info?.tags
|
||||
|
||||
val uri = LocalUriHandler.current
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
@@ -1071,7 +1069,7 @@ private fun DrawAdditionalInfo(
|
||||
val pubkeyHex = remember { baseUser.pubkeyHex }
|
||||
DisplayLNAddress(lud16, pubkeyHex, accountViewModel, nav)
|
||||
|
||||
val identities = user.info?.latestMetadata?.identityClaims()
|
||||
val identities = user.latestMetadata?.identityClaims()
|
||||
if (!identities.isNullOrEmpty()) {
|
||||
identities.forEach { identity: IdentityClaim ->
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
|
||||
@@ -414,12 +414,6 @@ class UserMetadata {
|
||||
|
||||
var twitter: String? = null
|
||||
|
||||
@Transient
|
||||
var updatedMetadataAt: Long = 0
|
||||
|
||||
@Transient
|
||||
var latestMetadata: MetadataEvent? = null
|
||||
|
||||
@Transient
|
||||
var tags: ImmutableListOfLists<String>? = null
|
||||
|
||||
|
||||
@@ -154,10 +154,7 @@ class MetadataEvent(
|
||||
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
fun contactMetaData() =
|
||||
try {
|
||||
mapper.readValue(
|
||||
ByteArrayInputStream(content.toByteArray(Charsets.UTF_8)),
|
||||
UserMetadata::class.java,
|
||||
)
|
||||
mapper.readValue(content, UserMetadata::class.java)
|
||||
} catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
Log.w("MT", "Content Parse Error: ${e.localizedMessage} $content")
|
||||
|
||||
Reference in New Issue
Block a user