Skip to content

Commit

Permalink
[1.151.*] Pre-release merge (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Jun 26, 2024
2 parents f4224f2 + 3a15eea commit 07dff72
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.slack.eithernet.ApiResult.Success
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dev.msfjarvis.claw.android.ui.toError
import dev.msfjarvis.claw.android.viewmodel.ReadPostsRepository
import dev.msfjarvis.claw.android.viewmodel.SavedPostsRepository
import dev.msfjarvis.claw.core.injection.IODispatcher
Expand Down Expand Up @@ -62,7 +63,7 @@ constructor(
)
is Failure.NetworkFailure -> LoadResult.Error(result.error)
is Failure.UnknownFailure -> LoadResult.Error(result.error)
is Failure.HttpFailure,
is Failure.HttpFailure -> LoadResult.Error(result.toError())
is Failure.ApiFailure -> LoadResult.Error(IOException("API returned an invalid response"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dev.msfjarvis.claw.android.paging.LobstersPagingSource.Companion.PAGE_SIZE
import dev.msfjarvis.claw.android.paging.LobstersPagingSource.Companion.STARTING_PAGE_INDEX
import dev.msfjarvis.claw.android.ui.toError
import dev.msfjarvis.claw.android.viewmodel.ReadPostsRepository
import dev.msfjarvis.claw.android.viewmodel.SavedPostsRepository
import dev.msfjarvis.claw.api.LobstersSearchApi
Expand Down Expand Up @@ -80,7 +81,7 @@ constructor(
}
is ApiResult.Failure.NetworkFailure -> LoadResult.Error(result.error)
is ApiResult.Failure.UnknownFailure -> LoadResult.Error(result.error)
is ApiResult.Failure.HttpFailure,
is ApiResult.Failure.HttpFailure -> LoadResult.Error(result.toError())
is ApiResult.Failure.ApiFailure ->
LoadResult.Error(IOException("API returned an invalid response"))
}
Expand Down
17 changes: 17 additions & 0 deletions android/src/main/kotlin/dev/msfjarvis/claw/android/ui/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavController
import com.slack.eithernet.ApiResult
import dev.msfjarvis.claw.android.ui.navigation.Destinations
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
import dev.msfjarvis.claw.common.posts.PostActions
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
import dev.msfjarvis.claw.model.LinkMetadata
import dev.msfjarvis.claw.model.UIPost
import java.io.IOException
import java.net.HttpURLConnection

fun Context.getActivity(): ComponentActivity? {
return when (this) {
Expand Down Expand Up @@ -80,3 +83,17 @@ fun rememberPostActions(
}
}
}

/**
* Convert an [ApiResult.Failure.HttpFailure] to a scoped down error with a more useful user-facing
* message.
*/
@Suppress("NOTHING_TO_INLINE") // We inline this to eliminate the stacktrace frame.
inline fun <T : Any> ApiResult.Failure.HttpFailure<T>.toError(): Throwable =
when (code) {
HttpURLConnection.HTTP_NOT_FOUND -> IOException("Story was removed by moderator")
HttpURLConnection.HTTP_INTERNAL_ERROR,
HttpURLConnection.HTTP_BAD_GATEWAY,
HttpURLConnection.HTTP_UNAVAILABLE -> IOException("It appears lobste.rs is currently down")
else -> IOException("API returned an invalid response")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import dev.msfjarvis.claw.android.paging.LobstersPagingSource
import dev.msfjarvis.claw.android.paging.LobstersPagingSource.Companion.PAGE_SIZE
import dev.msfjarvis.claw.android.paging.LobstersPagingSource.Companion.STARTING_PAGE_INDEX
import dev.msfjarvis.claw.android.paging.SearchPagingSource
import dev.msfjarvis.claw.android.ui.toError
import dev.msfjarvis.claw.api.LobstersApi
import dev.msfjarvis.claw.core.injection.IODispatcher
import dev.msfjarvis.claw.core.injection.MainDispatcher
Expand All @@ -39,7 +40,6 @@ import dev.msfjarvis.claw.model.toUIPost
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.net.HttpURLConnection
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -139,13 +139,7 @@ constructor(
is Success -> result.value.toUIPost()
is Failure.NetworkFailure -> throw result.error
is Failure.UnknownFailure -> throw result.error
is Failure.HttpFailure -> {
if (result.code == HttpURLConnection.HTTP_NOT_FOUND) {
throw IOException("Story was removed by moderator")
} else {
throw IOException("API returned an invalid response")
}
}
is Failure.HttpFailure -> throw result.toError()
is Failure.ApiFailure -> throw IOException("API returned an invalid response")
}
}
Expand All @@ -165,7 +159,7 @@ constructor(
is Success -> result.value
is Failure.NetworkFailure -> throw result.error
is Failure.UnknownFailure -> throw result.error
is Failure.HttpFailure,
is Failure.HttpFailure -> throw result.toError()
is Failure.ApiFailure -> throw IOException("API returned an invalid response")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private val CommentEntryPadding = 16f.dp
internal fun CommentEntry(
commentNode: CommentNode,
htmlConverter: HTMLConverter,
@Suppress("UNUSED_PARAMETER") toggleExpanded: (CommentNode) -> Unit,
toggleExpanded: (CommentNode) -> Unit,
openUserProfile: (String) -> Unit,
modifier: Modifier = Modifier,
) {
Expand All @@ -139,7 +139,7 @@ internal fun CommentEntry(
modifier =
modifier
.fillMaxWidth()
/*.clickable { toggleExpanded(commentNode) }*/
.clickable { toggleExpanded(commentNode) }
.background(MaterialTheme.colorScheme.background)
.padding(
start = CommentEntryPadding * commentNode.indentLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ private fun LazyListScope.node(
toggleExpanded: (CommentNode) -> Unit,
openUserProfile: (String) -> Unit,
) {
/*
// Skip the node if neither the node nor its parent is expanded
if (!node.isExpanded && node.parent?.isExpanded == false) {
return
}
*/
// Skip the node if neither the node nor its parent is expanded
if (!node.isExpanded && node.parent?.isExpanded == false) {
return
}
item(key = node.comment.shortId) {
CommentEntry(
commentNode = node,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lifecycle = "2.8.2"
retrofit = "2.11.0"
richtext = "1.0.0-alpha01"
sentry-sdk = "7.10.0"
serialization = "1.7.0"
serialization = "1.7.1"
store = "5.1.0-alpha02"
sqldelight = "2.0.2"
whetstone = "0.9.0-beta02"
Expand Down

0 comments on commit 07dff72

Please sign in to comment.