{"action":"created","comment":{"url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/comments/228799351","pull_request_review_id":169146026,"id":228799351,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyODc5OTM1MQ==","diff_hunk":"@@ -178,77 +163,70 @@ class SmmryFragment : InjectableBaseFragment() {\n     } else {\n       loadingView.hide()\n     }\n-    Maybe.concatArray(tryRequestFromStorage(), getRequestSingle().toMaybe())\n-        .firstOrError()\n-        .subscribeOn(Schedulers.io())\n-        .observeOn(AndroidSchedulers.mainThread())\n-        .autoDisposable(this)\n-        .subscribe({ smmryResponse ->\n-          alreadyLoaded = true\n-          loadingView.hide(true)\n-          when (smmryResponse) {\n-            is Success -> {\n-              showSummary(smmryResponse)\n-            }\n-            else -> {\n-              val message = when (smmryResponse) {\n-                is InternalError -> \"Smmry internal error - ${smmryResponse.message}\"\n-                is IncorrectVariables -> \"Smmry invalid input - ${smmryResponse.message}\"\n-                is ApiRejection -> \"Smmry API error - ${smmryResponse.message}\"\n-                is SummarizationError -> \"Smmry summarization error - ${smmryResponse.message}\"\n-                UnknownErrorCode -> \"Unknown error :(\"\n-                else -> TODO(\"Give me sealed whens!\")\n-              }\n-              summary.text = message\n-            }\n-          }\n-        }, { error ->\n-          loadingView.hide(true)\n-          summary.setText(R.string.unknown_issue)\n-          if (error is IOException) {\n-            w(error) { \"Unknown error in smmry load\" }\n-          } else {\n-            e(error) { \"Unknown error in smmry load\" }\n+    lifecycleCoroutineScope().launch {\n+      val response = tryRequestFromStorage() ?: fetchFromNetwork()\n+      alreadyLoaded = true\n+      loadingView.hide(animate = true)\n+      when (response) {\n+        is Success -> {\n+          showSummary(response)\n+        }\n+        else -> {\n+          val message = when (response) {\n+            is InternalError -> \"Smmry internal error - ${response.message}\"\n+            is IncorrectVariables -> \"Smmry invalid input - ${response.message}\"\n+            is ApiRejection -> \"Smmry API error - ${response.message}\"\n+            is SummarizationError -> \"Smmry summarization error - ${response.message}\"\n+            UnknownErrorCode -> getString(R.string.unknown_issue)\n+            else -> TODO(\"Give me sealed whens!\")\n           }\n-        })\n+          summary.text = message\n+        }\n+      }\n+    }\n   }\n \n   fun canScrollVertically(directionInt: Int): Boolean {\n     return content.canScrollVertically(directionInt)\n   }\n \n-  private fun tryRequestFromStorage(): Maybe<SmmryResponse> {\n-    return smmryDao.getItem(id)\n-        .map { moshi.adapter(SmmryResponse::class.java).fromJson(it.json)!! }\n-        .onErrorComplete { exception ->\n-          e(exception) { \"Error loading smmry cache.\" }\n-          true\n-        }\n+  private suspend fun tryRequestFromStorage() = withContext(Dispatchers.IO) {\n+    smmryDao.getItem(id)?.let {\n+      moshi.adapter(SmmryResponse::class.java).fromJson(it.json) ?: throw JsonDataException(\n+          \"Could not parse entry\")\n+    }\n   }\n \n-  private fun getRequestSingle(): Single<SmmryResponse> {\n-    val summarizer: Single<SmmryResponse> = when (info.type) {\n-      TEXT -> smmryService.summarizeText(SmmryRequestBuilder.forText()\n-          .withBreak(true)\n-          .keywordCount(5)\n-          .sentenceCount(5)\n-          .build(),\n-          info.value)\n-      URL -> smmryService.summarizeUrl(SmmryRequestBuilder.forUrl(info.value)\n-          .withBreak(true)\n-          .keywordCount(5)\n-          .sentenceCount(5)\n-          .build())\n-      NONE -> Single.just(Success.just(inputTitle, info.value))\n+  private suspend fun fetchFromNetwork(): SmmryResponse {\n+    val response: SmmryResponse = try {\n+      when (info.type) {\n+        TEXT -> smmryService.summarizeText(SmmryRequestBuilder.forText()\n+            .withBreak(true)\n+            .keywordCount(5)\n+            .sentenceCount(5)\n+            .build(),\n+            info.value)\n+            .await()\n+        URL -> smmryService.summarizeUrl(SmmryRequestBuilder.forUrl(info.value)\n+            .withBreak(true)\n+            .keywordCount(5)\n+            .sentenceCount(5)\n+            .build())\n+            .await()\n+        NONE -> Success.just(inputTitle, info.value)\n+      }\n+    } catch (error: Exception) {\n+      // We should indicate when something's network related\n+      UnknownErrorCode\n     }\n-    return summarizer.doOnSuccess {\n-      if (it != UnknownErrorCode) {\n+    if (response != UnknownErrorCode) {\n+      withContext(Dispatchers.IO) {","path":"app/src/main/kotlin/io/sweers/catchup/ui/fragments/SmmryFragment.kt","position":172,"original_position":172,"commit_id":"83d7240f76102c269242f2c1cd326feadb7b760d","original_commit_id":"83d7240f76102c269242f2c1cd326feadb7b760d","user":{"login":"adamp","id":103458,"node_id":"MDQ6VXNlcjEwMzQ1OA==","avatar_url":"https://avatars3.githubusercontent.com/u/103458?v=4","gravatar_id":"","url":"https://api.github.com/users/adamp","html_url":"https://github.com/adamp","followers_url":"https://api.github.com/users/adamp/followers","following_url":"https://api.github.com/users/adamp/following{/other_user}","gists_url":"https://api.github.com/users/adamp/gists{/gist_id}","starred_url":"https://api.github.com/users/adamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamp/subscriptions","organizations_url":"https://api.github.com/users/adamp/orgs","repos_url":"https://api.github.com/users/adamp/repos","events_url":"https://api.github.com/users/adamp/events{/privacy}","received_events_url":"https://api.github.com/users/adamp/received_events","type":"User","site_admin":false},"body":"You might want to handle errors from this differently though","created_at":"2018-10-29T04:38:26Z","updated_at":"2018-10-29T04:38:49Z","html_url":"https://github.com/hzsweers/CatchUp/pull/136#discussion_r228799351","pull_request_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/comments/228799351"},"html":{"href":"https://github.com/hzsweers/CatchUp/pull/136#discussion_r228799351"},"pull_request":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136"}},"in_reply_to_id":228799198},"pull_request":{"url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136","id":226433626,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2NDMzNjI2","html_url":"https://github.com/hzsweers/CatchUp/pull/136","diff_url":"https://github.com/hzsweers/CatchUp/pull/136.diff","patch_url":"https://github.com/hzsweers/CatchUp/pull/136.patch","issue_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/136","number":136,"state":"open","locked":false,"title":"Introduce coroutines (via Smmry)","user":{"login":"hzsweers","id":1361086,"node_id":"MDQ6VXNlcjEzNjEwODY=","avatar_url":"https://avatars1.githubusercontent.com/u/1361086?v=4","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"body":"This brings in coroutines via the `Smmry` API, leveraging them on both retrofit as well as ROOM ","created_at":"2018-10-29T04:18:07Z","updated_at":"2018-10-29T04:38:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a3f0cc35c01cdcd9cbd1400e227d13d629a6199","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136/commits","review_comments_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136/comments","review_comment_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/136/comments","statuses_url":"https://api.github.com/repos/hzsweers/CatchUp/statuses/83d7240f76102c269242f2c1cd326feadb7b760d","head":{"label":"hzsweers:z/introCoroutines","ref":"z/introCoroutines","sha":"83d7240f76102c269242f2c1cd326feadb7b760d","user":{"login":"hzsweers","id":1361086,"node_id":"MDQ6VXNlcjEzNjEwODY=","avatar_url":"https://avatars1.githubusercontent.com/u/1361086?v=4","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"repo":{"id":57029623,"node_id":"MDEwOlJlcG9zaXRvcnk1NzAyOTYyMw==","name":"CatchUp","full_name":"hzsweers/CatchUp","private":false,"owner":{"login":"hzsweers","id":1361086,"node_id":"MDQ6VXNlcjEzNjEwODY=","avatar_url":"https://avatars1.githubusercontent.com/u/1361086?v=4","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"html_url":"https://github.com/hzsweers/CatchUp","description":"An app for catching up on things.","fork":false,"url":"https://api.github.com/repos/hzsweers/CatchUp","forks_url":"https://api.github.com/repos/hzsweers/CatchUp/forks","keys_url":"https://api.github.com/repos/hzsweers/CatchUp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hzsweers/CatchUp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hzsweers/CatchUp/teams","hooks_url":"https://api.github.com/repos/hzsweers/CatchUp/hooks","issue_events_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/events{/number}","events_url":"https://api.github.com/repos/hzsweers/CatchUp/events","assignees_url":"https://api.github.com/repos/hzsweers/CatchUp/assignees{/user}","branches_url":"https://api.github.com/repos/hzsweers/CatchUp/branches{/branch}","tags_url":"https://api.github.com/repos/hzsweers/CatchUp/tags","blobs_url":"https://api.github.com/repos/hzsweers/CatchUp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hzsweers/CatchUp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hzsweers/CatchUp/git/refs{/sha}","trees_url":"https://api.github.com/repos/hzsweers/CatchUp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hzsweers/CatchUp/statuses/{sha}","languages_url":"https://api.github.com/repos/hzsweers/CatchUp/languages","stargazers_url":"https://api.github.com/repos/hzsweers/CatchUp/stargazers","contributors_url":"https://api.github.com/repos/hzsweers/CatchUp/contributors","subscribers_url":"https://api.github.com/repos/hzsweers/CatchUp/subscribers","subscription_url":"https://api.github.com/repos/hzsweers/CatchUp/subscription","commits_url":"https://api.github.com/repos/hzsweers/CatchUp/commits{/sha}","git_commits_url":"https://api.github.com/repos/hzsweers/CatchUp/git/commits{/sha}","comments_url":"https://api.github.com/repos/hzsweers/CatchUp/comments{/number}","issue_comment_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/comments{/number}","contents_url":"https://api.github.com/repos/hzsweers/CatchUp/contents/{+path}","compare_url":"https://api.github.com/repos/hzsweers/CatchUp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hzsweers/CatchUp/merges","archive_url":"https://api.github.com/repos/hzsweers/CatchUp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hzsweers/CatchUp/downloads","issues_url":"https://api.github.com/repos/hzsweers/CatchUp/issues{/number}","pulls_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls{/number}","milestones_url":"https://api.github.com/repos/hzsweers/CatchUp/milestones{/number}","notifications_url":"https://api.github.com/repos/hzsweers/CatchUp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hzsweers/CatchUp/labels{/name}","releases_url":"https://api.github.com/repos/hzsweers/CatchUp/releases{/id}","deployments_url":"https://api.github.com/repos/hzsweers/CatchUp/deployments","created_at":"2016-04-25T09:33:27Z","updated_at":"2018-10-29T02:44:49Z","pushed_at":"2018-10-29T04:18:08Z","git_url":"git://github.com/hzsweers/CatchUp.git","ssh_url":"git@github.com:hzsweers/CatchUp.git","clone_url":"https://github.com/hzsweers/CatchUp.git","svn_url":"https://github.com/hzsweers/CatchUp","homepage":"","size":13124,"stargazers_count":969,"watchers_count":969,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":106,"mirror_url":null,"archived":false,"open_issues_count":29,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":106,"open_issues":29,"watchers":969,"default_branch":"master"}},"base":{"label":"hzsweers:master","ref":"master","sha":"cfd3f54621b275fe4e381daa13bb90dea98e852d","user":{"login":"hzsweers","id":1361086,"node_id":"MDQ6VXNlcjEzNjEwODY=","avatar_url":"https://avatars1.githubusercontent.com/u/1361086?v=4","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"repo":{"id":57029623,"node_id":"MDEwOlJlcG9zaXRvcnk1NzAyOTYyMw==","name":"CatchUp","full_name":"hzsweers/CatchUp","private":false,"owner":{"login":"hzsweers","id":1361086,"node_id":"MDQ6VXNlcjEzNjEwODY=","avatar_url":"https://avatars1.githubusercontent.com/u/1361086?v=4","gravatar_id":"","url":"https://api.github.com/users/hzsweers","html_url":"https://github.com/hzsweers","followers_url":"https://api.github.com/users/hzsweers/followers","following_url":"https://api.github.com/users/hzsweers/following{/other_user}","gists_url":"https://api.github.com/users/hzsweers/gists{/gist_id}","starred_url":"https://api.github.com/users/hzsweers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzsweers/subscriptions","organizations_url":"https://api.github.com/users/hzsweers/orgs","repos_url":"https://api.github.com/users/hzsweers/repos","events_url":"https://api.github.com/users/hzsweers/events{/privacy}","received_events_url":"https://api.github.com/users/hzsweers/received_events","type":"User","site_admin":false},"html_url":"https://github.com/hzsweers/CatchUp","description":"An app for catching up on things.","fork":false,"url":"https://api.github.com/repos/hzsweers/CatchUp","forks_url":"https://api.github.com/repos/hzsweers/CatchUp/forks","keys_url":"https://api.github.com/repos/hzsweers/CatchUp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hzsweers/CatchUp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hzsweers/CatchUp/teams","hooks_url":"https://api.github.com/repos/hzsweers/CatchUp/hooks","issue_events_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/events{/number}","events_url":"https://api.github.com/repos/hzsweers/CatchUp/events","assignees_url":"https://api.github.com/repos/hzsweers/CatchUp/assignees{/user}","branches_url":"https://api.github.com/repos/hzsweers/CatchUp/branches{/branch}","tags_url":"https://api.github.com/repos/hzsweers/CatchUp/tags","blobs_url":"https://api.github.com/repos/hzsweers/CatchUp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hzsweers/CatchUp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hzsweers/CatchUp/git/refs{/sha}","trees_url":"https://api.github.com/repos/hzsweers/CatchUp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hzsweers/CatchUp/statuses/{sha}","languages_url":"https://api.github.com/repos/hzsweers/CatchUp/languages","stargazers_url":"https://api.github.com/repos/hzsweers/CatchUp/stargazers","contributors_url":"https://api.github.com/repos/hzsweers/CatchUp/contributors","subscribers_url":"https://api.github.com/repos/hzsweers/CatchUp/subscribers","subscription_url":"https://api.github.com/repos/hzsweers/CatchUp/subscription","commits_url":"https://api.github.com/repos/hzsweers/CatchUp/commits{/sha}","git_commits_url":"https://api.github.com/repos/hzsweers/CatchUp/git/commits{/sha}","comments_url":"https://api.github.com/repos/hzsweers/CatchUp/comments{/number}","issue_comment_url":"https://api.github.com/repos/hzsweers/CatchUp/issues/comments{/number}","contents_url":"https://api.github.com/repos/hzsweers/CatchUp/contents/{+path}","compare_url":"https://api.github.com/repos/hzsweers/CatchUp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hzsweers/CatchUp/merges","archive_url":"https://api.github.com/repos/hzsweers/CatchUp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hzsweers/CatchUp/downloads","issues_url":"https://api.github.com/repos/hzsweers/CatchUp/issues{/number}","pulls_url":"https://api.github.com/repos/hzsweers/CatchUp/pulls{/number}","milestones_url":"https://api.github.com/repos/hzsweers/CatchUp/milestones{/number}","notifications_url":"https://api.github.com/repos/hzsweers/CatchUp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hzsweers/CatchUp/labels{/name}","releases_url":"https://api.github.com/repos/hzsweers/CatchUp/releases{/id}","deployments_url":"https://api.github.com/repos/hzsweers/CatchUp/deployments","created_at":"2016-04-25T09:33:27Z","updated_at":"2018-10-29T02:44:49Z","pushed_at":"2018-10-29T04:18:08Z","git_url":"git://github.com/hzsweers/CatchUp.git","ssh_url":"git@github.com:hzsweers/CatchUp.git","clone_url":"https://github.com/hzsweers/CatchUp.git","svn_url":"https://github.com/hzsweers/CatchUp","homepage":"","size":13124,"stargazers_count":969,"watchers_count":969,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":106,"mirror_url":null,"archived":false,"open_issues_count":29,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":106,"open_issues":29,"watchers":969,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136"},"html":{"href":"https://github.com/hzsweers/CatchUp/pull/136"},"issue":{"href":"https://api.github.com/repos/hzsweers/CatchUp/issues/136"},"comments":{"href":"https://api.github.com/repos/hzsweers/CatchUp/issues/136/comments"},"review_comments":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136/comments"},"review_comment":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hzsweers/CatchUp/pulls/136/commits"},"statuses":{"href":"https://api.github.com/repos/hzsweers/CatchUp/statuses/83d7240f76102c269242f2c1cd326feadb7b760d"}},"author_association":"OWNER"}}
{"actor":{"display_login":"adamp"}}