package com.discord.widgets.guilds.invite; import android.content.Context; import androidx.fragment.app.FragmentActivity; import b.a.d.j; import com.discord.R; import com.discord.api.channel.Channel; import com.discord.api.channel.ChannelUtils; import com.discord.api.guild.Guild; import com.discord.api.guild.GuildFeature; import com.discord.api.guildscheduledevent.GuildScheduledEvent; import com.discord.api.guildscheduledevent.GuildScheduledEventStatus; import com.discord.api.permission.Permission; import com.discord.app.AppFragment; import com.discord.models.domain.ModelInvite; import com.discord.restapi.RestAPIParams; import com.discord.stores.StoreStream; import com.discord.utilities.captcha.CaptchaHelper; import com.discord.utilities.channel.ChannelSelector; import com.discord.utilities.coroutines.RxCoroutineExtensionsKt; import com.discord.utilities.error.AppCancellationException; import com.discord.utilities.error.Error; import com.discord.utilities.features.GrowthTeamFeatures; import com.discord.utilities.guilds.GuildCaptchaUtilsKt; import com.discord.utilities.guilds.MemberVerificationUtils; import com.discord.utilities.permissions.PermissionUtils; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.widgets.guilds.join.InviteArgs; import com.discord.widgets.hubs.HubEmailArgs; import com.discord.widgets.hubs.HubEmailEntryPoint; import com.discord.widgets.hubs.WidgetHubEmailFlow; import d0.l; import d0.w.g; import d0.w.h.c; import d0.w.i.a.b; import d0.w.i.a.e; import d0.w.i.a.k; import d0.z.d.m; import java.util.List; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.jvm.functions.Function2; import kotlin.jvm.internal.Ref$ObjectRef; import kotlinx.coroutines.CoroutineScope; import retrofit2.HttpException; /* compiled from: InviteJoinHelper.kt */ @e(c = "com.discord.widgets.guilds.invite.InviteJoinHelper$joinViaInvite$4", f = "InviteJoinHelper.kt", l = {79, 104, 117, 118, 132, 171, 200}, m = "invokeSuspend") public final class InviteJoinHelper$joinViaInvite$4 extends k implements Function2, Object> { public final /* synthetic */ CaptchaHelper.CaptchaPayload $captchaPayload; public final /* synthetic */ AppFragment $fragment; public final /* synthetic */ ModelInvite $invite; public final /* synthetic */ Class $javaClass; public final /* synthetic */ String $location; public final /* synthetic */ Function2 $onInviteFlowFinished; public final /* synthetic */ Function2 $onInvitePostError; public final /* synthetic */ Function2 $onInvitePostSuccess; public Object L$0; public Object L$1; public Object L$2; public Object L$3; public int label; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public InviteJoinHelper$joinViaInvite$4(AppFragment appFragment, ModelInvite modelInvite, String str, Function2 function2, CaptchaHelper.CaptchaPayload captchaPayload, Class cls, Function2 function22, Function2 function23, Continuation continuation) { super(2, continuation); this.$fragment = appFragment; this.$invite = modelInvite; this.$location = str; this.$onInvitePostSuccess = function2; this.$captchaPayload = captchaPayload; this.$javaClass = cls; this.$onInvitePostError = function22; this.$onInviteFlowFinished = function23; } @Override // d0.w.i.a.a public final Continuation create(Object obj, Continuation continuation) { m.checkNotNullParameter(continuation, "completion"); return new InviteJoinHelper$joinViaInvite$4(this.$fragment, this.$invite, this.$location, this.$onInvitePostSuccess, this.$captchaPayload, this.$javaClass, this.$onInvitePostError, this.$onInviteFlowFinished, 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 continuation) { return ((InviteJoinHelper$joinViaInvite$4) create(coroutineScope, continuation)).invokeSuspend(Unit.a); } /* JADX WARNING: Removed duplicated region for block: B:102:0x024d A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:103:0x024e */ /* JADX WARNING: Removed duplicated region for block: B:112:0x0285 */ /* JADX WARNING: Removed duplicated region for block: B:125:0x02d0 */ /* JADX WARNING: Removed duplicated region for block: B:129:0x02df */ /* JADX WARNING: Removed duplicated region for block: B:159:0x0370 */ /* JADX WARNING: Removed duplicated region for block: B:160:0x037e */ /* JADX WARNING: Removed duplicated region for block: B:172:0x03d2 */ /* JADX WARNING: Removed duplicated region for block: B:175:0x03e5 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:69:0x01a1 */ /* JADX WARNING: Removed duplicated region for block: B:74:0x01ac */ /* JADX WARNING: Removed duplicated region for block: B:79:0x01d2 */ /* JADX WARNING: Removed duplicated region for block: B:80:0x01d4 */ /* JADX WARNING: Removed duplicated region for block: B:82:0x01d7 */ /* JADX WARNING: Removed duplicated region for block: B:87:0x01f2 */ /* JADX WARNING: Unknown variable types count: 2 */ @Override // d0.w.i.a.a public final Object invokeSuspend(Object obj) { ModelInvite modelInvite; Function2 function2; Object obj2; Ref$ObjectRef ref$ObjectRef; Channel channel; boolean z2; Guild guild; Long boxLong; boolean z3; Boolean boxBoolean; Boolean boxBoolean2; Ref$ObjectRef ref$ObjectRef2; ModelInvite modelInvite2; AppCancellationException e; Object obj3; ModelInvite modelInvite3; Function2 function22; Ref$ObjectRef ref$ObjectRef3; ModelInvite modelInvite4; Guild guild2; Long boxLong2; Object obj4; Long boxLong3; List m; List m2; List m3; Object coroutine_suspended = c.getCOROUTINE_SUSPENDED(); String str = null; switch (this.label) { case 0: l.throwOnFailure(obj); Ref$ObjectRef ref$ObjectRef4 = new Ref$ObjectRef(); ref$ObjectRef4.element = this.$fragment.requireContext(); Ref$ObjectRef ref$ObjectRef5 = new Ref$ObjectRef(); ?? parentFragmentManager = this.$fragment.getParentFragmentManager(); m.checkNotNullExpressionValue(parentFragmentManager, "fragment.parentFragmentManager"); ref$ObjectRef5.element = parentFragmentManager; Guild guild3 = this.$invite.guild; boolean z4 = (guild3 == null || (m3 = guild3.m()) == null || !m3.contains(GuildFeature.MEMBER_VERIFICATION_GATE_ENABLED)) ? false : true; Guild guild4 = this.$invite.guild; boolean z5 = (guild4 == null || (m2 = guild4.m()) == null || m2.contains(GuildFeature.PREVIEW_ENABLED)) ? false : true; Guild guild5 = this.$invite.guild; boolean z6 = (guild5 == null || (m = guild5.m()) == null || !m.contains(GuildFeature.HUB)) ? false : true; if (z6 && !GrowthTeamFeatures.INSTANCE.isHubEnabled()) { b.a.d.m.g(ref$ObjectRef4.element, R.string.discord_u_coming_soon_to_mobile, 0, null, 12); return Unit.a; } else if (z6 && GrowthTeamFeatures.INSTANCE.isHubEmailConnectionEnabled()) { Context context = ref$ObjectRef4.element; HubEmailEntryPoint hubEmailEntryPoint = HubEmailEntryPoint.Invite; Guild guild6 = this.$invite.guild; if (guild6 != null) { str = guild6.x(); } if (str == null) { str = ""; } j.d(context, WidgetHubEmailFlow.class, new HubEmailArgs(str, this.$invite.getApproximateMemberCount(), hubEmailEntryPoint)); FragmentActivity activity = this.$fragment.e(); if (activity != null) { activity.onBackPressed(); } return Unit.a; } else if (!z4 || !z5) { ref$ObjectRef2 = ref$ObjectRef4; modelInvite4 = null; guild2 = this.$invite.guild; if (((guild2 != null || (boxLong2 = b.boxLong(guild2.r())) == null) ? null : StoreStream.Companion.getGuilds().getGuilds().get(b.boxLong(boxLong2.longValue()))) != null) { Function2 function23 = this.$onInvitePostSuccess; ModelInvite modelInvite5 = this.$invite; this.L$0 = ref$ObjectRef2; this.L$1 = modelInvite4; this.L$2 = null; this.L$3 = null; this.label = 2; if (function23.invoke(modelInvite5, this) == coroutine_suspended) { return coroutine_suspended; } modelInvite = modelInvite4; ref$ObjectRef3 = ref$ObjectRef2; ref$ObjectRef = ref$ObjectRef3; channel = this.$invite.getChannel(); if (channel != null) { m.checkNotNullExpressionValue(channel, "channel"); if (ChannelUtils.t(channel)) { Long l = StoreStream.Companion.getPermissions().getPermissionsByChannel().get(b.boxLong(channel.h())); if ((l == null || (boxBoolean2 = b.boxBoolean(PermissionUtils.can(Permission.CONNECT, b.boxLong(l.longValue())))) == null) ? false : boxBoolean2.booleanValue()) { z3 = true; boxBoolean = b.boxBoolean(z3); if (boxBoolean != null) { z2 = boxBoolean.booleanValue(); guild = this.$invite.guild; if (guild != null) { if (((guild == null || (boxLong = b.boxLong(guild.r())) == null) ? 0 : boxLong.longValue()) > 0) { if (this.$invite.getGuildScheduledEvent() != null) { GuildScheduledEvent guildScheduledEvent = this.$invite.getGuildScheduledEvent(); if ((guildScheduledEvent != null ? guildScheduledEvent.m() : null) != GuildScheduledEventStatus.ACTIVE) { InviteJoinHelper.access$navigateToGuild(InviteJoinHelper.INSTANCE, this.$invite); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { modelInvite = this.$invite; } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { return coroutine_suspended; } return Unit.a; } } Channel channel2 = this.$invite.getChannel(); if (channel2 == null || !ChannelUtils.E(channel2)) { Channel channel3 = this.$invite.getChannel(); if (channel3 == null || !ChannelUtils.z(channel3)) { InviteJoinHelper.access$navigateToChannel(InviteJoinHelper.INSTANCE, ref$ObjectRef.element, this.$fragment, this.$invite); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } if (!z2) { InviteJoinHelper.access$navigateToGuild(InviteJoinHelper.INSTANCE, this.$invite); } else { InviteJoinHelper.access$navigateToChannel(InviteJoinHelper.INSTANCE, ref$ObjectRef.element, this.$fragment, this.$invite); } function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } else if (!z2) { InviteJoinHelper.access$navigateToGuild(InviteJoinHelper.INSTANCE, this.$invite); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } else { this.L$0 = ref$ObjectRef; this.L$1 = modelInvite; this.L$2 = this; this.L$3 = null; this.label = 6; g gVar = new g(d0.w.h.b.intercepted(this)); this.$fragment.requestMicrophone(new InviteJoinHelper$joinViaInvite$4$hasMicrophonePermissions$1$1(gVar), new InviteJoinHelper$joinViaInvite$4$hasMicrophonePermissions$1$2(gVar)); obj2 = gVar.getOrThrow(); if (obj2 == c.getCOROUTINE_SUSPENDED()) { d0.w.i.a.g.probeCoroutineSuspended(this); } if (obj2 == coroutine_suspended) { return coroutine_suspended; } if (!((Boolean) obj2).booleanValue()) { InviteJoinHelper.access$navigateToChannel(InviteJoinHelper.INSTANCE, ref$ObjectRef.element, this.$fragment, this.$invite); } else { InviteJoinHelper.access$navigateToGuild(InviteJoinHelper.INSTANCE, this.$invite); } function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } } } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } } } z3 = false; boxBoolean = b.boxBoolean(z3); if (boxBoolean != null) { } } z2 = false; guild = this.$invite.guild; if (guild != null) { } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } RestAPI api = RestAPI.Companion.getApi(); ModelInvite modelInvite6 = this.$invite; String str2 = this.$location; CaptchaHelper.CaptchaPayload captchaPayload = this.$captchaPayload; String captchaKey = captchaPayload != null ? captchaPayload.getCaptchaKey() : null; CaptchaHelper.CaptchaPayload captchaPayload2 = this.$captchaPayload; String captchaRqtoken = captchaPayload2 != null ? captchaPayload2.getCaptchaRqtoken() : null; Boolean boxBoolean3 = b.boxBoolean(true); this.L$0 = ref$ObjectRef2; this.L$1 = modelInvite4; this.L$2 = null; this.L$3 = null; this.label = 3; obj3 = RxCoroutineExtensionsKt.appAwaitSingle(ObservableExtensionsKt.ui(ObservableExtensionsKt.restSubscribeOn$default(api.postInviteCode(modelInvite6, str2, new RestAPIParams.InviteCode(captchaKey, captchaRqtoken)), false, 1, null)), ref$ObjectRef2.element, boxBoolean3, this); if (obj3 == coroutine_suspended) { return coroutine_suspended; } modelInvite3 = (ModelInvite) obj3; try { function22 = this.$onInvitePostSuccess; this.L$0 = ref$ObjectRef2; this.L$1 = modelInvite3; this.label = 4; if (function22.invoke(modelInvite3, this) != coroutine_suspended) { return coroutine_suspended; } modelInvite2 = modelInvite3; modelInvite = modelInvite2; ref$ObjectRef = ref$ObjectRef2; channel = this.$invite.getChannel(); if (channel != null) { } z2 = false; guild = this.$invite.guild; if (guild != null) { } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } catch (AppCancellationException e2) { e = e2; modelInvite2 = modelInvite3; Throwable cause = e.getCause(); if (cause instanceof HttpException) { GuildCaptchaUtilsKt.handleHttpException(e.getError(), this.$fragment, new InviteArgs(this.$invite, this.$javaClass, this.$location, this.$onInvitePostError, this.$onInvitePostSuccess, this.$onInviteFlowFinished)); modelInvite = modelInvite2; ref$ObjectRef = ref$ObjectRef2; channel = this.$invite.getChannel(); if (channel != null) { } z2 = false; guild = this.$invite.guild; if (guild != null) { } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; } Function2 function24 = this.$onInvitePostError; Error create = cause != null ? Error.create(cause) : null; this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 5; if (function24.invoke(create, this) == coroutine_suspended) { return coroutine_suspended; } return Unit.a; } } else { this.L$0 = ref$ObjectRef4; this.L$1 = ref$ObjectRef5; this.L$2 = null; this.L$3 = this; this.label = 1; g gVar2 = new g(d0.w.h.b.intercepted(this)); MemberVerificationUtils memberVerificationUtils = MemberVerificationUtils.INSTANCE; Context context2 = ref$ObjectRef4.element; Guild guild7 = this.$invite.guild; memberVerificationUtils.maybeShowVerificationGate(context2, ref$ObjectRef5.element, (guild7 == null || (boxLong3 = b.boxLong(guild7.r())) == null) ? -1 : boxLong3.longValue(), this.$location, this.$invite, new InviteJoinHelper$joinViaInvite$4$hasCompletedMembershipGate$1$1(gVar2), new InviteJoinHelper$joinViaInvite$4$hasCompletedMembershipGate$1$2(gVar2)); obj4 = gVar2.getOrThrow(); if (obj4 == c.getCOROUTINE_SUSPENDED()) { d0.w.i.a.g.probeCoroutineSuspended(this); } if (obj4 == coroutine_suspended) { return coroutine_suspended; } ref$ObjectRef2 = ref$ObjectRef4; modelInvite4 = null; if (!((Boolean) obj4).booleanValue()) { return Unit.a; } guild2 = this.$invite.guild; if (((guild2 != null || (boxLong2 = b.boxLong(guild2.r())) == null) ? null : StoreStream.Companion.getGuilds().getGuilds().get(b.boxLong(boxLong2.longValue()))) != null) { } } break; case 1: InviteJoinHelper$joinViaInvite$4 inviteJoinHelper$joinViaInvite$4 = (InviteJoinHelper$joinViaInvite$4) this.L$3; Ref$ObjectRef ref$ObjectRef6 = (Ref$ObjectRef) this.L$1; l.throwOnFailure(obj); ref$ObjectRef2 = (Ref$ObjectRef) this.L$0; modelInvite4 = (ModelInvite) this.L$2; obj4 = obj; if (!((Boolean) obj4).booleanValue()) { } guild2 = this.$invite.guild; if (((guild2 != null || (boxLong2 = b.boxLong(guild2.r())) == null) ? null : StoreStream.Companion.getGuilds().getGuilds().get(b.boxLong(boxLong2.longValue()))) != null) { } break; case 2: modelInvite = (ModelInvite) this.L$1; ref$ObjectRef3 = (Ref$ObjectRef) this.L$0; l.throwOnFailure(obj); ref$ObjectRef = ref$ObjectRef3; channel = this.$invite.getChannel(); if (channel != null) { } z2 = false; guild = this.$invite.guild; if (guild != null) { } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; case 3: ModelInvite modelInvite7 = (ModelInvite) this.L$1; ref$ObjectRef2 = (Ref$ObjectRef) this.L$0; l.throwOnFailure(obj); obj3 = obj; modelInvite3 = (ModelInvite) obj3; function22 = this.$onInvitePostSuccess; this.L$0 = ref$ObjectRef2; this.L$1 = modelInvite3; this.label = 4; if (function22.invoke(modelInvite3, this) != coroutine_suspended) { } break; case 4: modelInvite2 = (ModelInvite) this.L$1; ref$ObjectRef2 = (Ref$ObjectRef) this.L$0; try { l.throwOnFailure(obj); } catch (AppCancellationException e3) { e = e3; break; } modelInvite = modelInvite2; ref$ObjectRef = ref$ObjectRef2; channel = this.$invite.getChannel(); if (channel != null) { } z2 = false; guild = this.$invite.guild; if (guild != null) { } ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), this.$invite.getChannel(), null, null, 6, null); function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; case 5: l.throwOnFailure(obj); return Unit.a; case 6: InviteJoinHelper$joinViaInvite$4 inviteJoinHelper$joinViaInvite$42 = (InviteJoinHelper$joinViaInvite$4) this.L$2; modelInvite = (ModelInvite) this.L$1; ref$ObjectRef = (Ref$ObjectRef) this.L$0; l.throwOnFailure(obj); obj2 = obj; if (!((Boolean) obj2).booleanValue()) { } function2 = this.$onInviteFlowFinished; if (modelInvite == null) { } this.L$0 = null; this.L$1 = null; this.L$2 = null; this.L$3 = null; this.label = 7; if (function2.invoke(modelInvite, this) == coroutine_suspended) { } return Unit.a; case 7: l.throwOnFailure(obj); return Unit.a; default: throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } } }