2021-06-27 20:44:35 +00:00
|
|
|
package com.discord.stores;
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
import com.discord.api.user.User;
|
2021-06-27 20:44:35 +00:00
|
|
|
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 {
|
2021-07-03 23:36:06 +00:00
|
|
|
public static final Companion Companion = new Companion(null);
|
|
|
|
private static final ModelUserProfile EMPTY_PROFILE = new ModelUserProfile();
|
2021-06-27 20:44:35 +00:00
|
|
|
private final Dispatcher dispatcher;
|
|
|
|
private final ObservationDeck observationDeck;
|
|
|
|
private final HashMap<Long, ModelUserProfile> profiles;
|
|
|
|
private final HashSet<Long> profilesLoading;
|
|
|
|
private Map<Long, ? extends ModelUserProfile> profilesSnapshot;
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
/* 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public static final /* synthetic */ ModelUserProfile access$getEMPTY_PROFILE$cp() {
|
|
|
|
return EMPTY_PROFILE;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public static final /* synthetic */ void access$handleUser(StoreUserProfile storeUserProfile, User user) {
|
|
|
|
storeUserProfile.handleUser(user);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public static final /* synthetic */ void access$handleUserProfile(StoreUserProfile storeUserProfile, ModelUserProfile modelUserProfile, long j) {
|
|
|
|
storeUserProfile.handleUserProfile(modelUserProfile, j);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@StoreThread
|
|
|
|
private final void handleFailure(long j) {
|
|
|
|
this.profilesLoading.remove(Long.valueOf(j));
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
@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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@StoreThread
|
|
|
|
private final void handleUserProfile(ModelUserProfile modelUserProfile, long j) {
|
|
|
|
this.profilesLoading.remove(Long.valueOf(j));
|
|
|
|
this.profiles.put(Long.valueOf(j), modelUserProfile);
|
|
|
|
markChanged();
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final void fetchProfile(long j) {
|
|
|
|
this.dispatcher.schedule(new StoreUserProfile$fetchProfile$1(this, j));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final ModelUserProfile getUserProfile(long j) {
|
|
|
|
ModelUserProfile modelUserProfile = (ModelUserProfile) this.profilesSnapshot.get(Long.valueOf(j));
|
|
|
|
return modelUserProfile != null ? modelUserProfile : EMPTY_PROFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<ModelUserProfile> observeUserProfile(long j) {
|
|
|
|
fetchProfile(j);
|
|
|
|
Observable<ModelUserProfile> 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;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
|
|
@StoreThread
|
|
|
|
public void snapshotData() {
|
|
|
|
super.snapshotData();
|
|
|
|
this.profilesSnapshot = new HashMap(this.profiles);
|
|
|
|
}
|
2021-07-03 23:36:06 +00:00
|
|
|
|
|
|
|
public final void updateUser(User user) {
|
|
|
|
m.checkNotNullParameter(user, "user");
|
|
|
|
this.dispatcher.schedule(new StoreUserProfile$updateUser$1(this, user));
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|