From 6e1182d163b7633cb43045b059309f243a5f012c Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 12 Dec 2022 13:58:55 -0800 Subject: [PATCH] add graphql files for archiving and deleting in android --- .../main/graphql/ArchiveLinkedItem.graphql | 12 +++++++++ .../src/main/graphql/DeleteLinkedItem.graphql | 12 +++++++++ .../networking/LinkedItemMutations.kt | 26 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 android/Omnivore/app/src/main/graphql/ArchiveLinkedItem.graphql create mode 100644 android/Omnivore/app/src/main/graphql/DeleteLinkedItem.graphql create mode 100644 android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemMutations.kt diff --git a/android/Omnivore/app/src/main/graphql/ArchiveLinkedItem.graphql b/android/Omnivore/app/src/main/graphql/ArchiveLinkedItem.graphql new file mode 100644 index 000000000..7f0bff0a5 --- /dev/null +++ b/android/Omnivore/app/src/main/graphql/ArchiveLinkedItem.graphql @@ -0,0 +1,12 @@ +mutation SetLinkArchived($input: ArchiveLinkInput!) { + setLinkArchived(input: $input) { + ... on ArchiveLinkSuccess { + linkId + message + } + ... on ArchiveLinkError { + message + errorCodes + } + } +} diff --git a/android/Omnivore/app/src/main/graphql/DeleteLinkedItem.graphql b/android/Omnivore/app/src/main/graphql/DeleteLinkedItem.graphql new file mode 100644 index 000000000..cabbc6a0d --- /dev/null +++ b/android/Omnivore/app/src/main/graphql/DeleteLinkedItem.graphql @@ -0,0 +1,12 @@ +mutation SetBookmarkArticle($input: SetBookmarkArticleInput!) { + setBookmarkArticle(input: $input) { + ... on SetBookmarkArticleSuccess { + bookmarkedArticle { + id + } + } + ... on SetBookmarkArticleError { + errorCodes + } + } +} diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemMutations.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemMutations.kt new file mode 100644 index 000000000..b2ee7a0b2 --- /dev/null +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemMutations.kt @@ -0,0 +1,26 @@ +package app.omnivore.omnivore.networking + +import app.omnivore.omnivore.graphql.generated.SetBookmarkArticleMutation +import app.omnivore.omnivore.graphql.generated.SetLinkArchivedMutation +import app.omnivore.omnivore.graphql.generated.type.ArchiveLinkInput +import app.omnivore.omnivore.graphql.generated.type.SetBookmarkArticleInput + +suspend fun Networker.deleteLinkedItem(itemID: String): Boolean { + val input = SetBookmarkArticleInput(itemID, false) + val result = authenticatedApolloClient().mutation(SetBookmarkArticleMutation(input)).execute() + return result.data?.setBookmarkArticle?.onSetBookmarkArticleSuccess?.bookmarkedArticle?.id != null +} + +suspend fun Networker.archiveLinkedItem(itemID: String): Boolean { + return updateArchiveStatusLinkedItem(itemID, true) +} + +suspend fun Networker.unarchiveLinkedItem(itemID: String): Boolean { + return updateArchiveStatusLinkedItem(itemID, false) +} + +private suspend fun Networker.updateArchiveStatusLinkedItem(itemID: String, setAsArchived: Boolean): Boolean { + val input = ArchiveLinkInput(setAsArchived, itemID) + val result = authenticatedApolloClient().mutation(SetLinkArchivedMutation(input)).execute() + return result.data?.setLinkArchived?.onArchiveLinkSuccess?.linkId != null +}