discord-jadx/app/src/main/java/com/discord/stores/StoreUserRelationships.java

253 lines
11 KiB
Java

package com.discord.stores;
import c.d.b.a.a;
import com.discord.models.domain.ModelPayload;
import com.discord.models.domain.ModelUserRelationship;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.persister.Persister;
import d0.t.h0;
import d0.z.d.m;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreUserRelationships.kt */
public final class StoreUserRelationships extends StoreV2 {
private final ObservationDeck observationDeck;
private final Persister<Map<Long, Integer>> relationshipsCache;
private UserRelationshipsState relationshipsState;
private UserRelationshipsState relationshipsStateSnapshot;
/* compiled from: StoreUserRelationships.kt */
public static abstract class UserRelationshipsState {
/* compiled from: StoreUserRelationships.kt */
public static final class Loaded extends UserRelationshipsState {
private final Map<Long, Integer> relationships;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded(Map<Long, Integer> map) {
super(null);
m.checkNotNullParameter(map, "relationships");
this.relationships = map;
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreUserRelationships$UserRelationshipsState$Loaded */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Loaded copy$default(Loaded loaded, Map map, int i, Object obj) {
if ((i & 1) != 0) {
map = loaded.relationships;
}
return loaded.copy(map);
}
public final Map<Long, Integer> component1() {
return this.relationships;
}
public final Loaded copy(Map<Long, Integer> map) {
m.checkNotNullParameter(map, "relationships");
return new Loaded(map);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Loaded) && m.areEqual(this.relationships, ((Loaded) obj).relationships);
}
return true;
}
public final Map<Long, Integer> getRelationships() {
return this.relationships;
}
public int hashCode() {
Map<Long, Integer> map = this.relationships;
if (map != null) {
return map.hashCode();
}
return 0;
}
public String toString() {
return a.F(a.L("Loaded(relationships="), this.relationships, ")");
}
}
/* compiled from: StoreUserRelationships.kt */
public static final class Unloaded extends UserRelationshipsState {
public static final Unloaded INSTANCE = new Unloaded();
private Unloaded() {
super(null);
}
}
private UserRelationshipsState() {
}
public /* synthetic */ UserRelationshipsState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public StoreUserRelationships() {
this(null, 1, null);
}
public StoreUserRelationships(ObservationDeck observationDeck) {
m.checkNotNullParameter(observationDeck, "observationDeck");
this.observationDeck = observationDeck;
UserRelationshipsState.Unloaded unloaded = UserRelationshipsState.Unloaded.INSTANCE;
this.relationshipsState = unloaded;
this.relationshipsStateSnapshot = unloaded;
this.relationshipsCache = new Persister<>("STORE_USER_RELATIONSHIPS_V9", StoreUserRelationshipsKt.access$getUNLOADED_RELATIONSHIPS_SENTINEL$p());
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreUserRelationships(ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? ObservationDeckProvider.get() : observationDeck);
}
public static final /* synthetic */ UserRelationshipsState access$getRelationshipsStateSnapshot$p(StoreUserRelationships storeUserRelationships) {
return storeUserRelationships.relationshipsStateSnapshot;
}
public static final /* synthetic */ void access$setRelationshipsStateSnapshot$p(StoreUserRelationships storeUserRelationships, UserRelationshipsState userRelationshipsState) {
storeUserRelationships.relationshipsStateSnapshot = userRelationshipsState;
}
@StoreThread
private final UserRelationshipsState.Loaded ensureRelationshipLoaded() {
UserRelationshipsState userRelationshipsState = this.relationshipsState;
if (!(userRelationshipsState instanceof UserRelationshipsState.Loaded)) {
userRelationshipsState = null;
}
UserRelationshipsState.Loaded loaded = (UserRelationshipsState.Loaded) userRelationshipsState;
if (loaded == null) {
loaded = new UserRelationshipsState.Loaded(h0.emptyMap());
}
this.relationshipsState = loaded;
return loaded;
}
public final Map<Long, Integer> getRelationships() {
Map<Long, Integer> relationships;
UserRelationshipsState userRelationshipsState = this.relationshipsStateSnapshot;
if (!(userRelationshipsState instanceof UserRelationshipsState.Loaded)) {
userRelationshipsState = null;
}
UserRelationshipsState.Loaded loaded = (UserRelationshipsState.Loaded) userRelationshipsState;
return (loaded == null || (relationships = loaded.getRelationships()) == null) ? h0.emptyMap() : relationships;
}
public final UserRelationshipsState getRelationshipsState() {
return this.relationshipsStateSnapshot;
}
@StoreThread
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
List<ModelUserRelationship> relationships = modelPayload.getRelationships();
m.checkNotNullExpressionValue(relationships, "payload\n .relationships");
LinkedHashMap linkedHashMap = new LinkedHashMap(a.I(relationships, 10, 16));
for (ModelUserRelationship modelUserRelationship : relationships) {
m.checkNotNullExpressionValue(modelUserRelationship, "it");
Long valueOf = Long.valueOf(modelUserRelationship.getId());
m.checkNotNullExpressionValue(modelUserRelationship, "it");
linkedHashMap.put(valueOf, Integer.valueOf(modelUserRelationship.getType()));
}
this.relationshipsState = new UserRelationshipsState.Loaded(linkedHashMap);
markChanged();
}
@StoreThread
public final void handlePreLogout() {
this.relationshipsState = UserRelationshipsState.Unloaded.INSTANCE;
markChanged();
}
@StoreThread
public final void handleRelationshipAdd(ModelUserRelationship modelUserRelationship) {
m.checkNotNullParameter(modelUserRelationship, "relationship");
Map mutableMap = h0.toMutableMap(ensureRelationshipLoaded().getRelationships());
Integer num = (Integer) mutableMap.get(Long.valueOf(modelUserRelationship.getId()));
int type = modelUserRelationship.getType();
if (num == null || num.intValue() != type) {
mutableMap.put(Long.valueOf(modelUserRelationship.getId()), Integer.valueOf(modelUserRelationship.getType()));
this.relationshipsState = new UserRelationshipsState.Loaded(mutableMap);
markChanged();
}
}
@StoreThread
public final void handleRelationshipRemove(ModelUserRelationship modelUserRelationship) {
m.checkNotNullParameter(modelUserRelationship, "relationship");
Map mutableMap = h0.toMutableMap(ensureRelationshipLoaded().getRelationships());
if (mutableMap.remove(Long.valueOf(modelUserRelationship.getId())) != null) {
this.relationshipsState = new UserRelationshipsState.Loaded(mutableMap);
markChanged();
}
}
public final void init() {
Map<Long, Integer> map = this.relationshipsCache.get();
if (!m.areEqual(map, StoreUserRelationshipsKt.access$getUNLOADED_RELATIONSHIPS_SENTINEL$p())) {
this.relationshipsState = new UserRelationshipsState.Loaded(map);
markChanged();
}
}
public final Observable<Map<Long, Integer>> observe() {
Observable<Map<Long, Integer>> s2 = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserRelationships$observe$1(this), 14, null).s();
m.checkNotNullExpressionValue(s2, "observationDeck.connectR… }.distinctUntilChanged()");
return s2;
}
public final Observable<Integer> observe(long j) {
Observable<R> G = observe().G(new StoreUserRelationships$observe$3(j));
m.checkNotNullExpressionValue(G, "observe()\n .map…> relationships[userId] }");
return G;
}
public final Observable<Map<Long, Integer>> observe(Collection<Long> collection) {
m.checkNotNullParameter(collection, "userIds");
Observable<Map<Long, Integer>> s2 = observe().G(new StoreUserRelationships$observe$2(collection)).s();
m.checkNotNullExpressionValue(s2, "observe()\n .map… .distinctUntilChanged()");
return s2;
}
public final Observable<Map<Long, Integer>> observeForType(int i) {
Observable<Map<Long, Integer>> s2 = observe().G(new StoreUserRelationships$observeForType$1(i)).s();
m.checkNotNullExpressionValue(s2, "observe()\n .map… .distinctUntilChanged()");
return s2;
}
public final Observable<UserRelationshipsState> observeUserRelationshipsState() {
Observable<UserRelationshipsState> s2 = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserRelationships$observeUserRelationshipsState$1(this), 14, null).s();
m.checkNotNullExpressionValue(s2, "observationDeck.connectR… }.distinctUntilChanged()");
return s2;
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData() {
UserRelationshipsState userRelationshipsState;
super.snapshotData();
UserRelationshipsState userRelationshipsState2 = this.relationshipsState;
if (userRelationshipsState2 instanceof UserRelationshipsState.Loaded) {
HashMap hashMap = new HashMap(((UserRelationshipsState.Loaded) userRelationshipsState2).getRelationships());
Persister.set$default(this.relationshipsCache, hashMap, false, 2, null);
userRelationshipsState = new UserRelationshipsState.Loaded(hashMap);
} else {
Persister.clear$default(this.relationshipsCache, false, 1, null);
userRelationshipsState = UserRelationshipsState.Unloaded.INSTANCE;
}
this.relationshipsStateSnapshot = userRelationshipsState;
}
}