package com.discord.stores; import a0.a.a.b; import android.content.Context; import c.d.b.a.a; import com.discord.api.message.reaction.MessageReactionEmoji; import com.discord.api.message.reaction.MessageReactionUpdate; import com.discord.models.user.User; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.z.d.m; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreMessageReactions.kt */ public final class StoreMessageReactions extends StoreV2 { private final Dispatcher dispatcher; private final ObservationDeck observationDeck; private final Map> reactions; private Map> reactionsSnapshot; private final StoreUser userStore; /* compiled from: StoreMessageReactions.kt */ public static abstract class EmojiResults { /* compiled from: StoreMessageReactions.kt */ public static final class Failure extends EmojiResults { private final long channelId; private final MessageReactionEmoji emoji; private final long messageId; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Failure(long j, long j2, MessageReactionEmoji messageReactionEmoji) { super(null); m.checkNotNullParameter(messageReactionEmoji, "emoji"); this.channelId = j; this.messageId = j2; this.emoji = messageReactionEmoji; } public static /* synthetic */ Failure copy$default(Failure failure, long j, long j2, MessageReactionEmoji messageReactionEmoji, int i, Object obj) { if ((i & 1) != 0) { j = failure.channelId; } if ((i & 2) != 0) { j2 = failure.messageId; } if ((i & 4) != 0) { messageReactionEmoji = failure.emoji; } return failure.copy(j, j2, messageReactionEmoji); } public final long component1() { return this.channelId; } public final long component2() { return this.messageId; } public final MessageReactionEmoji component3() { return this.emoji; } public final Failure copy(long j, long j2, MessageReactionEmoji messageReactionEmoji) { m.checkNotNullParameter(messageReactionEmoji, "emoji"); return new Failure(j, j2, messageReactionEmoji); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Failure)) { return false; } Failure failure = (Failure) obj; return this.channelId == failure.channelId && this.messageId == failure.messageId && m.areEqual(this.emoji, failure.emoji); } public final long getChannelId() { return this.channelId; } public final MessageReactionEmoji getEmoji() { return this.emoji; } public final long getMessageId() { return this.messageId; } public int hashCode() { int a = (b.a(this.messageId) + (b.a(this.channelId) * 31)) * 31; MessageReactionEmoji messageReactionEmoji = this.emoji; return a + (messageReactionEmoji != null ? messageReactionEmoji.hashCode() : 0); } public String toString() { StringBuilder L = a.L("Failure(channelId="); L.append(this.channelId); L.append(", messageId="); L.append(this.messageId); L.append(", emoji="); L.append(this.emoji); L.append(")"); return L.toString(); } } /* compiled from: StoreMessageReactions.kt */ public static final class Loading extends EmojiResults { public static final Loading INSTANCE = new Loading(); private Loading() { super(null); } } /* compiled from: StoreMessageReactions.kt */ public static final class Users extends EmojiResults { private final long channelId; private final MessageReactionEmoji emoji; private final long messageId; private final LinkedHashMap users; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Users(LinkedHashMap linkedHashMap, long j, long j2, MessageReactionEmoji messageReactionEmoji) { super(null); m.checkNotNullParameter(linkedHashMap, "users"); m.checkNotNullParameter(messageReactionEmoji, "emoji"); this.users = linkedHashMap; this.channelId = j; this.messageId = j2; this.emoji = messageReactionEmoji; } /* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: com.discord.stores.StoreMessageReactions$EmojiResults$Users */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Users copy$default(Users users, LinkedHashMap linkedHashMap, long j, long j2, MessageReactionEmoji messageReactionEmoji, int i, Object obj) { if ((i & 1) != 0) { linkedHashMap = users.users; } if ((i & 2) != 0) { j = users.channelId; } if ((i & 4) != 0) { j2 = users.messageId; } if ((i & 8) != 0) { messageReactionEmoji = users.emoji; } return users.copy(linkedHashMap, j, j2, messageReactionEmoji); } public final LinkedHashMap component1() { return this.users; } public final long component2() { return this.channelId; } public final long component3() { return this.messageId; } public final MessageReactionEmoji component4() { return this.emoji; } public final Users copy(LinkedHashMap linkedHashMap, long j, long j2, MessageReactionEmoji messageReactionEmoji) { m.checkNotNullParameter(linkedHashMap, "users"); m.checkNotNullParameter(messageReactionEmoji, "emoji"); return new Users(linkedHashMap, j, j2, messageReactionEmoji); } public final Users deepCopy() { return new Users(new LinkedHashMap(this.users), this.channelId, this.messageId, this.emoji); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Users)) { return false; } Users users = (Users) obj; return m.areEqual(this.users, users.users) && this.channelId == users.channelId && this.messageId == users.messageId && m.areEqual(this.emoji, users.emoji); } public final long getChannelId() { return this.channelId; } public final MessageReactionEmoji getEmoji() { return this.emoji; } public final long getMessageId() { return this.messageId; } public final LinkedHashMap getUsers() { return this.users; } public int hashCode() { LinkedHashMap linkedHashMap = this.users; int i = 0; int hashCode = linkedHashMap != null ? linkedHashMap.hashCode() : 0; int a = (b.a(this.messageId) + ((b.a(this.channelId) + (hashCode * 31)) * 31)) * 31; MessageReactionEmoji messageReactionEmoji = this.emoji; if (messageReactionEmoji != null) { i = messageReactionEmoji.hashCode(); } return a + i; } public String toString() { StringBuilder L = a.L("Users(users="); L.append(this.users); L.append(", channelId="); L.append(this.channelId); L.append(", messageId="); L.append(this.messageId); L.append(", emoji="); L.append(this.emoji); L.append(")"); return L.toString(); } } private EmojiResults() { } public /* synthetic */ EmojiResults(DefaultConstructorMarker defaultConstructorMarker) { this(); } } public StoreMessageReactions(Dispatcher dispatcher, StoreUser storeUser, ObservationDeck observationDeck) { m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(storeUser, "userStore"); m.checkNotNullParameter(observationDeck, "observationDeck"); this.dispatcher = dispatcher; this.userStore = storeUser; this.observationDeck = observationDeck; this.reactions = new HashMap(); this.reactionsSnapshot = new HashMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreMessageReactions(Dispatcher dispatcher, StoreUser storeUser, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) { this(dispatcher, storeUser, (i & 4) != 0 ? ObservationDeckProvider.get() : observationDeck); } public static final /* synthetic */ void access$fetchReactions(StoreMessageReactions storeMessageReactions, long j, long j2, MessageReactionEmoji messageReactionEmoji) { storeMessageReactions.fetchReactions(j, j2, messageReactionEmoji); } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreMessageReactions storeMessageReactions) { return storeMessageReactions.dispatcher; } public static final /* synthetic */ Map access$getReactions$p(StoreMessageReactions storeMessageReactions) { return storeMessageReactions.reactions; } public static final /* synthetic */ Map access$getReactionsSnapshot$p(StoreMessageReactions storeMessageReactions) { return storeMessageReactions.reactionsSnapshot; } public static final /* synthetic */ void access$handleLoadReactionUsersFailure(StoreMessageReactions storeMessageReactions, long j, long j2, MessageReactionEmoji messageReactionEmoji) { storeMessageReactions.handleLoadReactionUsersFailure(j, j2, messageReactionEmoji); } public static final /* synthetic */ void access$handleReactionUsers(StoreMessageReactions storeMessageReactions, long j, long j2, MessageReactionEmoji messageReactionEmoji, List list) { storeMessageReactions.handleReactionUsers(j, j2, messageReactionEmoji, list); } public static final /* synthetic */ void access$setReactionsSnapshot$p(StoreMessageReactions storeMessageReactions, Map map) { storeMessageReactions.reactionsSnapshot = map; } @StoreThread private final EmojiResults ensureReactionResults(long j, String str) { Map map = this.reactions.get(Long.valueOf(j)); if (map == null) { map = new HashMap<>(); } EmojiResults emojiResults = map.get(str); if (emojiResults == null) { emojiResults = EmojiResults.Loading.INSTANCE; } map.put(str, emojiResults); this.reactions.put(Long.valueOf(j), map); return emojiResults; } @StoreThread private final void fetchReactions(long j, long j2, MessageReactionEmoji messageReactionEmoji) { EmojiResults ensureReactionResults = ensureReactionResults(j2, messageReactionEmoji.c()); if (!(ensureReactionResults instanceof EmojiResults.Users) || !(!((EmojiResults.Users) ensureReactionResults).getUsers().isEmpty())) { String reactionEmojiRequestParam = getReactionEmojiRequestParam(messageReactionEmoji); Map map = this.reactions.get(Long.valueOf(j2)); if (map != null) { map.put(messageReactionEmoji.c(), EmojiResults.Loading.INSTANCE); } ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().getReactionUsers(j, j2, reactionEmojiRequestParam, 100), false, 1, null), StoreMessageReactions.class, (Context) null, (Function1) null, new StoreMessageReactions$fetchReactions$2(this, j, j2, messageReactionEmoji), (Function0) null, (Function0) null, new StoreMessageReactions$fetchReactions$1(this, j, j2, messageReactionEmoji), 54, (Object) null); } } private final String getReactionEmojiRequestParam(MessageReactionEmoji messageReactionEmoji) { if (messageReactionEmoji.e()) { return messageReactionEmoji.d() + ':' + messageReactionEmoji.b(); } String d = messageReactionEmoji.d(); return d != null ? d : ""; } @StoreThread private final void handleLoadReactionUsersFailure(long j, long j2, MessageReactionEmoji messageReactionEmoji) { ensureReactionResults(j2, messageReactionEmoji.c()); Map map = this.reactions.get(Long.valueOf(j2)); if (map != null) { map.put(messageReactionEmoji.c(), new EmojiResults.Failure(j, j2, messageReactionEmoji)); } markChanged(); } @StoreThread private final void handleReactionUsers(long j, long j2, MessageReactionEmoji messageReactionEmoji, List list) { ensureReactionResults(j2, messageReactionEmoji.c()); LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Object obj : list) { linkedHashMap.put(Long.valueOf(((User) obj).getId()), obj); } Map map = this.reactions.get(Long.valueOf(j2)); if (map != null) { map.put(messageReactionEmoji.c(), new EmojiResults.Users(linkedHashMap, j, j2, messageReactionEmoji)); } markChanged(); } public final void deleteEmoji(long j, long j2, MessageReactionEmoji messageReactionEmoji, long j3) { m.checkNotNullParameter(messageReactionEmoji, "emoji"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().removeReaction(j, j2, getReactionEmojiRequestParam(messageReactionEmoji), j3), false, 1, null), StoreMessageReactions.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, StoreMessageReactions$deleteEmoji$1.INSTANCE, 62, (Object) null); } public final void forceRetryFetchReactions(long j, long j2, MessageReactionEmoji messageReactionEmoji) { m.checkNotNullParameter(messageReactionEmoji, "emoji"); this.dispatcher.schedule(new StoreMessageReactions$forceRetryFetchReactions$1(this, j2, messageReactionEmoji, j)); } @StoreThread public final void handleConnectionOpen() { if (!this.reactions.isEmpty()) { this.reactions.clear(); markChanged(); } } @StoreThread public final void handleReactionAdd(MessageReactionUpdate messageReactionUpdate) { m.checkNotNullParameter(messageReactionUpdate, "update"); User user = this.userStore.getUsersInternal$app_productionBetaRelease().get(Long.valueOf(messageReactionUpdate.d())); if (user != null) { EmojiResults ensureReactionResults = ensureReactionResults(messageReactionUpdate.c(), messageReactionUpdate.b().c()); if (!(ensureReactionResults instanceof EmojiResults.Users)) { ensureReactionResults = null; } EmojiResults.Users users = (EmojiResults.Users) ensureReactionResults; if (users != null) { users.getUsers().put(Long.valueOf(messageReactionUpdate.d()), user); markChanged(); } } } @StoreThread public final void handleReactionRemove(MessageReactionUpdate messageReactionUpdate) { m.checkNotNullParameter(messageReactionUpdate, "update"); EmojiResults ensureReactionResults = ensureReactionResults(messageReactionUpdate.c(), messageReactionUpdate.b().c()); if (!(ensureReactionResults instanceof EmojiResults.Users)) { ensureReactionResults = null; } EmojiResults.Users users = (EmojiResults.Users) ensureReactionResults; if (users != null) { users.getUsers().remove(Long.valueOf(messageReactionUpdate.d())); markChanged(); } } @StoreThread public final void handleReactionRemoveAll(MessageReactionUpdate messageReactionUpdate) { m.checkNotNullParameter(messageReactionUpdate, "update"); this.reactions.remove(Long.valueOf(messageReactionUpdate.c())); markChanged(); } @StoreThread public final void handleReactionRemoveEmoji(MessageReactionUpdate messageReactionUpdate) { m.checkNotNullParameter(messageReactionUpdate, "update"); long c2 = messageReactionUpdate.c(); String c3 = messageReactionUpdate.b().c(); ensureReactionResults(c2, c3); Map map = this.reactions.get(Long.valueOf(c2)); if (map != null) { map.remove(c3); } markChanged(); } public final Observable observeMessageReactions(long j, long j2, MessageReactionEmoji messageReactionEmoji) { m.checkNotNullParameter(messageReactionEmoji, "emoji"); this.dispatcher.schedule(new StoreMessageReactions$observeMessageReactions$1(this, j, j2, messageReactionEmoji)); Observable r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreMessageReactions$observeMessageReactions$2(this, j2, messageReactionEmoji), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()"); return r; } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { super.snapshotData(); HashMap hashMap = new HashMap(this.reactions); for (Map.Entry> entry : this.reactions.entrySet()) { long longValue = entry.getKey().longValue(); HashMap hashMap2 = new HashMap(entry.getValue()); hashMap.put(Long.valueOf(longValue), hashMap2); for (Map.Entry entry2 : hashMap2.entrySet()) { String str = (String) entry2.getKey(); Object obj = (EmojiResults) entry2.getValue(); if (obj instanceof EmojiResults.Users) { obj = ((EmojiResults.Users) obj).deepCopy(); } hashMap2.put(str, obj); } } this.reactionsSnapshot = hashMap; } }