From 680e68f1c65c552882f556dcfe597d3ce5d81c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmedalija=20Kari=C5=A1ik?= Date: Thu, 12 Dec 2024 10:16:15 +0100 Subject: [PATCH] Fix: Save feed in MediaGrid (#250) --------- Co-authored-by: Aleksandar Ilic --- .../android/feeds/domain/FeedExtensions.kt | 10 +++++- .../feeds/domain/FeedExtensionsKtTest.kt | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) 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 32ed707f..c3ad9b27 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 3d791020..309b2e97 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))