Brings the findCitedUsers function to BaseTextNote Event with cache.
This commit is contained in:
@@ -57,7 +57,7 @@ open class Note(val idHex: String) {
|
|||||||
val channelHex =
|
val channelHex =
|
||||||
(event as? ChannelMessageEvent)?.channel()
|
(event as? ChannelMessageEvent)?.channel()
|
||||||
?: (event as? ChannelMetadataEvent)?.channel()
|
?: (event as? ChannelMetadataEvent)?.channel()
|
||||||
?: (event as? ChannelCreateEvent)?.let { it.id }
|
?: (event as? ChannelCreateEvent)?.id
|
||||||
|
|
||||||
return channelHex?.let { LocalCache.checkGetOrCreateChannel(it) }
|
return channelHex?.let { LocalCache.checkGetOrCreateChannel(it) }
|
||||||
}
|
}
|
||||||
@@ -270,45 +270,6 @@ open class Note(val idHex: String) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun directlyCiteUsersHex(): Set<HexKey> {
|
|
||||||
val matcher = tagSearch.matcher(event?.content() ?: "")
|
|
||||||
val returningList = mutableSetOf<String>()
|
|
||||||
while (matcher.find()) {
|
|
||||||
try {
|
|
||||||
val tag = matcher.group(1)?.let { event?.tags()?.get(it.toInt()) }
|
|
||||||
if (tag != null && tag[0] == "p") {
|
|
||||||
returningList.add(tag[1])
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return returningList
|
|
||||||
}
|
|
||||||
|
|
||||||
fun directlyCiteUsers(): Set<User> {
|
|
||||||
val matcher = tagSearch.matcher(event?.content() ?: "")
|
|
||||||
val returningList = mutableSetOf<User>()
|
|
||||||
while (matcher.find()) {
|
|
||||||
try {
|
|
||||||
val tag = matcher.group(1)?.let { event?.tags()?.get(it.toInt()) }
|
|
||||||
if (tag != null && tag[0] == "p") {
|
|
||||||
LocalCache.checkGetOrCreateUser(tag[1])?.let {
|
|
||||||
returningList.add(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isNewThread(): Boolean {
|
fun isNewThread(): Boolean {
|
||||||
return event is RepostEvent || replyTo == null || replyTo?.size == 0
|
return event is RepostEvent || replyTo == null || replyTo?.size == 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,26 @@ open class BaseTextNoteEvent(
|
|||||||
fun mentions() = taggedUsers()
|
fun mentions() = taggedUsers()
|
||||||
open fun replyTos() = tags.filter { it.firstOrNull() == "e" }.mapNotNull { it.getOrNull(1) }
|
open fun replyTos() = tags.filter { it.firstOrNull() == "e" }.mapNotNull { it.getOrNull(1) }
|
||||||
|
|
||||||
|
private var citedUsersCache: Set<HexKey>? = null
|
||||||
|
|
||||||
|
fun citedUsers(): Set<HexKey> {
|
||||||
|
citedUsersCache?.let { return it }
|
||||||
|
|
||||||
|
val matcher = tagSearch.matcher(content)
|
||||||
|
val returningList = mutableSetOf<String>()
|
||||||
|
while (matcher.find()) {
|
||||||
|
try {
|
||||||
|
val tag = matcher.group(1)?.let { tags[it.toInt()] }
|
||||||
|
if (tag != null && tag.size > 1 && tag[0] == "p") {
|
||||||
|
returningList.add(tag[1])
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
citedUsersCache = returningList
|
||||||
|
return returningList
|
||||||
|
}
|
||||||
|
|
||||||
fun findCitations(): Set<String> {
|
fun findCitations(): Set<String> {
|
||||||
var citations = mutableSetOf<String>()
|
var citations = mutableSetOf<String>()
|
||||||
// Removes citations from replies:
|
// Removes citations from replies:
|
||||||
@@ -22,10 +42,10 @@ open class BaseTextNoteEvent(
|
|||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
try {
|
try {
|
||||||
val tag = matcher.group(1)?.let { tags[it.toInt()] }
|
val tag = matcher.group(1)?.let { tags[it.toInt()] }
|
||||||
if (tag != null && tag[0] == "e") {
|
if (tag != null && tag.size > 1 && tag[0] == "e") {
|
||||||
citations.add(tag[1])
|
citations.add(tag[1])
|
||||||
}
|
}
|
||||||
if (tag != null && tag[0] == "a") {
|
if (tag != null && tag.size > 1 && tag[0] == "a") {
|
||||||
citations.add(tag[1])
|
citations.add(tag[1])
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user