diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/HighlightMutations.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/HighlightMutations.kt index 46f988ec4..4bc72d7fa 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/HighlightMutations.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/HighlightMutations.kt @@ -79,9 +79,14 @@ suspend fun Networker.deleteHighlight(jsonString: String): Boolean { suspend fun Networker.deleteHighlights(highlightIDs: List): Boolean { val statuses: MutableList = mutableListOf() - for (highlightID in highlightIDs) { - val result = authenticatedApolloClient().mutation(DeleteHighlightMutation(highlightID)).execute() - statuses.add(result.data?.deleteHighlight?.onDeleteHighlightSuccess?.highlight != null) + try { + for (highlightID in highlightIDs) { + val result = + authenticatedApolloClient().mutation(DeleteHighlightMutation(highlightID)).execute() + statuses.add(result.data?.deleteHighlight?.onDeleteHighlightSuccess?.highlight != null) + } + } catch (e: java.lang.Exception) { + return false } val hasFailure = statuses.any { !it } @@ -94,9 +99,13 @@ suspend fun Networker.updateWebHighlight(jsonString: String): Boolean { } suspend fun Networker.updateHighlight(input: UpdateHighlightInput): Boolean { - val result = authenticatedApolloClient().mutation(UpdateHighlightMutation(input)).execute() - Log.d("Network", "update highlight result: $result") - return result.data?.updateHighlight?.onUpdateHighlightSuccess?.highlight != null + return try { + val result = authenticatedApolloClient().mutation(UpdateHighlightMutation(input)).execute() + Log.d("Network", "update highlight result: $result") + result.data?.updateHighlight?.onUpdateHighlightSuccess?.highlight != null + } catch (e: java.lang.Exception) { + false + } } suspend fun Networker.mergeWebHighlights(jsonString: String): Boolean { @@ -105,9 +114,13 @@ suspend fun Networker.mergeWebHighlights(jsonString: String): Boolean { } suspend fun Networker.mergeHighlights(input: MergeHighlightInput): Boolean { - val result = authenticatedApolloClient().mutation(MergeHighlightMutation(input)).execute() - Log.d("Network", "highlight merge result: $result") - return result.data?.mergeHighlight?.onMergeHighlightSuccess?.highlight != null + return try { + val result = authenticatedApolloClient().mutation(MergeHighlightMutation(input)).execute() + Log.d("Network", "highlight merge result: $result") + result.data?.mergeHighlight?.onMergeHighlightSuccess?.highlight != null + } catch (e: java.lang.Exception) { + false + } } suspend fun Networker.createWebHighlight(jsonString: String): Boolean { @@ -118,24 +131,28 @@ suspend fun Networker.createWebHighlight(jsonString: String): Boolean { suspend fun Networker.createHighlight(input: CreateHighlightInput): Highlight? { Log.d("Loggo", "created highlight input: $input") - val result = authenticatedApolloClient().mutation(CreateHighlightMutation(input)).execute() + try { + val result = authenticatedApolloClient().mutation(CreateHighlightMutation(input)).execute() - val createdHighlight = result.data?.createHighlight?.onCreateHighlightSuccess?.highlight + val createdHighlight = result.data?.createHighlight?.onCreateHighlightSuccess?.highlight - if (createdHighlight != null) { - return Highlight( - id = createdHighlight.highlightFields.id, - shortId = createdHighlight.highlightFields.shortId, - quote = createdHighlight.highlightFields.quote, - prefix = createdHighlight.highlightFields.prefix, - suffix = createdHighlight.highlightFields.suffix, - patch = createdHighlight.highlightFields.patch, - annotation = createdHighlight.highlightFields.annotation, - createdAt = null, // TODO: update gql query to get this - updatedAt = createdHighlight.highlightFields.updatedAt, - createdByMe = createdHighlight.highlightFields.createdByMe, - ) - } else { + if (createdHighlight != null) { + return Highlight( + id = createdHighlight.highlightFields.id, + shortId = createdHighlight.highlightFields.shortId, + quote = createdHighlight.highlightFields.quote, + prefix = createdHighlight.highlightFields.prefix, + suffix = createdHighlight.highlightFields.suffix, + patch = createdHighlight.highlightFields.patch, + annotation = createdHighlight.highlightFields.annotation, + createdAt = null, // TODO: update gql query to get this + updatedAt = createdHighlight.highlightFields.updatedAt, + createdByMe = createdHighlight.highlightFields.createdByMe, + ) + } else { + return null + } + } catch (e: java.lang.Exception) { return null } } 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 index b2ee7a0b2..f1a8ac87a 100644 --- 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 @@ -6,9 +6,13 @@ 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 + return try { + val input = SetBookmarkArticleInput(itemID, false) + val result = authenticatedApolloClient().mutation(SetBookmarkArticleMutation(input)).execute() + result.data?.setBookmarkArticle?.onSetBookmarkArticleSuccess?.bookmarkedArticle?.id != null + } catch (e: java.lang.Exception) { + false + } } suspend fun Networker.archiveLinkedItem(itemID: String): Boolean { @@ -20,7 +24,11 @@ suspend fun Networker.unarchiveLinkedItem(itemID: String): Boolean { } 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 + return try { + val input = ArchiveLinkInput(setAsArchived, itemID) + val result = authenticatedApolloClient().mutation(SetLinkArchivedMutation(input)).execute() + result.data?.setLinkArchived?.onArchiveLinkSuccess?.linkId != null + } catch (e: java.lang.Exception) { + false + } } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemQuery.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemQuery.kt index dfbb18588..79e6c13ad 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemQuery.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/LinkedItemQuery.kt @@ -18,63 +18,67 @@ data class LinkedItemQueryResponse( } suspend fun Networker.linkedItem(slug: String): LinkedItemQueryResponse { - val result = authenticatedApolloClient().query( - GetArticleQuery(slug = slug) - ).execute() + try { + val result = authenticatedApolloClient().query( + GetArticleQuery(slug = slug) + ).execute() - val article = result.data?.article?.onArticleSuccess?.article - ?: return LinkedItemQueryResponse.emptyResponse() + val article = result.data?.article?.onArticleSuccess?.article + ?: return LinkedItemQueryResponse.emptyResponse() - val labels = article.labels ?: listOf() + val labels = article.labels ?: listOf() - val linkedItemLabels = labels.map { - LinkedItemLabel( - id = it.labelFields.id, - name = it.labelFields.name, - color = it.labelFields.color, - createdAt = it.labelFields.createdAt, - labelDescription = it.labelFields.description + val linkedItemLabels = labels.map { + LinkedItemLabel( + id = it.labelFields.id, + name = it.labelFields.name, + color = it.labelFields.color, + createdAt = it.labelFields.createdAt, + labelDescription = it.labelFields.description + ) + } + + val highlights = article.highlights.map { + Highlight( + id = it.highlightFields.id, + shortId = it.highlightFields.shortId, + quote = it.highlightFields.quote, + prefix = it.highlightFields.prefix, + suffix = it.highlightFields.suffix, + patch = it.highlightFields.patch, + annotation = it.highlightFields.annotation, + createdAt = null, // TODO: update gql query to get this + updatedAt = it.highlightFields.updatedAt, + createdByMe = it.highlightFields.createdByMe, + ) + } + + // TODO: handle errors + + val linkedItem = LinkedItem( + id = article.articleFields.id, + title = article.articleFields.title, + createdAt = article.articleFields.createdAt, + savedAt = article.articleFields.savedAt, + readAt = article.articleFields.readAt, + updatedAt = article.articleFields.updatedAt, + readingProgress = article.articleFields.readingProgressPercent, + readingProgressAnchor = article.articleFields.readingProgressAnchorIndex, + imageURLString = article.articleFields.image, + pageURLString = article.articleFields.url, + descriptionText = article.articleFields.description, + publisherURLString = article.articleFields.originalArticleUrl, + siteName = article.articleFields.siteName, + author = article.articleFields.author, + publishDate = article.articleFields.publishedAt, + slug = article.articleFields.slug, + isArchived = article.articleFields.isArchived, + contentReader = article.articleFields.contentReader.rawValue, + content = article.articleFields.content ) + + return LinkedItemQueryResponse(item = linkedItem, highlights, labels = linkedItemLabels) + } catch (e: java.lang.Exception) { + return LinkedItemQueryResponse(item = null, listOf(), labels = listOf()) } - - val highlights = article.highlights.map { - Highlight( - id = it.highlightFields.id, - shortId = it.highlightFields.shortId, - quote = it.highlightFields.quote, - prefix = it.highlightFields.prefix, - suffix = it.highlightFields.suffix, - patch = it.highlightFields.patch, - annotation = it.highlightFields.annotation, - createdAt = null, // TODO: update gql query to get this - updatedAt = it.highlightFields.updatedAt, - createdByMe = it.highlightFields.createdByMe, - ) - } - - // TODO: handle errors - - val linkedItem = LinkedItem( - id = article.articleFields.id, - title = article.articleFields.title, - createdAt = article.articleFields.createdAt, - savedAt = article.articleFields.savedAt, - readAt = article.articleFields.readAt, - updatedAt = article.articleFields.updatedAt, - readingProgress = article.articleFields.readingProgressPercent, - readingProgressAnchor = article.articleFields.readingProgressAnchorIndex, - imageURLString = article.articleFields.image, - pageURLString = article.articleFields.url, - descriptionText = article.articleFields.description, - publisherURLString = article.articleFields.originalArticleUrl, - siteName = article.articleFields.siteName, - author = article.articleFields.author, - publishDate = article.articleFields.publishedAt, - slug = article.articleFields.slug, - isArchived = article.articleFields.isArchived, - contentReader = article.articleFields.contentReader.rawValue, - content = article.articleFields.content - ) - - return LinkedItemQueryResponse(item = linkedItem, highlights, labels = linkedItemLabels) } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ReadingProgressMutations.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ReadingProgressMutations.kt index b3f7419ca..2fb86e691 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ReadingProgressMutations.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ReadingProgressMutations.kt @@ -25,17 +25,22 @@ suspend fun Networker.updateWebReadingProgress(jsonString: String): Boolean { } suspend fun Networker.updateReadingProgress(params: ReadingProgressParams): Boolean { - val input = params.asSaveReadingProgressInput() + try { + val input = params.asSaveReadingProgressInput() - Log.d("Loggo", "created reading progress input: $input") + Log.d("Loggo", "created reading progress input: $input") - val result = authenticatedApolloClient() - .mutation(SaveArticleReadingProgressMutation(input)) - .execute() + val result = authenticatedApolloClient() + .mutation(SaveArticleReadingProgressMutation(input)) + .execute() - val articleID = result.data?.saveArticleReadingProgress?.onSaveArticleReadingProgressSuccess?.updatedArticle?.id + val articleID = + result.data?.saveArticleReadingProgress?.onSaveArticleReadingProgressSuccess?.updatedArticle?.id - Log.d("Loggo", "updated article with id: $articleID") + Log.d("Loggo", "updated article with id: $articleID") - return articleID != null + return articleID != null + } catch (e: java.lang.Exception) { + return false + } } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/SearchQuery.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/SearchQuery.kt index 7086c123e..ca43f6dc6 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/SearchQuery.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/SearchQuery.kt @@ -14,40 +14,45 @@ suspend fun Networker.search( limit: Int = 15, query: String ): SearchQueryResponse { - val result = authenticatedApolloClient().query( - SearchQuery( - after = Optional.presentIfNotNull(cursor), - first = Optional.presentIfNotNull(limit), - query = Optional.presentIfNotNull(query) - ) - ).execute() + try { + val result = authenticatedApolloClient().query( + SearchQuery( + after = Optional.presentIfNotNull(cursor), + first = Optional.presentIfNotNull(limit), + query = Optional.presentIfNotNull(query) + ) + ).execute() - val newCursor = result.data?.search?.onSearchSuccess?.pageInfo?.endCursor - val itemList = result.data?.search?.onSearchSuccess?.edges ?: listOf() - val items = itemList.map { - LinkedItem( - id = it.node.id, - title = it.node.title, - createdAt = it.node.createdAt, - savedAt = it.node.savedAt, - readAt = it.node.readAt, - updatedAt = it.node.updatedAt, - readingProgress = it.node.readingProgressPercent, - readingProgressAnchor = it.node.readingProgressAnchorIndex, - imageURLString = it.node.image, - pageURLString = it.node.url, - descriptionText = it.node.description, - publisherURLString = it.node.originalArticleUrl, - siteName = it.node.siteName, - author = it.node.author, - publishDate = it.node.publishedAt, - slug = it.node.slug, - isArchived = it.node.isArchived, - contentReader = it.node.contentReader.rawValue, - content = null - ) + val newCursor = result.data?.search?.onSearchSuccess?.pageInfo?.endCursor + val itemList = result.data?.search?.onSearchSuccess?.edges ?: listOf() + + val items = itemList.map { + LinkedItem( + id = it.node.id, + title = it.node.title, + createdAt = it.node.createdAt, + savedAt = it.node.savedAt, + readAt = it.node.readAt, + updatedAt = it.node.updatedAt, + readingProgress = it.node.readingProgressPercent, + readingProgressAnchor = it.node.readingProgressAnchorIndex, + imageURLString = it.node.image, + pageURLString = it.node.url, + descriptionText = it.node.description, + publisherURLString = it.node.originalArticleUrl, + siteName = it.node.siteName, + author = it.node.author, + publishDate = it.node.publishedAt, + slug = it.node.slug, + isArchived = it.node.isArchived, + contentReader = it.node.contentReader.rawValue, + content = null + ) + } + + return SearchQueryResponse(newCursor, items) + } catch (e: java.lang.Exception) { + return SearchQueryResponse(null, listOf()) } - - return SearchQueryResponse(newCursor, items) } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ViewerQuery.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ViewerQuery.kt index f187362ee..d0c7ec45a 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ViewerQuery.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/networking/ViewerQuery.kt @@ -4,17 +4,21 @@ import app.omnivore.omnivore.graphql.generated.ViewerQuery import app.omnivore.omnivore.models.Viewer suspend fun Networker.viewer(): Viewer? { - val result = authenticatedApolloClient().query(ViewerQuery()).execute() - val me = result.data?.me + try { + val result = authenticatedApolloClient().query(ViewerQuery()).execute() + val me = result.data?.me - return if (me != null) { - Viewer( - id = me.id, - name = me.name, - username = me.profile.username, - pictureUrl = me.profile.pictureUrl - ) - } else { - null + return if (me != null) { + Viewer( + id = me.id, + name = me.name, + username = me.profile.username, + pictureUrl = me.profile.pictureUrl + ) + } else { + null + } + } catch (e: java.lang.Exception) { + return null } } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/auth/LoginViewModel.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/auth/LoginViewModel.kt index d42ef3a8d..68a7178be 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/auth/LoginViewModel.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/auth/LoginViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import app.omnivore.omnivore.* import app.omnivore.omnivore.graphql.generated.SearchQuery import app.omnivore.omnivore.graphql.generated.ValidateUsernameQuery +import app.omnivore.omnivore.networking.LinkedItemQueryResponse import app.omnivore.omnivore.networking.Networker import app.omnivore.omnivore.networking.viewer import com.apollographql.apollo3.ApolloClient @@ -146,16 +147,21 @@ class LoginViewModel @Inject constructor( .serverUrl("${Constants.apiURL}/api/graphql") .build() - val response = apolloClient.query( - ValidateUsernameQuery(username = potentialUsername) - ).execute() + try { + val response = apolloClient.query( + ValidateUsernameQuery(username = potentialUsername) + ).execute() - if (response.data?.validateUsername == true) { - usernameValidationErrorMessage = null - hasValidUsername = true - } else { + if (response.data?.validateUsername == true) { + usernameValidationErrorMessage = null + hasValidUsername = true + } else { + hasValidUsername = false + usernameValidationErrorMessage = "This username is not available." + } + } catch (e: java.lang.Exception) { hasValidUsername = false - usernameValidationErrorMessage = "This username is not available." + usernameValidationErrorMessage = "Sorry we're having trouble connecting to the server." } } } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/save/SaveViewModel.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/save/SaveViewModel.kt index ba706a0cd..0dbdc7222 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/save/SaveViewModel.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/save/SaveViewModel.kt @@ -51,26 +51,30 @@ class SaveViewModel @Inject constructor( .addHttpHeader("Authorization", value = authToken) .build() - val response = apolloClient.mutation( - SaveUrlMutation( - SaveUrlInput( - clientRequestId = UUID.randomUUID().toString(), - source = "android", - url = url + try { + val response = apolloClient.mutation( + SaveUrlMutation( + SaveUrlInput( + clientRequestId = UUID.randomUUID().toString(), + source = "android", + url = url + ) ) - ) - ).execute() + ).execute() - isLoading = false + isLoading = false - val success = (response.data?.saveUrl?.onSaveSuccess?.url != null) - message = if (success) { - "Page Saved" - } else { - "There was an error saving your page" + val success = (response.data?.saveUrl?.onSaveSuccess?.url != null) + message = if (success) { + "Page Saved" + } else { + "There was an error saving your page" + } + + Log.d(ContentValues.TAG, "Saved URL?: $success") + } catch (e: java.lang.Exception) { + message = "There was an error saving your page" } - - Log.d(ContentValues.TAG, "Saved URL?: $success") } } }