293 lines
13 KiB
Java
293 lines
13 KiB
Java
package com.discord.stores;
|
|
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEvent;
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEventUserUpdate;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import d0.t.h0;
|
|
import d0.t.n;
|
|
import d0.t.o;
|
|
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: StoreGuildScheduledEvents.kt */
|
|
public final class StoreGuildScheduledEvents extends StoreV2 {
|
|
private final Dispatcher dispatcher;
|
|
private final HashMap<Long, List<GuildScheduledEvent>> guildScheduledEvents = new HashMap<>();
|
|
private Map<Long, ? extends List<GuildScheduledEvent>> guildScheduledEventsSnapshot = h0.emptyMap();
|
|
private final ObservationDeck observationDeck;
|
|
private final StorePermissions permissionsStore;
|
|
private final HashSet<Long> rsvpsAwaitingNetwork = new HashSet<>();
|
|
private HashSet<Long> rsvpsAwaitingSnapshot = new HashSet<>();
|
|
private final HashMap<Long, GuildScheduledEvent> userGuildScheduledEvents = new HashMap<>();
|
|
private Map<Long, GuildScheduledEvent> userGuildScheduledEventsSnapshot = h0.emptyMap();
|
|
|
|
public StoreGuildScheduledEvents(Dispatcher dispatcher, ObservationDeck observationDeck, StorePermissions storePermissions) {
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
this.dispatcher = dispatcher;
|
|
this.observationDeck = observationDeck;
|
|
this.permissionsStore = storePermissions;
|
|
}
|
|
|
|
public static final /* synthetic */ GuildScheduledEvent access$findEventFromStore(StoreGuildScheduledEvents storeGuildScheduledEvents, GuildScheduledEvent guildScheduledEvent) {
|
|
return storeGuildScheduledEvents.findEventFromStore(guildScheduledEvent);
|
|
}
|
|
|
|
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.dispatcher;
|
|
}
|
|
|
|
public static final /* synthetic */ HashMap access$getGuildScheduledEvents$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.guildScheduledEvents;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getGuildScheduledEventsSnapshot$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.guildScheduledEventsSnapshot;
|
|
}
|
|
|
|
public static final /* synthetic */ ObservationDeck access$getObservationDeck$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.observationDeck;
|
|
}
|
|
|
|
public static final /* synthetic */ StorePermissions access$getPermissionsStore$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.permissionsStore;
|
|
}
|
|
|
|
public static final /* synthetic */ HashSet access$getRsvpsAwaitingNetwork$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.rsvpsAwaitingNetwork;
|
|
}
|
|
|
|
public static final /* synthetic */ HashMap access$getUserGuildScheduledEvents$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.userGuildScheduledEvents;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getUserGuildScheduledEventsSnapshot$p(StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
return storeGuildScheduledEvents.userGuildScheduledEventsSnapshot;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$processRsvpCreate(StoreGuildScheduledEvents storeGuildScheduledEvents, GuildScheduledEvent guildScheduledEvent) {
|
|
storeGuildScheduledEvents.processRsvpCreate(guildScheduledEvent);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$processRsvpDelete(StoreGuildScheduledEvents storeGuildScheduledEvents, GuildScheduledEvent guildScheduledEvent) {
|
|
storeGuildScheduledEvents.processRsvpDelete(guildScheduledEvent);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setGuildScheduledEventsSnapshot$p(StoreGuildScheduledEvents storeGuildScheduledEvents, Map map) {
|
|
storeGuildScheduledEvents.guildScheduledEventsSnapshot = map;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setUserGuildScheduledEventsSnapshot$p(StoreGuildScheduledEvents storeGuildScheduledEvents, Map map) {
|
|
storeGuildScheduledEvents.userGuildScheduledEventsSnapshot = map;
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:15:0x003b, code lost:
|
|
if (r3 != null) goto L_0x006a;
|
|
*/
|
|
private final GuildScheduledEvent findEventFromStore(long j, Long l) {
|
|
GuildScheduledEvent guildScheduledEvent;
|
|
boolean z2;
|
|
Object obj;
|
|
boolean z3;
|
|
Object obj2 = null;
|
|
if (l != null) {
|
|
List list = (List) this.guildScheduledEventsSnapshot.get(Long.valueOf(l.longValue()));
|
|
if (list != null) {
|
|
Iterator it = list.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
if (j == ((GuildScheduledEvent) obj).e()) {
|
|
z3 = true;
|
|
continue;
|
|
} else {
|
|
z3 = false;
|
|
continue;
|
|
}
|
|
if (z3) {
|
|
break;
|
|
}
|
|
}
|
|
guildScheduledEvent = (GuildScheduledEvent) obj;
|
|
} else {
|
|
guildScheduledEvent = null;
|
|
}
|
|
}
|
|
Iterator it2 = o.flatten(this.guildScheduledEventsSnapshot.values()).iterator();
|
|
while (true) {
|
|
if (!it2.hasNext()) {
|
|
break;
|
|
}
|
|
Object next = it2.next();
|
|
if (j == ((GuildScheduledEvent) next).e()) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
obj2 = next;
|
|
break;
|
|
}
|
|
}
|
|
guildScheduledEvent = (GuildScheduledEvent) obj2;
|
|
return guildScheduledEvent != null ? guildScheduledEvent : this.userGuildScheduledEvents.get(Long.valueOf(j));
|
|
}
|
|
|
|
private final GuildScheduledEvent findEventFromStore(GuildScheduledEvent guildScheduledEvent) {
|
|
GuildScheduledEvent findEventFromStore = findEventFromStore(guildScheduledEvent.e(), Long.valueOf(guildScheduledEvent.d()));
|
|
return findEventFromStore != null ? findEventFromStore : guildScheduledEvent;
|
|
}
|
|
|
|
public static /* synthetic */ GuildScheduledEvent findEventFromStore$default(StoreGuildScheduledEvents storeGuildScheduledEvents, long j, Long l, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
l = null;
|
|
}
|
|
return storeGuildScheduledEvents.findEventFromStore(j, l);
|
|
}
|
|
|
|
public static /* synthetic */ Observable observeGuildScheduledEvents$default(StoreGuildScheduledEvents storeGuildScheduledEvents, long j, boolean z2, boolean z3, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
z2 = true;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z3 = true;
|
|
}
|
|
return storeGuildScheduledEvents.observeGuildScheduledEvents(j, z2, z3);
|
|
}
|
|
|
|
@StoreThread
|
|
private final void processRsvpCreate(GuildScheduledEvent guildScheduledEvent) {
|
|
long e = guildScheduledEvent.e();
|
|
if (!this.userGuildScheduledEvents.containsKey(Long.valueOf(e))) {
|
|
this.rsvpsAwaitingSnapshot.add(Long.valueOf(e));
|
|
Integer i = guildScheduledEvent.i();
|
|
GuildScheduledEvent a = GuildScheduledEvent.a(guildScheduledEvent, 0, 0, 0, null, null, null, null, null, null, null, null, null, null, null, i != null ? Integer.valueOf(i.intValue() + 1) : null, 16383);
|
|
this.userGuildScheduledEvents.put(Long.valueOf(e), a);
|
|
List<GuildScheduledEvent> list = this.guildScheduledEvents.get(Long.valueOf(a.d()));
|
|
if (list != null) {
|
|
m.checkNotNullExpressionValue(list, "eventList");
|
|
Iterator<GuildScheduledEvent> it = list.iterator();
|
|
int i2 = 0;
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
i2 = -1;
|
|
break;
|
|
}
|
|
if (it.next().e() == e) {
|
|
break;
|
|
}
|
|
i2++;
|
|
}
|
|
if (i2 != -1) {
|
|
list.set(i2, a);
|
|
} else {
|
|
list.add(a);
|
|
}
|
|
} else {
|
|
this.guildScheduledEvents.put(Long.valueOf(guildScheduledEvent.d()), n.mutableListOf(a));
|
|
}
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
private final void processRsvpDelete(GuildScheduledEvent guildScheduledEvent) {
|
|
long e = guildScheduledEvent.e();
|
|
if (this.userGuildScheduledEvents.containsKey(Long.valueOf(e))) {
|
|
this.rsvpsAwaitingSnapshot.add(Long.valueOf(e));
|
|
this.userGuildScheduledEvents.remove(Long.valueOf(e));
|
|
List<GuildScheduledEvent> list = this.guildScheduledEvents.get(Long.valueOf(guildScheduledEvent.d()));
|
|
if (list != null) {
|
|
m.checkNotNullExpressionValue(list, "eventList");
|
|
Iterator<GuildScheduledEvent> it = list.iterator();
|
|
boolean z2 = false;
|
|
int i = 0;
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
i = -1;
|
|
break;
|
|
}
|
|
if (it.next().e() == e) {
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
Integer valueOf = Integer.valueOf(i);
|
|
if (valueOf.intValue() != -1) {
|
|
z2 = true;
|
|
}
|
|
Integer num = null;
|
|
if (!z2) {
|
|
valueOf = null;
|
|
}
|
|
if (valueOf != null) {
|
|
int intValue = valueOf.intValue();
|
|
Integer i2 = guildScheduledEvent.i();
|
|
if (i2 != null) {
|
|
num = Integer.valueOf(i2.intValue() - 1);
|
|
}
|
|
list.set(intValue, GuildScheduledEvent.a(guildScheduledEvent, 0, 0, 0, null, null, null, null, null, null, null, null, null, null, null, num, 16383));
|
|
}
|
|
}
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildScheduledEventUserCreate(GuildScheduledEventUserUpdate guildScheduledEventUserUpdate) {
|
|
m.checkNotNullParameter(guildScheduledEventUserUpdate, "guildScheduledEventUserUpdate");
|
|
GuildScheduledEvent findEventFromStore$default = findEventFromStore$default(this, guildScheduledEventUserUpdate.a(), null, 2, null);
|
|
if (findEventFromStore$default != null) {
|
|
processRsvpCreate(findEventFromStore$default);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildScheduledEventUserDelete(GuildScheduledEventUserUpdate guildScheduledEventUserUpdate) {
|
|
m.checkNotNullParameter(guildScheduledEventUserUpdate, "guildScheduledEventUserUpdate");
|
|
GuildScheduledEvent findEventFromStore$default = findEventFromStore$default(this, guildScheduledEventUserUpdate.a(), null, 2, null);
|
|
if (findEventFromStore$default != null) {
|
|
processRsvpDelete(findEventFromStore$default);
|
|
}
|
|
}
|
|
|
|
public final Observable<List<GuildScheduledEvent>> observeGuildScheduledEvents(long j, boolean z2, boolean z3) {
|
|
Observable<List<GuildScheduledEvent>> p = Observable.p(new StoreGuildScheduledEvents$observeGuildScheduledEvents$1(this, j, z2, z3));
|
|
m.checkNotNullExpressionValue(p, "Observable.defer {\n …emptyList()\n }\n }");
|
|
return p;
|
|
}
|
|
|
|
public final Observable<Map<Long, GuildScheduledEvent>> observeUserGuildScheduledEvents() {
|
|
Observable<Map<Long, GuildScheduledEvent>> p = Observable.p(new StoreGuildScheduledEvents$observeUserGuildScheduledEvents$1(this));
|
|
m.checkNotNullExpressionValue(p, "Observable.defer {\n …ntsSnapshot\n }\n }");
|
|
return p;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
this.guildScheduledEventsSnapshot = new HashMap(this.guildScheduledEvents);
|
|
this.userGuildScheduledEventsSnapshot = new HashMap(this.userGuildScheduledEvents);
|
|
this.rsvpsAwaitingSnapshot.clear();
|
|
}
|
|
|
|
public final void toggleRsvpGuildScheduledEvent(GuildScheduledEvent guildScheduledEvent) {
|
|
m.checkNotNullParameter(guildScheduledEvent, "guildScheduledEvent");
|
|
GuildScheduledEvent findEventFromStore = findEventFromStore(guildScheduledEvent);
|
|
long e = findEventFromStore.e();
|
|
if (!this.rsvpsAwaitingNetwork.contains(Long.valueOf(e)) && !this.rsvpsAwaitingSnapshot.contains(Long.valueOf(e))) {
|
|
this.rsvpsAwaitingNetwork.add(Long.valueOf(e));
|
|
this.dispatcher.schedule(new StoreGuildScheduledEvents$toggleRsvpGuildScheduledEvent$1(this, e, findEventFromStore));
|
|
}
|
|
}
|
|
}
|