package com.discord.stores; import a0.a.a.b; import android.content.Context; import c.a.d.q; import c.d.b.a.a; import com.discord.app.AppLog; import com.discord.models.message.Message; import com.discord.stores.StoreChat; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$1; import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$2; import d0.t.n0; import d0.z.d.m; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; import java.util.concurrent.TimeUnit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; import rx.Subscription; import rx.subjects.BehaviorSubject; import rx.subjects.SerializedSubject; /* compiled from: StoreMessagesLoader.kt */ public final class StoreMessagesLoader extends Store { public static final Companion Companion = new Companion(null); public static final long SCROLL_TO_LAST_UNREAD = 0; public static final long SCROLL_TO_LATEST = 1; private boolean authed; private boolean backgrounded; private final SerializedSubject, Map> channelLoadedStateSubject; private final HashMap channelLoadedStates; private final SerializedSubject channelMessageChunksSubject = new SerializedSubject<>(BehaviorSubject.k0()); private final SerializedSubject channelMessagesLoadingSubject; private Subscription delayLoadingMessagesSubscription; private Set detachedChannels; private final Dispatcher dispatcher; private boolean hasConnected; private StoreChat.InteractionState interactionState; private final long loadingMessagesRetryDelayDefault; private long loadingMessagesRetryDelayMillis; private final int loadingMessagesRetryJitter; private int loadingMessagesRetryMax; private Subscription loadingMessagesSubscription; private final int messageRequestSize = 50; private final SerializedSubject scrollToSubject; private long selectedChannelId; private final StoreStream stream; /* compiled from: StoreMessagesLoader.kt */ public static final class ChannelChunk { private final long channelId; private final boolean isAppendingTop; private final boolean isInitial; private final boolean isJump; private final boolean isPresent; private final List messages; public ChannelChunk(long j, List list, boolean z2, boolean z3, boolean z4, boolean z5) { m.checkNotNullParameter(list, "messages"); this.channelId = j; this.messages = list; this.isInitial = z2; this.isPresent = z3; this.isAppendingTop = z4; this.isJump = z5; } public static /* synthetic */ ChannelChunk copy$default(ChannelChunk channelChunk, long j, List list, boolean z2, boolean z3, boolean z4, boolean z5, int i, Object obj) { return channelChunk.copy((i & 1) != 0 ? channelChunk.channelId : j, (i & 2) != 0 ? channelChunk.messages : list, (i & 4) != 0 ? channelChunk.isInitial : z2, (i & 8) != 0 ? channelChunk.isPresent : z3, (i & 16) != 0 ? channelChunk.isAppendingTop : z4, (i & 32) != 0 ? channelChunk.isJump : z5); } public final long component1() { return this.channelId; } public final List component2() { return this.messages; } public final boolean component3() { return this.isInitial; } public final boolean component4() { return this.isPresent; } public final boolean component5() { return this.isAppendingTop; } public final boolean component6() { return this.isJump; } public final ChannelChunk copy(long j, List list, boolean z2, boolean z3, boolean z4, boolean z5) { m.checkNotNullParameter(list, "messages"); return new ChannelChunk(j, list, z2, z3, z4, z5); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof ChannelChunk)) { return false; } ChannelChunk channelChunk = (ChannelChunk) obj; return this.channelId == channelChunk.channelId && m.areEqual(this.messages, channelChunk.messages) && this.isInitial == channelChunk.isInitial && this.isPresent == channelChunk.isPresent && this.isAppendingTop == channelChunk.isAppendingTop && this.isJump == channelChunk.isJump; } public final long getChannelId() { return this.channelId; } public final List getMessages() { return this.messages; } public int hashCode() { int a = b.a(this.channelId) * 31; List list = this.messages; int hashCode = (a + (list != null ? list.hashCode() : 0)) * 31; boolean z2 = this.isInitial; int i = 1; if (z2) { z2 = true; } int i2 = z2 ? 1 : 0; int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = (hashCode + i2) * 31; boolean z3 = this.isPresent; if (z3) { z3 = true; } int i6 = z3 ? 1 : 0; int i7 = z3 ? 1 : 0; int i8 = z3 ? 1 : 0; int i9 = (i5 + i6) * 31; boolean z4 = this.isAppendingTop; if (z4) { z4 = true; } int i10 = z4 ? 1 : 0; int i11 = z4 ? 1 : 0; int i12 = z4 ? 1 : 0; int i13 = (i9 + i10) * 31; boolean z5 = this.isJump; if (!z5) { i = z5 ? 1 : 0; } return i13 + i; } public final boolean isAppendingTop() { return this.isAppendingTop; } public final boolean isInitial() { return this.isInitial; } public final boolean isJump() { return this.isJump; } public final boolean isPresent() { return this.isPresent; } public String toString() { StringBuilder K = a.K("ChannelChunk(channelId="); K.append(this.channelId); K.append(", messages="); K.append(this.messages); K.append(", isInitial="); K.append(this.isInitial); K.append(", isPresent="); K.append(this.isPresent); K.append(", isAppendingTop="); K.append(this.isAppendingTop); K.append(", isJump="); return a.F(K, this.isJump, ")"); } } /* compiled from: StoreMessagesLoader.kt */ public static final class ChannelLoadedState { private final boolean isInitialMessagesLoaded; private final boolean isLoadingMessages; private final boolean isOldestMessagesLoaded; private final boolean isTouchedSinceLastJump; private final Long newestSentByUserMessageId; public ChannelLoadedState() { this(false, false, false, false, null, 31, null); } public ChannelLoadedState(boolean z2, boolean z3, boolean z4, boolean z5, Long l) { this.isInitialMessagesLoaded = z2; this.isOldestMessagesLoaded = z3; this.isLoadingMessages = z4; this.isTouchedSinceLastJump = z5; this.newestSentByUserMessageId = l; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ ChannelLoadedState(boolean z2, boolean z3, boolean z4, boolean z5, Long l, int i, DefaultConstructorMarker defaultConstructorMarker) { this((i & 1) != 0 ? false : z2, (i & 2) != 0 ? false : z3, (i & 4) != 0 ? false : z4, (i & 8) == 0 ? z5 : false, (i & 16) != 0 ? null : l); } public static /* synthetic */ ChannelLoadedState copy$default(ChannelLoadedState channelLoadedState, boolean z2, boolean z3, boolean z4, boolean z5, Long l, int i, Object obj) { if ((i & 1) != 0) { z2 = channelLoadedState.isInitialMessagesLoaded; } if ((i & 2) != 0) { z3 = channelLoadedState.isOldestMessagesLoaded; } if ((i & 4) != 0) { z4 = channelLoadedState.isLoadingMessages; } if ((i & 8) != 0) { z5 = channelLoadedState.isTouchedSinceLastJump; } if ((i & 16) != 0) { l = channelLoadedState.newestSentByUserMessageId; } return channelLoadedState.copy(z2, z3, z4, z5, l); } public final boolean component1() { return this.isInitialMessagesLoaded; } public final boolean component2() { return this.isOldestMessagesLoaded; } public final boolean component3() { return this.isLoadingMessages; } public final boolean component4() { return this.isTouchedSinceLastJump; } public final Long component5() { return this.newestSentByUserMessageId; } public final ChannelLoadedState copy(boolean z2, boolean z3, boolean z4, boolean z5, Long l) { return new ChannelLoadedState(z2, z3, z4, z5, l); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof ChannelLoadedState)) { return false; } ChannelLoadedState channelLoadedState = (ChannelLoadedState) obj; return this.isInitialMessagesLoaded == channelLoadedState.isInitialMessagesLoaded && this.isOldestMessagesLoaded == channelLoadedState.isOldestMessagesLoaded && this.isLoadingMessages == channelLoadedState.isLoadingMessages && this.isTouchedSinceLastJump == channelLoadedState.isTouchedSinceLastJump && m.areEqual(this.newestSentByUserMessageId, channelLoadedState.newestSentByUserMessageId); } public final Long getNewestSentByUserMessageId() { return this.newestSentByUserMessageId; } public int hashCode() { boolean z2 = this.isInitialMessagesLoaded; int i = 1; if (z2) { z2 = true; } int i2 = z2 ? 1 : 0; int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = i2 * 31; boolean z3 = this.isOldestMessagesLoaded; if (z3) { z3 = true; } int i6 = z3 ? 1 : 0; int i7 = z3 ? 1 : 0; int i8 = z3 ? 1 : 0; int i9 = (i5 + i6) * 31; boolean z4 = this.isLoadingMessages; if (z4) { z4 = true; } int i10 = z4 ? 1 : 0; int i11 = z4 ? 1 : 0; int i12 = z4 ? 1 : 0; int i13 = (i9 + i10) * 31; boolean z5 = this.isTouchedSinceLastJump; if (!z5) { i = z5 ? 1 : 0; } int i14 = (i13 + i) * 31; Long l = this.newestSentByUserMessageId; return i14 + (l != null ? l.hashCode() : 0); } public final boolean isInitialMessagesLoaded() { return this.isInitialMessagesLoaded; } public final boolean isLoadingMessages() { return this.isLoadingMessages; } public final boolean isOldestMessagesLoaded() { return this.isOldestMessagesLoaded; } public final boolean isTouchedSinceLastJump() { return this.isTouchedSinceLastJump; } public String toString() { StringBuilder K = a.K("ChannelLoadedState(isInitialMessagesLoaded="); K.append(this.isInitialMessagesLoaded); K.append(", isOldestMessagesLoaded="); K.append(this.isOldestMessagesLoaded); K.append(", isLoadingMessages="); K.append(this.isLoadingMessages); K.append(", isTouchedSinceLastJump="); K.append(this.isTouchedSinceLastJump); K.append(", newestSentByUserMessageId="); return a.A(K, this.newestSentByUserMessageId, ")"); } } /* compiled from: StoreMessagesLoader.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final boolean isScrollToAction(long j) { return j == 0 || j == 1; } } public StoreMessagesLoader(StoreStream storeStream, Dispatcher dispatcher) { m.checkNotNullParameter(storeStream, "stream"); m.checkNotNullParameter(dispatcher, "dispatcher"); this.stream = storeStream; this.dispatcher = dispatcher; HashMap hashMap = new HashMap<>(); this.channelLoadedStates = hashMap; this.channelLoadedStateSubject = new SerializedSubject<>(BehaviorSubject.l0(new HashMap(hashMap))); this.scrollToSubject = new SerializedSubject<>(BehaviorSubject.l0(null)); this.channelMessagesLoadingSubject = new SerializedSubject<>(BehaviorSubject.l0(Boolean.FALSE)); this.detachedChannels = n0.emptySet(); this.backgrounded = true; this.loadingMessagesRetryDelayDefault = 1500; this.loadingMessagesRetryJitter = 2000; this.loadingMessagesRetryDelayMillis = 1500; this.loadingMessagesRetryMax = 30000; } public static final /* synthetic */ void access$channelLoadedStateUpdate(StoreMessagesLoader storeMessagesLoader, long j, Function1 function1) { storeMessagesLoader.channelLoadedStateUpdate(j, function1); } public static final /* synthetic */ SerializedSubject access$getChannelMessagesLoadingSubject$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.channelMessagesLoadingSubject; } public static final /* synthetic */ Subscription access$getDelayLoadingMessagesSubscription$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.delayLoadingMessagesSubscription; } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.dispatcher; } public static final /* synthetic */ Subscription access$getLoadingMessagesSubscription$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.loadingMessagesSubscription; } public static final /* synthetic */ int access$getMessageRequestSize$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.messageRequestSize; } public static final /* synthetic */ SerializedSubject access$getScrollToSubject$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.scrollToSubject; } public static final /* synthetic */ long access$getSelectedChannelId$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.selectedChannelId; } public static final /* synthetic */ StoreStream access$getStream$p(StoreMessagesLoader storeMessagesLoader) { return storeMessagesLoader.stream; } public static final /* synthetic */ void access$handleChatDetached(StoreMessagesLoader storeMessagesLoader, Set set) { storeMessagesLoader.handleChatDetached(set); } public static final /* synthetic */ void access$handleChatInteraction(StoreMessagesLoader storeMessagesLoader, StoreChat.InteractionState interactionState) { storeMessagesLoader.handleChatInteraction(interactionState); } public static final /* synthetic */ void access$handleLoadMessagesError(StoreMessagesLoader storeMessagesLoader, long j) { storeMessagesLoader.handleLoadMessagesError(j); } public static final /* synthetic */ void access$handleLoadedMessages(StoreMessagesLoader storeMessagesLoader, List list, long j, long j2, Long l, Long l2) { storeMessagesLoader.handleLoadedMessages(list, j, j2, l, l2); } public static final /* synthetic */ void access$setDelayLoadingMessagesSubscription$p(StoreMessagesLoader storeMessagesLoader, Subscription subscription) { storeMessagesLoader.delayLoadingMessagesSubscription = subscription; } public static final /* synthetic */ void access$setLoadingMessagesSubscription$p(StoreMessagesLoader storeMessagesLoader, Subscription subscription) { storeMessagesLoader.loadingMessagesSubscription = subscription; } public static final /* synthetic */ void access$setSelectedChannelId$p(StoreMessagesLoader storeMessagesLoader, long j) { storeMessagesLoader.selectedChannelId = j; } private final synchronized void channelLoadedStateUpdate(long j, Function1 function1) { ChannelLoadedState channelLoadedState = this.channelLoadedStates.get(Long.valueOf(j)); if (channelLoadedState == null) { channelLoadedState = new ChannelLoadedState(false, false, false, false, null, 31, null); } m.checkNotNullExpressionValue(channelLoadedState, "channelLoadedStates[chan…] ?: ChannelLoadedState()"); this.channelLoadedStates.put(Long.valueOf(j), function1.invoke(channelLoadedState)); SerializedSubject, Map> serializedSubject = this.channelLoadedStateSubject; serializedSubject.j.onNext(new HashMap(this.channelLoadedStates)); } private final void channelLoadedStatesReset() { this.channelLoadedStates.clear(); SerializedSubject, Map> serializedSubject = this.channelLoadedStateSubject; serializedSubject.j.onNext(new HashMap(this.channelLoadedStates)); Subscription subscription = this.loadingMessagesSubscription; if (subscription != null) { subscription.unsubscribe(); } this.loadingMessagesRetryDelayMillis = this.loadingMessagesRetryDelayDefault; log("Disconnected, resetting all message loaded states."); } private final synchronized void handleChatDetached(Set set) { this.detachedChannels = set; log("Loaded detached channel state: " + set); tryLoadMessages$default(this, 0, false, true, false, null, null, 59, null); } private final synchronized void handleChatInteraction(StoreChat.InteractionState interactionState) { channelLoadedStateUpdate(interactionState.getChannelId(), new StoreMessagesLoader$handleChatInteraction$1$1(interactionState)); this.interactionState = interactionState; tryLoadMessages$default(this, 0, false, true, false, null, null, 59, null); } private final synchronized void handleLoadMessagesError(long j) { channelLoadedStateUpdate(j, StoreMessagesLoader$handleLoadMessagesError$1.INSTANCE); long j2 = this.loadingMessagesRetryDelayMillis; if (j2 < ((long) this.loadingMessagesRetryMax)) { this.loadingMessagesRetryDelayMillis = (j2 * ((long) 2)) + ((long) new Random().nextInt(this.loadingMessagesRetryJitter)); } StringBuilder sb = new StringBuilder(); sb.append("Failed to load messages for channel [" + j + "], "); sb.append("retrying in " + this.loadingMessagesRetryDelayMillis + "ms"); String sb2 = sb.toString(); m.checkNotNullExpressionValue(sb2, "StringBuilder()\n …}ms\")\n .toString()"); log(sb2); tryLoadMessages$default(this, this.loadingMessagesRetryDelayMillis, false, false, false, null, null, 58, null); } /* JADX WARNING: Removed duplicated region for block: B:27:0x0070 */ /* JADX WARNING: Removed duplicated region for block: B:32:0x007e */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0082 */ /* JADX WARNING: Removed duplicated region for block: B:36:0x008e */ /* JADX WARNING: Removed duplicated region for block: B:39:0x009f */ private final synchronized void handleLoadedMessages(List list, long j, long j2, Long l, Long l2) { boolean z2; boolean z3; Object obj; boolean z4; boolean z5 = list.size() < this.messageRequestSize; boolean z6 = l2 != null; boolean z7 = l != null; boolean z8 = !Companion.isScrollToAction(j2); boolean z9 = !z8 && !z6 && !z7; if (!z9) { if (!z6 || !z5) { z2 = false; channelLoadedStateUpdate(j, new StoreMessagesLoader$handleLoadedMessages$1(this, z9, z7, z5, list)); this.channelMessagesLoadingSubject.j.onNext(Boolean.FALSE); this.channelMessageChunksSubject.j.onNext(new ChannelChunk(j, list, z9, z2, z7, z8)); if (!z9) { if ((!list.isEmpty()) && j2 == 1) { z3 = true; if (z3) { this.scrollToSubject.j.onNext(1L); } else if (z9) { this.scrollToSubject.j.onNext(0L); } if (z8) { Iterator it = list.iterator(); while (true) { if (!it.hasNext()) { obj = null; break; } obj = it.next(); if (((Message) obj).getId() == j2) { z4 = true; continue; } else { z4 = false; continue; } if (z4) { break; } } Message message = (Message) obj; if (message == null) { StoreStream.Companion.getReadStates().markAsRead(Long.valueOf(j)); } else { this.scrollToSubject.j.onNext(Long.valueOf(message.getId())); } } if (!z8 && !z3) { clearScrollTo(); } log("Loaded " + list.size() + " messages for channel [" + j + "], all loaded: " + z5 + '.'); tryLoadMessages$default(this, this.loadingMessagesRetryDelayDefault, false, false, false, null, null, 58, null); } } z3 = false; if (z3) { } if (z8) { } clearScrollTo(); log("Loaded " + list.size() + " messages for channel [" + j + "], all loaded: " + z5 + '.'); tryLoadMessages$default(this, this.loadingMessagesRetryDelayDefault, false, false, false, null, null, 58, null); } } z2 = true; channelLoadedStateUpdate(j, new StoreMessagesLoader$handleLoadedMessages$1(this, z9, z7, z5, list)); this.channelMessagesLoadingSubject.j.onNext(Boolean.FALSE); this.channelMessageChunksSubject.j.onNext(new ChannelChunk(j, list, z9, z2, z7, z8)); if (!z9) { } z3 = false; if (z3) { } if (z8) { } clearScrollTo(); log("Loaded " + list.size() + " messages for channel [" + j + "], all loaded: " + z5 + '.'); tryLoadMessages$default(this, this.loadingMessagesRetryDelayDefault, false, false, false, null, null, 58, null); } public static /* synthetic */ void handleLoadedMessages$default(StoreMessagesLoader storeMessagesLoader, List list, long j, long j2, Long l, Long l2, int i, Object obj) { storeMessagesLoader.handleLoadedMessages(list, j, (i & 4) != 0 ? 0 : j2, (i & 8) != 0 ? null : l, (i & 16) != 0 ? null : l2); } private final void log(String str) { AppLog.i("[MessageLoader] " + str); } private final synchronized void tryLoadMessages(long j, boolean z2, boolean z3, boolean z4, Long l, Long l2) { long longValue = l != null ? l.longValue() : this.selectedChannelId; Subscription subscription = this.delayLoadingMessagesSubscription; if (subscription != null && z4) { if (subscription != null) { subscription.unsubscribe(); } this.delayLoadingMessagesSubscription = null; } if (this.delayLoadingMessagesSubscription != null && !z2) { return; } if (j > 0) { Observable d02 = Observable.d0(j, TimeUnit.MILLISECONDS); m.checkNotNullExpressionValue(d02, "Observable\n .ti…y, TimeUnit.MILLISECONDS)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationBuffered(d02), getClass(), (Context) null, new StoreMessagesLoader$tryLoadMessages$2(this), (Function1) null, (Function0) null, (Function0) null, new StoreMessagesLoader$tryLoadMessages$1(this), 58, (Object) null); return; } if (z3) { this.loadingMessagesRetryDelayMillis = this.loadingMessagesRetryDelayDefault; } ChannelLoadedState channelLoadedState = this.channelLoadedStates.get(Long.valueOf(longValue)); if (channelLoadedState == null || !channelLoadedState.isLoadingMessages() || z2) { Subscription subscription2 = this.loadingMessagesSubscription; if (subscription2 != null) { subscription2.unsubscribe(); } if (longValue > 0 && !this.backgrounded && this.authed) { StoreMessagesLoader$tryLoadMessages$3 storeMessagesLoader$tryLoadMessages$3 = new StoreMessagesLoader$tryLoadMessages$3(this); StoreMessagesLoader$tryLoadMessages$4 storeMessagesLoader$tryLoadMessages$4 = new StoreMessagesLoader$tryLoadMessages$4(this, storeMessagesLoader$tryLoadMessages$3); if (l2 != null) { StoreMessagesLoader$tryLoadMessages$3.invoke$default(storeMessagesLoader$tryLoadMessages$3, longValue, l2, null, null, 12, null); } else if (channelLoadedState == null || !channelLoadedState.isInitialMessagesLoaded()) { StoreMessagesLoader$tryLoadMessages$3.invoke$default(storeMessagesLoader$tryLoadMessages$3, longValue, 0L, null, null, 12, null); } else { this.channelMessagesLoadingSubject.j.onNext(Boolean.FALSE); StoreChat.InteractionState interactionState = this.interactionState; if (interactionState != null) { boolean z5 = false; boolean z6 = interactionState.isAtTop() && !channelLoadedState.isOldestMessagesLoaded(); if (interactionState.isAtBottom() && this.detachedChannels.contains(Long.valueOf(longValue))) { z5 = true; } if (interactionState.getChannelId() == longValue && (z6 || z5)) { channelLoadedStateUpdate(longValue, StoreMessagesLoader$tryLoadMessages$5$1.INSTANCE); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationBuffered(ObservableExtensionsKt.takeSingleUntilTimeout$default(this.stream.getMessages$app_productionBetaRelease().observeMessagesForChannel(longValue), 0, false, 3, null)), interactionState.getClass(), (Context) null, (Function1) null, new StoreMessagesLoader$tryLoadMessages$$inlined$apply$lambda$2(this, channelLoadedState, longValue, storeMessagesLoader$tryLoadMessages$4), (Function0) null, (Function0) null, new StoreMessagesLoader$tryLoadMessages$$inlined$apply$lambda$1(z6, z5, this, channelLoadedState, longValue, storeMessagesLoader$tryLoadMessages$4), 54, (Object) null); } } } } } } public static /* synthetic */ void tryLoadMessages$default(StoreMessagesLoader storeMessagesLoader, long j, boolean z2, boolean z3, boolean z4, Long l, Long l2, int i, Object obj) { long j2 = (i & 1) != 0 ? 0 : j; boolean z5 = false; boolean z6 = (i & 2) != 0 ? false : z2; boolean z7 = (i & 4) != 0 ? false : z3; if ((i & 8) == 0) { z5 = z4; } Long l3 = null; Long l4 = (i & 16) != 0 ? null : l; if ((i & 32) == 0) { l3 = l2; } storeMessagesLoader.tryLoadMessages(j2, z6, z7, z5, l4, l3); } public final void clearScrollTo() { this.scrollToSubject.j.onNext(null); } public final Observable get() { return ObservableExtensionsKt.computationBuffered(this.channelMessageChunksSubject); } public final Observable getMessagesLoadedState(long j) { Observable> F = this.channelLoadedStateSubject.F(new StoreMessagesLoader$getMessagesLoadedState$1(j)); m.checkNotNullExpressionValue(F, "channelLoadedStateSubjec…?: ChannelLoadedState() }"); Observable r = ObservableExtensionsKt.computationLatest(F).r(); m.checkNotNullExpressionValue(r, "channelLoadedStateSubjec… .distinctUntilChanged()"); return r; } public final Observable getScrollTo() { Observable F = this.scrollToSubject.x(ObservableExtensionsKt$filterNull$1.INSTANCE).F(ObservableExtensionsKt$filterNull$2.INSTANCE); m.checkNotNullExpressionValue(F, "filter { it != null }.map { it!! }"); return ObservableExtensionsKt.computationLatest(F); } public final synchronized void handleAuthToken(String str) { this.authed = str != null; tryLoadMessages$default(this, 0, false, true, false, null, null, 59, null); } public final synchronized void handleBackgrounded(boolean z2) { this.backgrounded = z2; tryLoadMessages$default(this, 0, false, true, false, null, null, 59, null); } @StoreThread public final synchronized void handleChannelSelected(long j) { channelLoadedStateUpdate(this.selectedChannelId, StoreMessagesLoader$handleChannelSelected$1.INSTANCE); this.selectedChannelId = j; tryLoadMessages$default(this, 0, true, true, false, null, null, 57, null); } public final synchronized void handleConnected(boolean z2) { if (z2) { this.hasConnected = true; } else if (this.hasConnected) { channelLoadedStatesReset(); } tryLoadMessages$default(this, 0, false, true, this.hasConnected, null, null, 51, null); } @Override // com.discord.stores.Store public void init(Context context) { m.checkNotNullParameter(context, "context"); super.init(context); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationLatest(this.stream.getChat$app_productionBetaRelease().observeInteractionState()), StoreMessagesLoader.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreMessagesLoader$init$1(this), 62, (Object) null); ObservableExtensionsKt.appSubscribe$default(this.stream.getMessages$app_productionBetaRelease().getAllDetached(), StoreMessagesLoader.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreMessagesLoader$init$2(this), 62, (Object) null); } public final synchronized void jumpToMessage(long j, long j2) { if (j2 > 0) { StoreMessagesLoader$jumpToMessage$1 storeMessagesLoader$jumpToMessage$1 = new StoreMessagesLoader$jumpToMessage$1(this, j, j2); StoreMessagesLoader$jumpToMessage$2 storeMessagesLoader$jumpToMessage$2 = new StoreMessagesLoader$jumpToMessage$2(this, j); Observable Y = this.stream.getChannelsSelected$app_productionBetaRelease().observeId().k(q.c(new StoreMessagesLoader$jumpToMessage$3(j), -1L, 1000, TimeUnit.MILLISECONDS)).Y(new StoreMessagesLoader$jumpToMessage$4(this, j, j2)); m.checkNotNullExpressionValue(Y, "stream\n .channels…lId, messageId)\n }"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationLatest(ObservableExtensionsKt.takeSingleUntilTimeout$default(Y, 0, false, 3, null)), getClass(), (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreMessagesLoader$jumpToMessage$5(this, storeMessagesLoader$jumpToMessage$1), 62, (Object) null); Observable z2 = StoreConnectionOpen.observeConnectionOpen$default(this.stream.getConnectionOpen$app_productionBetaRelease(), false, 1, null).Z(1).z(new StoreMessagesLoader$jumpToMessage$6(this, j)); m.checkNotNullExpressionValue(z2, "stream\n .connecti…mes.ONE_SECOND)\n }"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationLatest(z2), getClass(), (Context) null, (Function1) null, StoreMessagesLoader$jumpToMessage$7.INSTANCE, (Function0) null, (Function0) null, new StoreMessagesLoader$jumpToMessage$8(storeMessagesLoader$jumpToMessage$2), 54, (Object) null); } } public final Observable observeChannelMessagesLoading() { Observable r = ObservableExtensionsKt.computationBuffered(this.channelMessagesLoadingSubject).r(); m.checkNotNullExpressionValue(r, "channelMessagesLoadingSu… .distinctUntilChanged()"); return r; } public final synchronized void requestNewestMessages() { ChannelLoadedState channelLoadedState; if (this.detachedChannels.contains(Long.valueOf(this.selectedChannelId)) || (channelLoadedState = this.channelLoadedStates.get(Long.valueOf(this.selectedChannelId))) == null || !channelLoadedState.isInitialMessagesLoaded()) { channelLoadedStateUpdate(this.selectedChannelId, StoreMessagesLoader$requestNewestMessages$1.INSTANCE); tryLoadMessages$default(this, 0, true, false, false, null, 1L, 25, null); return; } this.scrollToSubject.j.onNext(1L); } }