Not reloading reactions to an event.
This commit is contained in:
@@ -43,7 +43,7 @@ class Note(val idHex: String) {
|
|||||||
|
|
||||||
var channel: Channel? = null
|
var channel: Channel? = null
|
||||||
|
|
||||||
var lastDownloadTime: Long? = null
|
var lastReactionsDownloadTime: Long? = null
|
||||||
|
|
||||||
fun loadEvent(event: Event, author: User, mentions: List<User>, replyTo: MutableList<Note>) {
|
fun loadEvent(event: Event, author: User, mentions: List<User>, replyTo: MutableList<Note>) {
|
||||||
this.event = event
|
this.event = event
|
||||||
|
|||||||
+29
-13
@@ -9,29 +9,38 @@ import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
|||||||
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import java.util.Date
|
||||||
import nostr.postr.JsonFilter
|
import nostr.postr.JsonFilter
|
||||||
|
import nostr.postr.events.MetadataEvent
|
||||||
import nostr.postr.events.TextNoteEvent
|
import nostr.postr.events.TextNoteEvent
|
||||||
|
|
||||||
object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
|
object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
|
||||||
private var eventsToWatch = setOf<String>()
|
private var eventsToWatch = setOf<String>()
|
||||||
|
|
||||||
private fun createRepliesAndReactionsFilter(): JsonFilter? {
|
private fun createRepliesAndReactionsFilter(): List<JsonFilter>? {
|
||||||
val reactionsToWatch = eventsToWatch.map { it }
|
val reactionsToWatch = eventsToWatch.map { it }
|
||||||
|
|
||||||
if (reactionsToWatch.isEmpty()) {
|
if (reactionsToWatch.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloads all the reactions to a given event.
|
val now = Date().time / 1000
|
||||||
return JsonFilter(
|
|
||||||
kinds = listOf(
|
return eventsToWatch.filter {
|
||||||
TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind, ReportEvent.kind
|
val lastTime = LocalCache.getOrCreateNote(it).lastReactionsDownloadTime;
|
||||||
),
|
lastTime == null || lastTime < (now - 10)
|
||||||
tags = mapOf("e" to reactionsToWatch)
|
}.map {
|
||||||
)
|
JsonFilter(
|
||||||
|
kinds = listOf(
|
||||||
|
TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind, ReportEvent.kind
|
||||||
|
),
|
||||||
|
tags = mapOf("e" to listOf(it)),
|
||||||
|
since = LocalCache.getOrCreateNote(it).lastReactionsDownloadTime
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLoadEventsIfNotLoadedFilter(): JsonFilter? {
|
fun createLoadEventsIfNotLoadedFilter(): List<JsonFilter>? {
|
||||||
val directEventsToLoad = eventsToWatch
|
val directEventsToLoad = eventsToWatch
|
||||||
.map { LocalCache.getOrCreateNote(it) }
|
.map { LocalCache.getOrCreateNote(it) }
|
||||||
.filter { it.event == null }
|
.filter { it.event == null }
|
||||||
@@ -51,16 +60,23 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// downloads linked events to this event.
|
// downloads linked events to this event.
|
||||||
return JsonFilter(
|
return listOf(JsonFilter(
|
||||||
kinds = listOf(
|
kinds = listOf(
|
||||||
TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind,
|
TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind,
|
||||||
ChannelMessageEvent.kind, ChannelCreateEvent.kind, ChannelMetadataEvent.kind
|
ChannelMessageEvent.kind, ChannelCreateEvent.kind, ChannelMetadataEvent.kind
|
||||||
),
|
),
|
||||||
ids = interestedEvents.toList()
|
ids = interestedEvents.toList()
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
val singleEventChannel = requestNewChannel()
|
val singleEventChannel = requestNewChannel() { time ->
|
||||||
|
eventsToWatch.forEach {
|
||||||
|
LocalCache.getOrCreateNote(it).lastReactionsDownloadTime = time
|
||||||
|
}
|
||||||
|
// Many relays operate with limits in the amount of filters.
|
||||||
|
// As information comes, the filters will be rotated to get more data.
|
||||||
|
invalidateFilters()
|
||||||
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
return synchronized(eventsToWatch) {
|
return synchronized(eventsToWatch) {
|
||||||
@@ -74,7 +90,7 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
|
|||||||
val reactions = createRepliesAndReactionsFilter()
|
val reactions = createRepliesAndReactionsFilter()
|
||||||
val missing = createLoadEventsIfNotLoadedFilter()
|
val missing = createLoadEventsIfNotLoadedFilter()
|
||||||
|
|
||||||
singleEventChannel.filter = listOfNotNull(reactions, missing).ifEmpty { null }
|
singleEventChannel.filter = listOfNotNull(reactions, missing).flatten().ifEmpty { null }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(eventId: String) {
|
fun add(eventId: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user