package com.discord.stores; import com.discord.api.user.User; import com.discord.models.domain.ModelUserProfile; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import d0.t.h0; import d0.z.d.m; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreUserProfile.kt */ public final class StoreUserProfile extends StoreV2 { public static final Companion Companion = new Companion(null); private static final ModelUserProfile EMPTY_PROFILE = new ModelUserProfile(); private final Dispatcher dispatcher; private final ObservationDeck observationDeck; private final HashMap profiles; private final HashSet profilesLoading; private Map profilesSnapshot; /* compiled from: StoreUserProfile.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final ModelUserProfile getEMPTY_PROFILE() { return StoreUserProfile.access$getEMPTY_PROFILE$cp(); } } public StoreUserProfile(Dispatcher dispatcher, ObservationDeck observationDeck) { m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(observationDeck, "observationDeck"); this.dispatcher = dispatcher; this.observationDeck = observationDeck; this.profilesLoading = new HashSet<>(); this.profiles = new HashMap<>(); this.profilesSnapshot = h0.emptyMap(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreUserProfile(Dispatcher dispatcher, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) { this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck); } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreUserProfile storeUserProfile) { return storeUserProfile.dispatcher; } public static final /* synthetic */ ModelUserProfile access$getEMPTY_PROFILE$cp() { return EMPTY_PROFILE; } public static final /* synthetic */ HashSet access$getProfilesLoading$p(StoreUserProfile storeUserProfile) { return storeUserProfile.profilesLoading; } public static final /* synthetic */ void access$handleFailure(StoreUserProfile storeUserProfile, long j) { storeUserProfile.handleFailure(j); } public static final /* synthetic */ void access$handleUser(StoreUserProfile storeUserProfile, User user) { storeUserProfile.handleUser(user); } public static final /* synthetic */ void access$handleUserProfile(StoreUserProfile storeUserProfile, ModelUserProfile modelUserProfile, long j) { storeUserProfile.handleUserProfile(modelUserProfile, j); } @StoreThread private final void handleFailure(long j) { this.profilesLoading.remove(Long.valueOf(j)); } @StoreThread private final void handleUser(User user) { ModelUserProfile modelUserProfile = this.profiles.get(Long.valueOf(user.i())); if (modelUserProfile != null) { m.checkNotNullExpressionValue(modelUserProfile, "profiles[user.id] ?: return"); this.profiles.put(Long.valueOf(user.i()), new ModelUserProfile(modelUserProfile.getConnectedAccounts(), modelUserProfile.getMutualGuilds(), user, modelUserProfile.getPremiumSince(), modelUserProfile.getPremiumGuildSince())); markChanged(); } } @StoreThread private final void handleUserProfile(ModelUserProfile modelUserProfile, long j) { this.profilesLoading.remove(Long.valueOf(j)); this.profiles.put(Long.valueOf(j), modelUserProfile); markChanged(); } public final void fetchProfile(long j) { this.dispatcher.schedule(new StoreUserProfile$fetchProfile$1(this, j)); } public final ModelUserProfile getUserProfile(long j) { ModelUserProfile modelUserProfile = (ModelUserProfile) this.profilesSnapshot.get(Long.valueOf(j)); return modelUserProfile != null ? modelUserProfile : EMPTY_PROFILE; } public final Observable observeUserProfile(long j) { fetchProfile(j); Observable r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserProfile$observeUserProfile$1(this, j), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()"); return r; } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { super.snapshotData(); this.profilesSnapshot = new HashMap(this.profiles); } public final void updateUser(User user) { m.checkNotNullParameter(user, "user"); this.dispatcher.schedule(new StoreUserProfile$updateUser$1(this, user)); } }