Skip to content

Commit

Permalink
Fix: Save feed in MediaGrid (#250)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Aleksandar Ilic <[email protected]>
  • Loading branch information
mehmedalijaK and AleksandarIlic authored Dec 12, 2024
1 parent 0eb4e68 commit 680e68f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ fun buildArticleBookmarksFeedSpec(userId: String): String =
fun buildLatestNotesUserFeedSpec(userId: String) = """{"id":"feed","kind":"notes","pubkey":"$userId"}"""

fun String.resolveFeedSpecKind(): FeedSpecKind? {
// TODO Update to work with Image, Video and Sound search types
return when {
this.isNotesFeedSpec() -> FeedSpecKind.Notes
this.isReadsFeedSpec() -> FeedSpecKind.Reads
this.isImageSpec() -> FeedSpecKind.Notes
this.isVideoSpec() -> FeedSpecKind.Notes
this.isAudioSpec() -> FeedSpecKind.Notes
else -> null
}
}
Expand Down Expand Up @@ -161,6 +163,12 @@ fun String.resolveDefaultDescription(): String =

fun String.isNotesFeedSpec() = this.contains("\"kind\":\"notes\"") || this.contains("kind:1")

fun String.isImageSpec() = this.contains("\"query\":\"filter:image")

fun String.isVideoSpec() = this.contains("\"query\":\"filter:video")

fun String.isAudioSpec() = this.contains("\"query\":\"filter:audio")

fun String.isReadsFeedSpec() = this.contains("\"kind\":\"reads\"") || this.contains("kind:30023")

fun buildAdvancedSearchNotesFeedSpec(query: String) = """{"id":"advsearch","query":"kind:1 $query"}"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,40 @@ class FeedExtensionsKtTest {
spec.isNotesBookmarkFeedSpec() shouldBe false
}

@Test
fun isNotesFeedSpec_forProperFeedSpec_returnsTrue() {
val specId = "{\"id\":\"advsearch\",\"query\":\"kind:1 mehmedalija pas:1\"}"
val specText = "{\"id\":\"latest\",\"kind\":\"notes\"}"
specId.isNotesFeedSpec() shouldBe true
specText.isNotesFeedSpec() shouldBe true
}

@Test
fun isReadsFeedSpec_forProperFeedSpec_returnsTrue() {
val specId = "{\"id\":\"advsearch\",\"query\":\"kind:30023 code pas:1\"}"
val specText = "{\"id\":\"nostr-reads-feed\",\"kind\":\"reads\"}"
specId.isReadsFeedSpec() shouldBe true
specText.isReadsFeedSpec() shouldBe true
}

@Test
fun isImageFeedSpec_forProperFeedSpec_returnsTrue() {
val spec = "{\"id\":\"advsearch\",\"query\":\"filter:image waterfall pas:1\"}"
spec.isImageSpec() shouldBe true
}

@Test
fun isVideoFeedSpec_forProperFeedSpec_returnsTrue() {
val spec = "{\"id\":\"advsearch\",\"query\":\"filter:video running pas:1\"}"
spec.isVideoSpec() shouldBe true
}

@Test
fun isAudioFeedSpec_forProperFeedSpec_returnsTrue() {
val spec = "{\"id\":\"advsearch\",\"query\":\"filter:audio music pas:1\"}"
spec.isAudioSpec() shouldBe true
}

// @Test
// fun isReadsBookmarkFeedSpec_forProperFeedSpec_returnsTrue() {
// println(buildArticleBookmarksFeedSpec(userId = profileId))
Expand Down

0 comments on commit 680e68f

Please sign in to comment.