package com.discord.stores; import c.d.b.a.a; import com.discord.models.message.Message; import com.discord.stores.StoreMessageAck; import d0.z.d.m; import d0.z.d.o; import j0.l.e.j; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import kotlin.Pair; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; /* compiled from: StoreMessageAck.kt */ public final class StoreMessageAck$markUnread$3 extends o implements Function1, ? extends StoreMessageAck.ThreadState>, Unit> { public final /* synthetic */ long $channelId; public final /* synthetic */ long $messageId; public final /* synthetic */ StoreMessageAck this$0; /* compiled from: StoreMessageAck.kt */ /* renamed from: com.discord.stores.StoreMessageAck$markUnread$3$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function0 { public final /* synthetic */ List $channelMessages; public final /* synthetic */ StoreMessageAck$markUnread$3 this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(StoreMessageAck$markUnread$3 storeMessageAck$markUnread$3, List list) { super(0); this.this$0 = storeMessageAck$markUnread$3; this.$channelMessages = list; } /* JADX WARN: Multi-variable type inference failed */ @Override // kotlin.jvm.functions.Function0 /* renamed from: invoke */ public final void mo1invoke() { Message message; List list = this.$channelMessages; ArrayList R = a.R(list, "channelMessages"); Iterator it = list.iterator(); while (true) { boolean z2 = true; if (!it.hasNext()) { break; } Object next = it.next(); if (((Message) next).getId() >= this.this$0.$messageId) { z2 = false; } if (z2) { R.add(next); } } Iterator it2 = R.iterator(); if (!it2.hasNext()) { message = null; } else { Object next2 = it2.next(); if (it2.hasNext()) { long id2 = ((Message) next2).getId(); do { Object next3 = it2.next(); long id3 = ((Message) next3).getId(); if (id2 < id3) { next2 = next3; id2 = id3; } } while (it2.hasNext()); } message = next2; } Message message2 = message; List list2 = this.$channelMessages; ArrayList R2 = a.R(list2, "channelMessages"); for (Object obj : list2) { if (((Message) obj).getId() >= this.this$0.$messageId) { R2.add(obj); } } StoreMessageAck.Ack ack = new StoreMessageAck.Ack(message2 != null ? message2.getId() : (((this.this$0.$messageId >>> 22) - 1) - 1420070400000L) << 22, false, true); StoreMessageAck$markUnread$3 storeMessageAck$markUnread$3 = this.this$0; StoreMessageAck.access$updateAcks(storeMessageAck$markUnread$3.this$0, storeMessageAck$markUnread$3.$channelId, ack); int processMarkUnread$app_productionBetaRelease = StoreStream.Companion.getMentions().processMarkUnread$app_productionBetaRelease(this.this$0.$channelId, R2); StoreMessageAck storeMessageAck = this.this$0.this$0; j jVar = new j(new StoreMessageAck.PendingAck(this.this$0.$channelId, ack)); m.checkNotNullExpressionValue(jVar, "Observable.just(PendingAck(channelId, ack))"); StoreMessageAck.access$postPendingAck(storeMessageAck, jVar, processMarkUnread$app_productionBetaRelease); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public StoreMessageAck$markUnread$3(StoreMessageAck storeMessageAck, long j, long j2) { super(1); this.this$0 = storeMessageAck; this.$messageId = j; this.$channelId = j2; } /* 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(Pair, ? extends StoreMessageAck.ThreadState> pair) { invoke((Pair, ? extends StoreMessageAck.ThreadState>) pair); return Unit.a; } public final void invoke(Pair, ? extends StoreMessageAck.ThreadState> pair) { List list = (List) pair.component1(); StoreMessageAck.ThreadState threadState = (StoreMessageAck.ThreadState) pair.component2(); StoreMessageAck storeMessageAck = this.this$0; m.checkNotNullExpressionValue(threadState, "threadState"); if (StoreMessageAck.access$shouldAck(storeMessageAck, threadState)) { StoreMessageAck.access$getDispatcher$p(this.this$0).schedule(new AnonymousClass1(this, list)); } } }