2021-08-09 22:50:52 +00:00
|
|
|
package com.discord.stores;
|
|
|
|
|
|
|
|
import c.d.b.a.a;
|
2021-10-18 07:12:10 +00:00
|
|
|
import c0.d0.f;
|
|
|
|
import c0.t.g0;
|
|
|
|
import c0.t.h0;
|
|
|
|
import c0.t.o;
|
|
|
|
import c0.z.d.m;
|
2021-08-09 22:50:52 +00:00
|
|
|
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 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() {
|
2021-10-11 07:48:45 +00:00
|
|
|
return a.J(a.O("Loaded(relationships="), this.relationships, ")");
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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(f.coerceAtLeast(g0.mapCapacity(o.collectionSizeOrDefault(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() {
|
2021-10-18 07:12:10 +00:00
|
|
|
Observable<Map<Long, Integer>> q = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserRelationships$observe$1(this), 14, null).q();
|
|
|
|
m.checkNotNullExpressionValue(q, "observationDeck.connectR… }.distinctUntilChanged()");
|
|
|
|
return q;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<Integer> observe(long j) {
|
2021-10-22 07:30:30 +00:00
|
|
|
Observable<R> F = observe().F(new StoreUserRelationships$observe$3(j));
|
|
|
|
m.checkNotNullExpressionValue(F, "observe()\n .map…> relationships[userId] }");
|
|
|
|
return F;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<Map<Long, Integer>> observe(Collection<Long> collection) {
|
|
|
|
m.checkNotNullParameter(collection, "userIds");
|
2021-10-22 07:30:30 +00:00
|
|
|
Observable<Map<Long, Integer>> q = observe().F(new StoreUserRelationships$observe$2(collection)).q();
|
2021-10-18 07:12:10 +00:00
|
|
|
m.checkNotNullExpressionValue(q, "observe()\n .map… .distinctUntilChanged()");
|
|
|
|
return q;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<Map<Long, Integer>> observeForType(int i) {
|
2021-10-22 07:30:30 +00:00
|
|
|
Observable<Map<Long, Integer>> q = observe().F(new StoreUserRelationships$observeForType$1(i)).q();
|
2021-10-18 07:12:10 +00:00
|
|
|
m.checkNotNullExpressionValue(q, "observe()\n .map… .distinctUntilChanged()");
|
|
|
|
return q;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<UserRelationshipsState> observeUserRelationshipsState() {
|
2021-10-18 07:12:10 +00:00
|
|
|
Observable<UserRelationshipsState> q = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserRelationships$observeUserRelationshipsState$1(this), 14, null).q();
|
|
|
|
m.checkNotNullExpressionValue(q, "observationDeck.connectR… }.distinctUntilChanged()");
|
|
|
|
return q;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
}
|