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 +}