package com.discord.stores; import android.content.Context; import com.discord.api.message.Message; import com.discord.stores.StoreMessagesLoader; import com.discord.utilities.error.Error; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.z.d.m; import d0.z.d.o; import j0.k.b; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function4; import rx.Observable; import rx.Subscription; import rx.subjects.SerializedSubject; /* compiled from: StoreMessagesLoader.kt */ public final class StoreMessagesLoader$tryLoadMessages$3 extends o implements Function4 { public final /* synthetic */ StoreMessagesLoader this$0; /* compiled from: StoreMessagesLoader.kt */ /* renamed from: com.discord.stores.StoreMessagesLoader$tryLoadMessages$3$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function1 { public static final AnonymousClass1 INSTANCE = new AnonymousClass1(); public AnonymousClass1() { super(1); } public final StoreMessagesLoader.ChannelLoadedState invoke(StoreMessagesLoader.ChannelLoadedState channelLoadedState) { m.checkNotNullParameter(channelLoadedState, "it"); return StoreMessagesLoader.ChannelLoadedState.copy$default(channelLoadedState, false, false, true, false, null, 27, null); } } /* compiled from: StoreMessagesLoader.kt */ /* renamed from: com.discord.stores.StoreMessagesLoader$tryLoadMessages$3$2 reason: invalid class name */ public static final class AnonymousClass2 implements b, List> { public static final AnonymousClass2 INSTANCE = new AnonymousClass2(); /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // j0.k.b public /* bridge */ /* synthetic */ List call(List list) { return call((List) list); } public final List call(List list) { m.checkNotNullExpressionValue(list, "messages"); ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(list, 10)); Iterator it = list.iterator(); while (it.hasNext()) { arrayList.add(new com.discord.models.message.Message(it.next())); } return arrayList; } } /* compiled from: StoreMessagesLoader.kt */ /* renamed from: com.discord.stores.StoreMessagesLoader$tryLoadMessages$3$3 reason: invalid class name */ public static final class AnonymousClass3 extends o implements Function1, Unit> { public final /* synthetic */ Long $after; public final /* synthetic */ Long $before; public final /* synthetic */ long $channelId; public final /* synthetic */ Long $messageId; public final /* synthetic */ StoreMessagesLoader$tryLoadMessages$3 this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass3(StoreMessagesLoader$tryLoadMessages$3 storeMessagesLoader$tryLoadMessages$3, long j, Long l, Long l2, Long l3) { super(1); this.this$0 = storeMessagesLoader$tryLoadMessages$3; this.$channelId = j; this.$messageId = l; this.$before = l2; this.$after = l3; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(List list) { invoke((List) list); return Unit.a; } public final void invoke(List list) { StoreMessagesLoader storeMessagesLoader = this.this$0.this$0; m.checkNotNullExpressionValue(list, "it"); long j = this.$channelId; Long l = this.$messageId; StoreMessagesLoader.access$handleLoadedMessages(storeMessagesLoader, list, j, l != null ? l.longValue() : 0, this.$before, this.$after); } } /* compiled from: StoreMessagesLoader.kt */ /* renamed from: com.discord.stores.StoreMessagesLoader$tryLoadMessages$3$4 reason: invalid class name */ public static final class AnonymousClass4 extends o implements Function1 { public final /* synthetic */ long $channelId; public final /* synthetic */ StoreMessagesLoader$tryLoadMessages$3 this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass4(StoreMessagesLoader$tryLoadMessages$3 storeMessagesLoader$tryLoadMessages$3, long j) { super(1); this.this$0 = storeMessagesLoader$tryLoadMessages$3; this.$channelId = j; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(Error error) { invoke(error); return Unit.a; } public final void invoke(Error error) { m.checkNotNullParameter(error, "it"); StoreMessagesLoader.access$handleLoadMessagesError(this.this$0.this$0, this.$channelId); } } /* compiled from: StoreMessagesLoader.kt */ /* renamed from: com.discord.stores.StoreMessagesLoader$tryLoadMessages$3$5 reason: invalid class name */ public static final class AnonymousClass5 extends o implements Function1 { public final /* synthetic */ StoreMessagesLoader$tryLoadMessages$3 this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass5(StoreMessagesLoader$tryLoadMessages$3 storeMessagesLoader$tryLoadMessages$3) { super(1); this.this$0 = storeMessagesLoader$tryLoadMessages$3; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(Subscription subscription) { invoke(subscription); return Unit.a; } public final void invoke(Subscription subscription) { m.checkNotNullParameter(subscription, "it"); StoreMessagesLoader.access$setLoadingMessagesSubscription$p(this.this$0.this$0, subscription); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public StoreMessagesLoader$tryLoadMessages$3(StoreMessagesLoader storeMessagesLoader) { super(4); this.this$0 = storeMessagesLoader; } public static /* synthetic */ void invoke$default(StoreMessagesLoader$tryLoadMessages$3 storeMessagesLoader$tryLoadMessages$3, long j, Long l, Long l2, Long l3, int i, Object obj) { storeMessagesLoader$tryLoadMessages$3.invoke(j, (i & 2) != 0 ? null : l, (i & 4) != 0 ? null : l2, (i & 8) != 0 ? null : l3); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object] */ @Override // kotlin.jvm.functions.Function4 public /* bridge */ /* synthetic */ Unit invoke(Long l, Long l2, Long l3, Long l4) { invoke(l.longValue(), l2, l3, l4); return Unit.a; } public final synchronized void invoke(long j, Long l, Long l2, Long l3) { Observable> observable; StoreMessagesLoader.access$channelLoadedStateUpdate(this.this$0, j, AnonymousClass1.INSTANCE); if (l != null) { if (l.longValue() == 1) { observable = RestAPI.Companion.getApi().getChannelMessages(j, l2, l3, Integer.valueOf(StoreMessagesLoader.access$getMessageRequestSize$p(this.this$0))); SerializedSubject access$getChannelMessagesLoadingSubject$p = StoreMessagesLoader.access$getChannelMessagesLoadingSubject$p(this.this$0); access$getChannelMessagesLoadingSubject$p.j.onNext(Boolean.TRUE); Observable F = ObservableExtensionsKt.restSubscribeOn(observable, false).F(AnonymousClass2.INSTANCE); m.checkNotNullExpressionValue(F, "messagesRequest\n …messages.map(::Message) }"); Observable computationLatest = ObservableExtensionsKt.computationLatest(F); Class cls = this.this$0.getClass(); AnonymousClass3 r16 = new AnonymousClass3(this, j, l, l2, l3); ObservableExtensionsKt.appSubscribe$default(computationLatest, cls, (Context) null, new AnonymousClass5(this), new AnonymousClass4(this, j), (Function0) null, (Function0) null, r16, 50, (Object) null); } } if (l != null) { if (l.longValue() == 0) { observable = RestAPI.Companion.getApi().getChannelMessages(j, l2, l3, Integer.valueOf(StoreMessagesLoader.access$getMessageRequestSize$p(this.this$0))); SerializedSubject access$getChannelMessagesLoadingSubject$p = StoreMessagesLoader.access$getChannelMessagesLoadingSubject$p(this.this$0); access$getChannelMessagesLoadingSubject$p.j.onNext(Boolean.TRUE); Observable F = ObservableExtensionsKt.restSubscribeOn(observable, false).F(AnonymousClass2.INSTANCE); m.checkNotNullExpressionValue(F, "messagesRequest\n …messages.map(::Message) }"); Observable computationLatest = ObservableExtensionsKt.computationLatest(F); Class cls = this.this$0.getClass(); AnonymousClass3 r16 = new AnonymousClass3(this, j, l, l2, l3); ObservableExtensionsKt.appSubscribe$default(computationLatest, cls, (Context) null, new AnonymousClass5(this), new AnonymousClass4(this, j), (Function0) null, (Function0) null, r16, 50, (Object) null); } } if (l != null) { observable = RestAPI.Companion.getApi().getChannelMessagesAround(j, StoreMessagesLoader.access$getMessageRequestSize$p(this.this$0), l.longValue()); SerializedSubject access$getChannelMessagesLoadingSubject$p = StoreMessagesLoader.access$getChannelMessagesLoadingSubject$p(this.this$0); access$getChannelMessagesLoadingSubject$p.j.onNext(Boolean.TRUE); Observable F = ObservableExtensionsKt.restSubscribeOn(observable, false).F(AnonymousClass2.INSTANCE); m.checkNotNullExpressionValue(F, "messagesRequest\n …messages.map(::Message) }"); Observable computationLatest = ObservableExtensionsKt.computationLatest(F); Class cls = this.this$0.getClass(); AnonymousClass3 r16 = new AnonymousClass3(this, j, l, l2, l3); ObservableExtensionsKt.appSubscribe$default(computationLatest, cls, (Context) null, new AnonymousClass5(this), new AnonymousClass4(this, j), (Function0) null, (Function0) null, r16, 50, (Object) null); } observable = RestAPI.Companion.getApi().getChannelMessages(j, l2, l3, Integer.valueOf(StoreMessagesLoader.access$getMessageRequestSize$p(this.this$0))); SerializedSubject access$getChannelMessagesLoadingSubject$p = StoreMessagesLoader.access$getChannelMessagesLoadingSubject$p(this.this$0); access$getChannelMessagesLoadingSubject$p.j.onNext(Boolean.TRUE); Observable F = ObservableExtensionsKt.restSubscribeOn(observable, false).F(AnonymousClass2.INSTANCE); m.checkNotNullExpressionValue(F, "messagesRequest\n …messages.map(::Message) }"); Observable computationLatest = ObservableExtensionsKt.computationLatest(F); Class cls = this.this$0.getClass(); AnonymousClass3 r16 = new AnonymousClass3(this, j, l, l2, l3); ObservableExtensionsKt.appSubscribe$default(computationLatest, cls, (Context) null, new AnonymousClass5(this), new AnonymousClass4(this, j), (Function0) null, (Function0) null, r16, 50, (Object) null); } }