Tracks where notes are coming from

This commit is contained in:
Vitor Pamplona 2023-01-30 19:38:06 -03:00
parent dc47845dd6
commit 3c52ff6e8d
4 changed files with 16 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Collections
import java.util.concurrent.ConcurrentHashMap
import com.vitorpamplona.amethyst.service.relays.Relay
import nostr.postr.events.ContactListEvent
import nostr.postr.events.DeletionEvent
import nostr.postr.events.Event
@ -94,9 +95,12 @@ object LocalCache {
.format(DateTimeFormatter.ofPattern("uuuu MMM d hh:mm a"))
}
fun consume(event: TextNoteEvent) {
fun consume(event: TextNoteEvent, relay: Relay? = null) {
val note = getOrCreateNote(event.id.toHex())
if (relay != null)
note.addRelay(relay)
// Already processed this event.
if (note.event != null) return

View File

@ -16,6 +16,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import com.vitorpamplona.amethyst.service.relays.Relay
import nostr.postr.events.Event
class Note(val idHex: String) {
@ -39,6 +40,8 @@ class Note(val idHex: String) {
var channel: Channel? = null
val relays = Collections.synchronizedSet(mutableSetOf<Relay>())
fun loadEvent(event: Event, author: User, mentions: List<User>, replyTo: MutableList<Note>) {
this.event = event
this.author = author
@ -90,6 +93,11 @@ class Note(val idHex: String) {
invalidateData(liveReactions)
}
fun addRelay(relay: Relay) {
if (relays.add(relay))
invalidateData(liveRelays)
}
fun addReport(note: Note) {
if (reports.add(note))
invalidateData(liveReports)
@ -126,6 +134,7 @@ class Note(val idHex: String) {
val liveBoosts: NoteLiveData = NoteLiveData(this)
val liveReplies: NoteLiveData = NoteLiveData(this)
val liveReports: NoteLiveData = NoteLiveData(this)
val liveRelays: NoteLiveData = NoteLiveData(this)
// Refreshes observers in batches.
var handlerWaiting = false

View File

@ -57,7 +57,7 @@ abstract class NostrDataSource<T>(val debugName: String) {
try {
when (event) {
is MetadataEvent -> LocalCache.consume(event)
is TextNoteEvent -> LocalCache.consume(event)
is TextNoteEvent -> LocalCache.consume(event, relay)
is RecommendRelayEvent -> LocalCache.consume(event)
is ContactListEvent -> LocalCache.consume(event)
is PrivateDmEvent -> LocalCache.consume(event)

View File

@ -258,11 +258,8 @@ fun NoteCompose(
RichTextViewer(eventContent, note.event?.tags, navController)
}
}
//if (note.event !is ChannelMessageEvent) {
ReactionsRow(note, accountViewModel)
//}
Divider(
modifier = Modifier.padding(top = 10.dp),