package com.discord.stores; import a0.a.a.b; 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.message.Message; import com.discord.api.thread.AugmentedThreadMember; import com.discord.api.thread.ThreadMember; import com.discord.api.thread.ThreadMemberUpdate; import com.discord.api.thread.ThreadMembersUpdate; import com.discord.api.user.User; import com.discord.api.utcdatetime.UtcDateTime; import com.discord.models.domain.ModelNotificationSettings; 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 com.discord.utilities.search.network.state.SearchState; import com.discord.utilities.time.Clock; import com.discord.utilities.time.ClockFactory; import d0.t.h0; import d0.t.r; import d0.z.d.m; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreThreadsJoined.kt */ public final class StoreThreadsJoined extends StoreV2 { public static final int ALL_FLAGS = 15; public static final Companion Companion = new Companion(null); public static final int NOTIFICATION_FLAGS = 14; private final Clock clock; private final Map joinedThreads; private Map joinedThreadsSnapshot; private final ObservationDeck observationDeck; private final StoreChannels storeChannels; private final StoreUser storeUser; private final StoreUserGuildSettings storeUserGuildSettings; private final Map upgradedThreadTimestamps; private Map upgradedThreadTimestampsSnapshot; /* compiled from: StoreThreadsJoined.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: StoreThreadsJoined.kt */ public static final class JoinedThread { private final int flags; private final long guildId; private final UtcDateTime joinTimestamp; private final long threadId; public JoinedThread(long j, long j2, int i, UtcDateTime utcDateTime) { m.checkNotNullParameter(utcDateTime, "joinTimestamp"); this.threadId = j; this.guildId = j2; this.flags = i; this.joinTimestamp = utcDateTime; } public static /* synthetic */ JoinedThread copy$default(JoinedThread joinedThread, long j, long j2, int i, UtcDateTime utcDateTime, int i2, Object obj) { if ((i2 & 1) != 0) { j = joinedThread.threadId; } if ((i2 & 2) != 0) { j2 = joinedThread.guildId; } if ((i2 & 4) != 0) { i = joinedThread.flags; } if ((i2 & 8) != 0) { utcDateTime = joinedThread.joinTimestamp; } return joinedThread.copy(j, j2, i, utcDateTime); } public final long component1() { return this.threadId; } public final long component2() { return this.guildId; } public final int component3() { return this.flags; } public final UtcDateTime component4() { return this.joinTimestamp; } public final JoinedThread copy(long j, long j2, int i, UtcDateTime utcDateTime) { m.checkNotNullParameter(utcDateTime, "joinTimestamp"); return new JoinedThread(j, j2, i, utcDateTime); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof JoinedThread)) { return false; } JoinedThread joinedThread = (JoinedThread) obj; return this.threadId == joinedThread.threadId && this.guildId == joinedThread.guildId && this.flags == joinedThread.flags && m.areEqual(this.joinTimestamp, joinedThread.joinTimestamp); } public final int getFlags() { return this.flags; } public final long getGuildId() { return this.guildId; } public final UtcDateTime getJoinTimestamp() { return this.joinTimestamp; } public final long getThreadId() { return this.threadId; } public int hashCode() { int a = (((b.a(this.guildId) + (b.a(this.threadId) * 31)) * 31) + this.flags) * 31; UtcDateTime utcDateTime = this.joinTimestamp; return a + (utcDateTime != null ? utcDateTime.hashCode() : 0); } public String toString() { StringBuilder K = a.K("JoinedThread(threadId="); K.append(this.threadId); K.append(", guildId="); K.append(this.guildId); K.append(", flags="); K.append(this.flags); K.append(", joinTimestamp="); K.append(this.joinTimestamp); K.append(")"); return K.toString(); } } public StoreThreadsJoined(StoreUser storeUser, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings, ObservationDeck observationDeck, Clock clock) { m.checkNotNullParameter(storeUser, "storeUser"); m.checkNotNullParameter(storeChannels, "storeChannels"); m.checkNotNullParameter(storeUserGuildSettings, "storeUserGuildSettings"); m.checkNotNullParameter(observationDeck, "observationDeck"); m.checkNotNullParameter(clock, "clock"); this.storeUser = storeUser; this.storeChannels = storeChannels; this.storeUserGuildSettings = storeUserGuildSettings; this.observationDeck = observationDeck; this.clock = clock; this.joinedThreads = new HashMap(); this.joinedThreadsSnapshot = h0.emptyMap(); this.upgradedThreadTimestamps = new HashMap(); this.upgradedThreadTimestampsSnapshot = h0.emptyMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreThreadsJoined(StoreUser storeUser, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings, ObservationDeck observationDeck, Clock clock, int i, DefaultConstructorMarker defaultConstructorMarker) { this(storeUser, storeChannels, storeUserGuildSettings, (i & 8) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 16) != 0 ? ClockFactory.get() : clock); } public static final /* synthetic */ boolean access$hasRecentlyAutoUpgradedNotifications(StoreThreadsJoined storeThreadsJoined, long j) { return storeThreadsJoined.hasRecentlyAutoUpgradedNotifications(j); } private final void deleteThreads(long j) { if (r.removeAll(this.joinedThreads.values(), new StoreThreadsJoined$deleteThreads$removed$1(j))) { markChanged(); } } private final boolean hasRecentlyAutoUpgradedNotifications(long j) { Long l = this.upgradedThreadTimestampsSnapshot.get(Long.valueOf(j)); return this.clock.currentTimeMillis() - (l != null ? l.longValue() : 0) < ((long) 900000); } private final void saveThreads(Guild guild) { ThreadMember j; List K = guild.K(); if (K != null) { for (Channel channel : K) { if (AnimatableValueParser.A1(channel) && (j = channel.j()) != null) { this.joinedThreads.put(Long.valueOf(channel.h()), new JoinedThread(channel.h(), guild.o(), j.a(), j.c())); markChanged(); } } } } @StoreThread public final Map getAllJoinedThreadsInternal$app_productionBetaRelease() { return this.joinedThreads; } public final JoinedThread getJoinedThread(long j) { return this.joinedThreadsSnapshot.get(Long.valueOf(j)); } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "payload"); this.joinedThreads.clear(); this.upgradedThreadTimestamps.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 handleMessageCreate(Message message) { JoinedThread joinedThread; m.checkNotNullParameter(message, "message"); User e = message.e(); if (e != null && e.i() == this.storeUser.getMe().getId()) { Long m = message.m(); Channel channelInternal$app_productionBetaRelease = this.storeChannels.getChannelInternal$app_productionBetaRelease(m != null ? m.longValue() : 0, message.g()); if (channelInternal$app_productionBetaRelease != null && AnimatableValueParser.A1(channelInternal$app_productionBetaRelease) && (joinedThread = this.joinedThreads.get(Long.valueOf(message.g()))) != null && (joinedThread.getFlags() & 15) == 0 && !NotificationTextUtils.INSTANCE.isGuildOrCategoryOrChannelMuted((ModelNotificationSettings) a.n0(channelInternal$app_productionBetaRelease, this.storeUserGuildSettings.getGuildSettingsInternal$app_productionBetaRelease()), channelInternal$app_productionBetaRelease)) { this.upgradedThreadTimestamps.put(Long.valueOf(message.g()), Long.valueOf(this.clock.currentTimeMillis())); } } } @StoreThread public final void handleSearchFinish(SearchState searchState) { Channel channel; m.checkNotNullParameter(searchState, "searchState"); List threads = searchState.getThreads(); if (!(threads == null || (channel = threads.get(0)) == null)) { long f = channel.f(); List threadMembers = searchState.getThreadMembers(); if (threadMembers != null) { for (ThreadMember threadMember : threadMembers) { if (threadMember.d() == this.storeUser.getMe().getId()) { this.joinedThreads.put(Long.valueOf(threadMember.b()), new JoinedThread(threadMember.b(), f, threadMember.a(), threadMember.c())); } } } } } @StoreThread public final void handleThreadCreateOrUpdate(Channel channel) { m.checkNotNullParameter(channel, "channel"); ThreadMember j = channel.j(); if (j != null && j.d() == this.storeUser.getMe().getId()) { this.joinedThreads.put(Long.valueOf(channel.h()), new JoinedThread(channel.h(), channel.f(), j.a(), j.c())); markChanged(); } } @StoreThread public final void handleThreadDelete(Channel channel) { m.checkNotNullParameter(channel, "channel"); if (this.joinedThreads.containsKey(Long.valueOf(channel.h()))) { this.joinedThreads.remove(Long.valueOf(channel.h())); this.upgradedThreadTimestamps.remove(Long.valueOf(channel.h())); markChanged(); } } @StoreThread public final void handleThreadListSync(ModelThreadListSync modelThreadListSync) { m.checkNotNullParameter(modelThreadListSync, "payload"); List members = modelThreadListSync.getMembers(); if (members != null) { for (ThreadMember threadMember : members) { this.joinedThreads.put(Long.valueOf(threadMember.b()), new JoinedThread(threadMember.b(), modelThreadListSync.getGuildId(), threadMember.a(), threadMember.c())); markChanged(); } } } @StoreThread public final void handleThreadMemberUpdate(ThreadMemberUpdate threadMemberUpdate) { m.checkNotNullParameter(threadMemberUpdate, "payload"); if (threadMemberUpdate.e() == this.storeUser.getMe().getId()) { this.joinedThreads.put(Long.valueOf(threadMemberUpdate.c()), new JoinedThread(threadMemberUpdate.c(), threadMemberUpdate.b(), threadMemberUpdate.a(), threadMemberUpdate.d())); if ((threadMemberUpdate.a() & 14) != 0) { this.upgradedThreadTimestamps.remove(Long.valueOf(threadMemberUpdate.c())); } markChanged(); } } /* JADX DEBUG: Multi-variable search result rejected for r5v2, resolved type: java.lang.Object */ /* JADX WARN: Multi-variable type inference failed */ @StoreThread public final void handleThreadMembersUpdate(ThreadMembersUpdate threadMembersUpdate) { boolean z2; List d; m.checkNotNullParameter(threadMembersUpdate, "payload"); long id2 = this.storeUser.getMe().getId(); if (this.joinedThreads.containsKey(Long.valueOf(threadMembersUpdate.c())) && (d = threadMembersUpdate.d()) != null && d.contains(Long.valueOf(id2))) { this.joinedThreads.remove(Long.valueOf(threadMembersUpdate.c())); this.upgradedThreadTimestamps.remove(Long.valueOf(threadMembersUpdate.c())); markChanged(); } List a = threadMembersUpdate.a(); AugmentedThreadMember augmentedThreadMember = null; if (a != null) { Iterator it = a.iterator(); while (true) { if (!it.hasNext()) { break; } Object next = it.next(); if (((AugmentedThreadMember) next).e() == id2) { z2 = true; continue; } else { z2 = false; continue; } if (z2) { augmentedThreadMember = next; break; } } augmentedThreadMember = augmentedThreadMember; } if (augmentedThreadMember != null) { this.joinedThreads.put(Long.valueOf(threadMembersUpdate.c()), new JoinedThread(threadMembersUpdate.c(), threadMembersUpdate.b(), augmentedThreadMember.a(), augmentedThreadMember.b())); markChanged(); } } public final boolean hasJoined(long j) { return this.joinedThreadsSnapshot.containsKey(Long.valueOf(j)); } @StoreThread public final boolean hasJoinedInternal(long j) { return this.joinedThreads.containsKey(Long.valueOf(j)); } public final Observable observeJoinedThread(long j) { return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadsJoined$observeJoinedThread$1(this, j), 14, null); } public final Observable observeRecentlyAutoUpgradedNotifications(long j) { return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadsJoined$observeRecentlyAutoUpgradedNotifications$1(this, j), 14, null); } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { this.joinedThreadsSnapshot = new HashMap(this.joinedThreads); this.upgradedThreadTimestampsSnapshot = new HashMap(this.upgradedThreadTimestamps); } }