mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-01 07:40:42 +02:00
Only showing notifications if it directly cites the account holder
This commit is contained in:
@ -2,6 +2,8 @@ package com.vitorpamplona.amethyst.model
|
|||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource
|
import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
||||||
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
@ -14,8 +16,12 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
|
import java.util.regex.Matcher
|
||||||
|
import java.util.regex.Pattern
|
||||||
import nostr.postr.events.Event
|
import nostr.postr.events.Event
|
||||||
|
|
||||||
|
val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]")
|
||||||
|
|
||||||
class Note(val idHex: String) {
|
class Note(val idHex: String) {
|
||||||
// These fields are always available.
|
// These fields are always available.
|
||||||
// They are immutable
|
// They are immutable
|
||||||
@ -117,6 +123,29 @@ class Note(val idHex: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun directlyCiteUsers(): Set<User> {
|
||||||
|
val matcher = tagSearch.matcher(event?.content ?: "")
|
||||||
|
val returningList = mutableSetOf<User>()
|
||||||
|
while (matcher.find()) {
|
||||||
|
try {
|
||||||
|
val tag = event?.tags?.get(matcher.group(1).toInt())
|
||||||
|
if (tag != null && tag[0] == "p") {
|
||||||
|
returningList.add(LocalCache.getOrCreateUser(tag[1]))
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returningList
|
||||||
|
}
|
||||||
|
|
||||||
|
fun directlyCites(userProfile: User): Boolean {
|
||||||
|
return author == userProfile
|
||||||
|
|| (userProfile in directlyCiteUsers())
|
||||||
|
|| (event is ReactionEvent && replyTo?.lastOrNull()?.directlyCites(userProfile) == true)
|
||||||
|
|| (event is RepostEvent && replyTo?.lastOrNull()?.directlyCites(userProfile) == true)
|
||||||
|
}
|
||||||
|
|
||||||
// Observers line up here.
|
// Observers line up here.
|
||||||
val live: NoteLiveData = NoteLiveData(this)
|
val live: NoteLiveData = NoteLiveData(this)
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.vitorpamplona.amethyst.model.Account
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
||||||
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
import nostr.postr.JsonFilter
|
import nostr.postr.JsonFilter
|
||||||
@ -25,7 +26,9 @@ object NostrNotificationDataSource: NostrDataSource<Note>("NotificationFeed") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return filtered.filter {
|
return filtered.filter {
|
||||||
it.event !is ChannelCreateEvent && it.event !is ChannelMetadataEvent
|
it.event !is ChannelCreateEvent
|
||||||
|
&& it.event !is ChannelMetadataEvent
|
||||||
|
&& it.directlyCites(account.userProfile())
|
||||||
}.sortedBy { it.event?.createdAt }.reversed()
|
}.sortedBy { it.event?.createdAt }.reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user