227 lines
8.4 KiB
Java
227 lines
8.4 KiB
Java
package com.discord.stores;
|
|
|
|
import com.discord.api.activity.Activity;
|
|
import com.discord.api.activity.ActivityParty;
|
|
import com.discord.api.guild.Guild;
|
|
import com.discord.api.presence.ClientStatus;
|
|
import com.discord.api.presence.Presence;
|
|
import com.discord.api.user.User;
|
|
import com.discord.models.domain.ModelPayload;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import rx.Observable;
|
|
/* compiled from: StoreGameParty.kt */
|
|
public final class StoreGameParty extends StoreV2 {
|
|
private final ObservationDeck observationDeck;
|
|
private final HashMap<String, HashSet<Long>> parties = new HashMap<>();
|
|
private HashMap<String, HashSet<Long>> partiesSnapshot = new HashMap<>();
|
|
private final StoreUser storeUser;
|
|
private final StoreUserPresence storeUserPresence;
|
|
private final HashMap<Long, HashMap<Long, String>> userParties = new HashMap<>();
|
|
|
|
public StoreGameParty(ObservationDeck observationDeck, StoreUserPresence storeUserPresence, StoreUser storeUser) {
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
m.checkNotNullParameter(storeUserPresence, "storeUserPresence");
|
|
m.checkNotNullParameter(storeUser, "storeUser");
|
|
this.observationDeck = observationDeck;
|
|
this.storeUserPresence = storeUserPresence;
|
|
this.storeUser = storeUser;
|
|
}
|
|
|
|
public static final /* synthetic */ HashMap access$getPartiesSnapshot$p(StoreGameParty storeGameParty) {
|
|
return storeGameParty.partiesSnapshot;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setPartiesSnapshot$p(StoreGameParty storeGameParty, HashMap hashMap) {
|
|
storeGameParty.partiesSnapshot = hashMap;
|
|
}
|
|
|
|
@StoreThread
|
|
private final void addUserToParty(long j, long j2, String str) {
|
|
if (str != null) {
|
|
if (j2 > 0) {
|
|
HashMap<Long, HashMap<Long, String>> hashMap = this.userParties;
|
|
Long valueOf = Long.valueOf(j);
|
|
HashMap<Long, String> hashMap2 = hashMap.get(valueOf);
|
|
if (hashMap2 == null) {
|
|
hashMap2 = new HashMap<>();
|
|
hashMap.put(valueOf, hashMap2);
|
|
}
|
|
hashMap2.put(Long.valueOf(j2), str);
|
|
}
|
|
HashSet<Long> hashSet = this.parties.get(str);
|
|
HashSet<Long> hashSet2 = hashSet != null ? new HashSet<>(hashSet) : new HashSet<>();
|
|
hashSet2.add(Long.valueOf(j));
|
|
this.parties.put(str, hashSet2);
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void handlePresenceUpdate$default(StoreGameParty storeGameParty, Presence presence, long j, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
Long d = presence.d();
|
|
j = d != null ? d.longValue() : 0;
|
|
}
|
|
storeGameParty.handlePresenceUpdate(presence, j);
|
|
}
|
|
|
|
@StoreThread
|
|
private final void handlePresences(List<Presence> list) {
|
|
for (Presence presence : list) {
|
|
Long d = presence.d();
|
|
updateParty(presence, d != null ? d.longValue() : 0);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
private final void removeUserFromParty(long j, long j2) {
|
|
String remove;
|
|
HashMap<Long, String> hashMap = this.userParties.get(Long.valueOf(j));
|
|
if (hashMap != null && (remove = hashMap.remove(Long.valueOf(j2))) != null) {
|
|
m.checkNotNullExpressionValue(remove, "userParties[userId]?.remove(guildId) ?: return");
|
|
HashSet<Long> hashSet = this.parties.get(remove);
|
|
if (hashSet != null) {
|
|
if (hashSet.size() != 1) {
|
|
HashMap<String, HashSet<Long>> hashMap2 = this.parties;
|
|
HashSet<Long> hashSet2 = new HashSet<>(hashSet);
|
|
hashSet2.remove(Long.valueOf(j));
|
|
hashMap2.put(remove, hashSet2);
|
|
} else {
|
|
this.parties.remove(remove);
|
|
}
|
|
}
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
private final void updateParty(Presence presence, long j) {
|
|
List<Activity> list;
|
|
boolean z2;
|
|
Object obj;
|
|
ActivityParty i;
|
|
boolean z3;
|
|
User f = presence.f();
|
|
if (f != null) {
|
|
HashMap<Long, String> hashMap = this.userParties.get(Long.valueOf(f.i()));
|
|
String str = null;
|
|
String str2 = hashMap != null ? hashMap.get(Long.valueOf(j)) : null;
|
|
Map<Long, com.discord.models.presence.Presence> presences = this.storeUserPresence.m14getPresences();
|
|
User f2 = presence.f();
|
|
com.discord.models.presence.Presence presence2 = presences.get(f2 != null ? Long.valueOf(f2.i()) : null);
|
|
if (presence2 == null || (list = presence2.getActivities()) == null) {
|
|
list = n.emptyList();
|
|
}
|
|
Iterator<T> it = list.iterator();
|
|
while (true) {
|
|
z2 = false;
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
ActivityParty i2 = ((Activity) obj).i();
|
|
if ((i2 != null ? i2.a() : null) != null) {
|
|
z3 = true;
|
|
continue;
|
|
} else {
|
|
z3 = false;
|
|
continue;
|
|
}
|
|
if (z3) {
|
|
break;
|
|
}
|
|
}
|
|
Activity activity = (Activity) obj;
|
|
if (!(activity == null || (i = activity.i()) == null)) {
|
|
str = i.a();
|
|
}
|
|
if (!(str == null || presence.e() == ClientStatus.OFFLINE)) {
|
|
z2 = true;
|
|
}
|
|
if (z2) {
|
|
if (!m.areEqual(str2, str)) {
|
|
removeUserFromParty(f.i(), j);
|
|
}
|
|
addUserToParty(f.i(), j, str);
|
|
return;
|
|
}
|
|
removeUserFromParty(f.i(), j);
|
|
}
|
|
}
|
|
|
|
public final ObservationDeck getObservationDeck() {
|
|
return this.observationDeck;
|
|
}
|
|
|
|
public final StoreUser getStoreUser() {
|
|
return this.storeUser;
|
|
}
|
|
|
|
public final StoreUserPresence getStoreUserPresence() {
|
|
return this.storeUserPresence;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionOpen(ModelPayload modelPayload) {
|
|
m.checkNotNullParameter(modelPayload, "payload");
|
|
List<Presence> presences = modelPayload.getPresences();
|
|
if (presences != null) {
|
|
handlePresences(presences);
|
|
}
|
|
List<Guild> guilds = modelPayload.getGuilds();
|
|
m.checkNotNullExpressionValue(guilds, "payload.guilds");
|
|
for (Guild guild : guilds) {
|
|
handleGuildCreateOrSync(guild);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildCreateOrSync(Guild guild) {
|
|
m.checkNotNullParameter(guild, "guild");
|
|
List<Presence> A = guild.A();
|
|
if (A != null) {
|
|
handlePresences(A);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handlePresenceReplace(List<Presence> list) {
|
|
m.checkNotNullParameter(list, "presences");
|
|
handlePresences(list);
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handlePresenceUpdate(Presence presence) {
|
|
handlePresenceUpdate$default(this, presence, 0, 2, null);
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handlePresenceUpdate(Presence presence, long j) {
|
|
m.checkNotNullParameter(presence, "presence");
|
|
updateParty(presence, j);
|
|
}
|
|
|
|
public final Observable<Map<Long, com.discord.models.user.User>> observeUsersForPartyId(String str) {
|
|
Observable<Map<Long, com.discord.models.user.User>> s2 = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this, StoreUser.Companion.getUsersUpdate()}, false, null, null, new StoreGameParty$observeUsersForPartyId$1(this, str), 14, null).s();
|
|
m.checkNotNullExpressionValue(s2, "observationDeck.connectR… .distinctUntilChanged()");
|
|
return s2;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
@StoreThread
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
this.partiesSnapshot = new HashMap<>();
|
|
for (Map.Entry<String, HashSet<Long>> entry : this.parties.entrySet()) {
|
|
this.partiesSnapshot.put(entry.getKey(), new HashSet<>(entry.getValue()));
|
|
}
|
|
}
|
|
}
|