Adds notes to channels to facilitate their loading.

This commit is contained in:
Vitor Pamplona
2025-08-18 19:24:23 -04:00
parent 3bf6e80650
commit f31fa4a9c6
3 changed files with 14 additions and 5 deletions
@@ -852,7 +852,7 @@ object LocalCache : ILocalCache {
val creator = event.host()?.let { checkGetOrCreateUser(it.pubKey) } ?: author
channel.updateChannelInfo(creator, event)
channel.updateChannelInfo(creator, event, note)
refreshNewNoteObservers(note)
@@ -1548,7 +1548,7 @@ object LocalCache : ILocalCache {
if (oldChannel.creator == null || oldChannel.creator == author) {
if (isVerified || justVerify(event)) {
oldChannel.updateChannelInfo(author, event)
oldChannel.updateChannelInfo(author, event, note)
}
}
@@ -1567,6 +1567,8 @@ object LocalCache : ILocalCache {
val oldChannel = checkGetOrCreatePublicChatChannel(channelId) ?: return false
val author = getOrCreateUser(event.pubKey)
val note = getOrCreateNote(event.id)
val isVerified =
if (event.createdAt > oldChannel.updatedMetadataAt) {
if (wasVerified || justVerify(event)) {
@@ -1579,7 +1581,6 @@ object LocalCache : ILocalCache {
wasVerified
}
val note = getOrCreateNote(event.id)
if (note.event == null && (isVerified || justVerify(event))) {
oldChannel.addNote(note, relay)
note.loadEvent(event, author, emptyList())
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.model.nip28PublicChats
import androidx.compose.runtime.Stable
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.note.toShortDisplay
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
@@ -39,6 +40,7 @@ class PublicChatChannel(
) : Channel() {
var creator: User? = null
var event: ChannelCreateEvent? = null
var eventNote: Note? = null
var info = ChannelDataNorm(null, null, null, null)
var infoTags = EmptyTagList
@@ -61,13 +63,15 @@ class PublicChatChannel(
fun updateChannelInfo(
creator: User,
event: ChannelCreateEvent,
eventNote: Note? = null,
) {
this.creator = creator
this.event = event
this.info = event.channelInfo()
this.infoTags = event.tags.toImmutableListOfLists()
this.updatedMetadataAt = event.createdAt
this.eventNote = eventNote
updateChannelInfo()
}
@@ -77,8 +81,8 @@ class PublicChatChannel(
event: ChannelMetadataEvent,
) {
this.creator = creator
this.info = event.channelInfo()
this.infoTags = event.tags.toImmutableListOfLists()
this.updatedMetadataAt = event.createdAt
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.model.nip53LiveActivities
import androidx.compose.runtime.Stable
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.note.toShortDisplay
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
@@ -35,6 +36,7 @@ class LiveActivitiesChannel(
) : Channel() {
var creator: User? = null
var info: LiveActivitiesEvent? = null
var infoNote: Note? = null
fun address() = address
@@ -47,9 +49,11 @@ class LiveActivitiesChannel(
fun updateChannelInfo(
creator: User,
channelInfo: LiveActivitiesEvent,
channelInfoNote: Note,
) {
this.info = channelInfo
this.creator = creator
this.infoNote = channelInfoNote
super.updateChannelInfo()
}