Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.19 upgrade #1277

Merged
merged 9 commits into from
Nov 28, 2023
7 changes: 5 additions & 2 deletions app/src/main/java/com/jerboa/api/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,20 @@ interface API {

fun createTempInstance(
host: String,
auth: String? = null,
customErrorHandler: ((Exception) -> Exception?)? = null,
): API {
return buildApi(host, customErrorHandler)
return buildApi(host, auth, customErrorHandler)
}

private fun buildApi(
customUrl: String? = null,
customAuth: String? = null,
customErrorHandler: ((Exception) -> Exception?)? = null,
): API {
val currErrorHandler = customErrorHandler ?: errorHandler
val url = customUrl ?: currentInstance
val auth = customAuth ?: currentAuth
val baseUrl = buildUrl(url)

val client =
Expand All @@ -404,7 +407,7 @@ interface API {
.build()
}
}
.addInterceptor(AuthInterceptor(currentAuth))
.addInterceptor(AuthInterceptor(auth))
.addInterceptor(CustomHttpLoggingInterceptor(REDACTED_QUERY_PARAMS, REDACTED_BODY_FIELDS))
.build()

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/jerboa/model/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LoginViewModel : ViewModel() {
ctx: Context,
) {
val newInstance = getHostFromInstanceString(instance)
val tempAPI = API.createTempInstance(newInstance)
var tempAPI = API.createTempInstance(newInstance)
var jwt: String

viewModelScope.launch {
Expand All @@ -59,11 +59,11 @@ class LoginViewModel : ViewModel() {
}
// Login was sucessful after this point
dessalines marked this conversation as resolved.
Show resolved Hide resolved

// Change the lemmy instance to the new one
API.changeLemmyInstance(instance, jwt)
// Change the temp lemmy instance to a new one with the auth
tempAPI = API.createTempInstance(newInstance, jwt)

// Fetch the site to get your name and id
siteViewModel.siteRes = apiWrapper(API.getInstance().getSite())
siteViewModel.siteRes = apiWrapper(tempAPI.getSite())

try {
when (val siteRes = siteViewModel.siteRes) {
Expand Down Expand Up @@ -115,6 +115,7 @@ class LoginViewModel : ViewModel() {
accountViewModel.insert(account)

loading = false
API.changeLemmyInstance(newInstance, jwt)
onGoHome()
}

Expand Down