diff --git a/app/src/main/kotlin/net/primal/android/feeds/domain/FeedExtensions.kt b/app/src/main/kotlin/net/primal/android/feeds/domain/FeedExtensions.kt index 32ed707ff..c3ad9b270 100644 --- a/app/src/main/kotlin/net/primal/android/feeds/domain/FeedExtensions.kt +++ b/app/src/main/kotlin/net/primal/android/feeds/domain/FeedExtensions.kt @@ -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 } } @@ -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"}""" diff --git a/app/src/test/kotlin/net/primal/android/feeds/domain/FeedExtensionsKtTest.kt b/app/src/test/kotlin/net/primal/android/feeds/domain/FeedExtensionsKtTest.kt index 3d7910208..309b2e975 100644 --- a/app/src/test/kotlin/net/primal/android/feeds/domain/FeedExtensionsKtTest.kt +++ b/app/src/test/kotlin/net/primal/android/feeds/domain/FeedExtensionsKtTest.kt @@ -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))