package com.discord.stores; import c.d.b.a.a; import com.airbnb.lottie.parser.AnimatableValueParser; import com.discord.api.channel.Channel; import com.discord.api.guild.Guild; import com.discord.api.thread.ThreadMetadata; import com.discord.models.domain.ModelPayload; import com.discord.models.thread.dto.ModelThreadListSync; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import d0.d0.f; import d0.t.g0; import d0.t.h0; import d0.t.o; import d0.t.u; import d0.z.d.m; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreThreadsActive.kt */ public final class StoreThreadsActive extends StoreV2 { private final ObservationDeck observationDeck; private final StoreChannels storeChannels; private final Map> threadsByGuild; private Map> threadsByGuildSnapshot; public StoreThreadsActive(StoreChannels storeChannels, ObservationDeck observationDeck) { m.checkNotNullParameter(storeChannels, "storeChannels"); m.checkNotNullParameter(observationDeck, "observationDeck"); this.storeChannels = storeChannels; this.observationDeck = observationDeck; this.threadsByGuild = new HashMap(); this.threadsByGuildSnapshot = h0.emptyMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreThreadsActive(StoreChannels storeChannels, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) { this(storeChannels, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck); } public static final /* synthetic */ Map access$getActiveThreadsForChannel(StoreThreadsActive storeThreadsActive, long j, Long l) { return storeThreadsActive.getActiveThreadsForChannel(j, l); } public static final /* synthetic */ Map access$getActiveThreadsForGuild(StoreThreadsActive storeThreadsActive, long j) { return storeThreadsActive.getActiveThreadsForGuild(j); } public static final /* synthetic */ Set access$getChannelsWithActiveThreadsByGuild(StoreThreadsActive storeThreadsActive, long j) { return storeThreadsActive.getChannelsWithActiveThreadsByGuild(j); } private final void deleteThread(Channel channel) { Map map = (Map) a.n0(channel, this.threadsByGuild); if (map != null && map.containsKey(Long.valueOf(channel.h()))) { map.remove(Long.valueOf(channel.h())); markChanged(); } } private final void deleteThreads(long j) { if (this.threadsByGuild.containsKey(Long.valueOf(j))) { this.threadsByGuild.remove(Long.valueOf(j)); markChanged(); } } private final Map getActiveThreadsForChannel(long j, Long l) { if (l == null) { return h0.emptyMap(); } Map map = (Map) this.threadsByGuildSnapshot.get(Long.valueOf(j)); if (map == null) { map = h0.emptyMap(); } LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry entry : map.entrySet()) { if (((Channel) entry.getValue()).r() == l.longValue()) { linkedHashMap.put(entry.getKey(), entry.getValue()); } } return linkedHashMap; } private final Map getActiveThreadsForGuild(long j) { Map map = (Map) this.threadsByGuildSnapshot.get(Long.valueOf(j)); return map != null ? map : h0.emptyMap(); } private final Set getChannelsWithActiveThreadsByGuild(long j) { Map map = (Map) this.threadsByGuildSnapshot.get(Long.valueOf(j)); if (map == null) { map = h0.emptyMap(); } ArrayList arrayList = new ArrayList(map.size()); for (Map.Entry entry : map.entrySet()) { arrayList.add(Long.valueOf(((Channel) entry.getValue()).r())); } return u.toSet(arrayList); } private final void saveThreads(Guild guild) { ThreadMetadata y2; List threadsForGuildInternal$app_productionBetaRelease = this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(guild.o()); if (!threadsForGuildInternal$app_productionBetaRelease.isEmpty()) { Map> map = this.threadsByGuild; Long valueOf = Long.valueOf(guild.o()); ArrayList arrayList = new ArrayList(); for (Object obj : threadsForGuildInternal$app_productionBetaRelease) { Channel channel = (Channel) obj; if (AnimatableValueParser.A1(channel) && ((y2 = channel.y()) == null || !y2.b())) { arrayList.add(obj); } } LinkedHashMap linkedHashMap = new LinkedHashMap(f.coerceAtLeast(g0.mapCapacity(o.collectionSizeOrDefault(arrayList, 10)), 16)); for (Object obj2 : arrayList) { linkedHashMap.put(Long.valueOf(((Channel) obj2).h()), obj2); } map.put(valueOf, h0.toMutableMap(linkedHashMap)); markChanged(); } } @StoreThread public final Map> getAllActiveThreadsInternal$app_productionBetaRelease() { return this.threadsByGuild; } @StoreThread public final void handleChannelCreateOrUpdate(Channel channel) { m.checkNotNullParameter(channel, "channel"); Map map = (Map) a.n0(channel, this.threadsByGuild); if (map != null) { Collection values = map.values(); ArrayList arrayList = new ArrayList(); for (Object obj : values) { Channel channel2 = (Channel) obj; if (channel2.r() == channel.h() && channel2.o() != channel.o()) { arrayList.add(obj); } } for (Channel channel3 : arrayList) { Channel channelInternal$app_productionBetaRelease = this.storeChannels.getChannelInternal$app_productionBetaRelease(channel3.f(), channel3.h()); if (channelInternal$app_productionBetaRelease != null) { map.put(Long.valueOf(channelInternal$app_productionBetaRelease.h()), channelInternal$app_productionBetaRelease); } } } } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "payload"); this.threadsByGuild.clear(); List guilds = modelPayload.getGuilds(); m.checkNotNullExpressionValue(guilds, "payload.guilds"); for (Guild guild : guilds) { m.checkNotNullExpressionValue(guild, "guild"); saveThreads(guild); } markChanged(); } @StoreThread public final void handleGuildCreate(Guild guild) { m.checkNotNullParameter(guild, "guild"); deleteThreads(guild.o()); saveThreads(guild); } @StoreThread public final void handleGuildDelete(long j) { deleteThreads(j); } @StoreThread public final void handleThreadCreateOrUpdate(Channel channel) { m.checkNotNullParameter(channel, "channel"); if (AnimatableValueParser.A1(channel)) { ThreadMetadata y2 = channel.y(); if (y2 == null || !y2.b()) { Map> map = this.threadsByGuild; Long valueOf = Long.valueOf(channel.f()); Map map2 = map.get(valueOf); if (map2 == null) { map2 = new HashMap<>(); map.put(valueOf, map2); } map2.put(Long.valueOf(channel.h()), channel); markChanged(); return; } deleteThread(channel); } } @StoreThread public final void handleThreadDelete(Channel channel) { m.checkNotNullParameter(channel, "channel"); deleteThread(channel); } @StoreThread public final void handleThreadListSync(ModelThreadListSync modelThreadListSync) { m.checkNotNullParameter(modelThreadListSync, "payload"); Map> map = this.threadsByGuild; Long valueOf = Long.valueOf(modelThreadListSync.getGuildId()); Map map2 = map.get(valueOf); if (map2 == null) { map2 = new HashMap<>(); map.put(valueOf, map2); } Map map3 = map2; for (Channel channel : modelThreadListSync.getThreads()) { if (AnimatableValueParser.A1(channel)) { map3.put(Long.valueOf(channel.h()), channel); } } markChanged(); } public final Observable> observeActiveThreadsForChannel(long j, Long l) { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadsActive$observeActiveThreadsForChannel$1(this, j, l), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()"); return r; } public final Observable> observeActiveThreadsForGuild(long j) { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadsActive$observeActiveThreadsForGuild$1(this, j), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()"); return r; } public final Observable> observeChannelsWithActiveThreadsByGuild(long j) { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadsActive$observeChannelsWithActiveThreadsByGuild$1(this, j), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()"); return r; } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { Map> map = this.threadsByGuild; LinkedHashMap linkedHashMap = new LinkedHashMap(g0.mapCapacity(map.size())); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); linkedHashMap.put(entry.getKey(), new HashMap((Map) entry.getValue())); } this.threadsByGuildSnapshot = linkedHashMap; } }