Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NostrFilter private constructor(
@SerialName("#t") private val topicList: List<String>? = null,
private val since: Long? = null,
private val until: Long? = null,
private val search: String? = null,
private val limit: Int = 1
) {

Expand All @@ -26,6 +27,7 @@ class NostrFilter private constructor(
Topic:$topicList
Since:$since
Until:$until
Search:$search
Limit:$limit
""".trimIndent()

Expand All @@ -42,6 +44,7 @@ class NostrFilter private constructor(
private var topicList: List<String>? = null
private var since: Long? = null
private var until: Long? = null
private var search: String? = null
private var limit: Int = 1

fun idList(vararg iDList: String = emptyArray()) = apply {
Expand Down Expand Up @@ -76,6 +79,10 @@ class NostrFilter private constructor(
until = timeStamp
}

fun search(searchString: String? = null) = apply {
search = searchString
}

fun limit(receivingEventLimit: Int) = apply {
limit = receivingEventLimit
}
Expand All @@ -89,6 +96,7 @@ class NostrFilter private constructor(
topicList = topicList,
since = since,
until = until,
search = search,
limit = limit
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,21 @@ class NostrFilterTest {
assertEquals(correctRequestJson, filterJson)
}

@Test
fun `filter with search parameter serializes correctly`(){
val currentTimestamp = 1653822739L
val previousTimestamp = currentTimestamp - 24 * 60 * 60
val searchFilter = NostrFilter.newFilter()
.kinds(EventKind.TEXT_NOTE.kind)
.search("bitcoin")
.since(previousTimestamp)
.until(currentTimestamp)
.limit(10)
.build()
val filterJson = nostrFilterEventMapper.encodeToString(searchFilter)
val correctSearchJson = """{"kinds":[1],"since":1653736339,"until":1653822739,"search":"bitcoin","limit":10}"""
println("Search filter JSON: $filterJson")
assertEquals(correctSearchJson, filterJson)
}

}
Loading