discord-jadx/app/src/main/java/c/a/s/b.java

110 lines
4.5 KiB
Java

package c.a.s;
import android.net.Uri;
import c.d.b.a.a;
import com.discord.samsung.SamsungConnect$SamsungCallbackException;
import d0.g0.w;
import d0.l;
import d0.o;
import d0.t.h0;
import d0.t.u;
import d0.w.g.c;
import d0.w.h.a.e;
import d0.w.h.a.k;
import d0.z.d.m;
import f0.x;
import f0.z;
import java.util.ArrayList;
import java.util.Map;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.jvm.functions.Function2;
import kotlinx.coroutines.CoroutineScope;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.Response;
/* compiled from: SamsungConnect.kt */
@e(c = "com.discord.samsung.SamsungConnect$postSamsungAuthorizeCallback$2", f = "SamsungConnect.kt", l = {}, m = "invokeSuspend")
public final class b extends k implements Function2<CoroutineScope, Continuation<? super Uri>, Object> {
public final /* synthetic */ x $okHttpClient;
public final /* synthetic */ String $samsungAuthCode;
public final /* synthetic */ String $state;
public final /* synthetic */ String $url;
public int label;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b(String str, String str2, String str3, x xVar, Continuation continuation) {
super(2, continuation);
this.$state = str;
this.$samsungAuthCode = str2;
this.$url = str3;
this.$okHttpClient = xVar;
}
@Override // d0.w.h.a.a
public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
m.checkNotNullParameter(continuation, "completion");
return new b(this.$state, this.$samsungAuthCode, this.$url, this.$okHttpClient, continuation);
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Uri> continuation) {
return ((b) create(coroutineScope, continuation)).invokeSuspend(Unit.a);
}
/* JADX WARNING: Code restructure failed: missing block: B:25:0x00f2, code lost:
if (r2 == false) goto L_0x00f5;
*/
@Override // d0.w.h.a.a
public final Object invokeSuspend(Object obj) {
String str;
String query;
c.getCOROUTINE_SUSPENDED();
if (this.label == 0) {
l.throwOnFailure(obj);
boolean z2 = false;
StringBuilder L = a.L("{\"code\":\"");
L.append(this.$samsungAuthCode);
L.append("\"}");
Map mapOf = h0.mapOf(o.to("state", this.$state), o.to("code", L.toString()));
ArrayList arrayList = new ArrayList(mapOf.size());
for (Map.Entry entry : mapOf.entrySet()) {
arrayList.add(((String) entry.getKey()) + '=' + ((String) entry.getValue()));
}
String joinToString$default = u.joinToString$default(arrayList, "&", null, null, 0, null, null, 62, null);
RequestBody.Companion companion = RequestBody.Companion;
MediaType.a aVar = MediaType.f2857c;
RequestBody a = companion.a(joinToString$default, MediaType.a.a("application/x-www-form-urlencoded"));
z.a aVar2 = new z.a();
m.checkParameterIsNotNull(a, "body");
aVar2.c("POST", a);
aVar2.f(this.$url);
Response execute = ((f0.f0.g.e) this.$okHttpClient.b(aVar2.a())).execute();
String str2 = null;
String a2 = Response.a(execute, "Location", null, 2);
Uri parse = a2 != null ? Uri.parse(a2) : null;
if (!((parse == null || (query = parse.getQuery()) == null) ? false : w.contains$default((CharSequence) query, (CharSequence) "error", false, 2, (Object) null))) {
if (!execute.b()) {
int i = execute.l;
if (!(i == 307 || i == 308)) {
switch (i) {
}
}
z2 = true;
}
return parse;
}
if (parse == null || (str = parse.getQueryParameter("error")) == null) {
str = "unknown";
}
m.checkNotNullExpressionValue(str, "location?.getQueryParameter(\"error\") ?: \"unknown\"");
if (parse != null) {
str2 = parse.getQueryParameter("error_description");
}
throw new SamsungConnect$SamsungCallbackException(str, str2);
}
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
}
}