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

159 lines
7.2 KiB
Java

package com.discord.stores;
import android.content.Context;
import com.discord.api.message.Message;
import com.discord.api.user.TypingUser;
import com.discord.api.user.User;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import d0.t.h0;
import d0.z.d.m;
import j0.l.e.j;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.Subscription;
/* compiled from: StoreUserTyping.kt */
public final class StoreUserTyping extends StoreV2 {
private final Dispatcher dispatcher;
private final ObservationDeck observationDeck;
private final RestAPI restAPI;
private final StoreStream stream;
private final HashMap<Long, Set<Long>> typingUsers;
private final HashMap<Long, Map<Long, Subscription>> typingUsersRemoveCallbacks;
private Map<Long, ? extends Set<Long>> typingUsersSnapshot;
public StoreUserTyping(StoreStream storeStream, Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI) {
m.checkNotNullParameter(storeStream, "stream");
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(observationDeck, "observationDeck");
m.checkNotNullParameter(restAPI, "restAPI");
this.stream = storeStream;
this.dispatcher = dispatcher;
this.observationDeck = observationDeck;
this.restAPI = restAPI;
this.typingUsersRemoveCallbacks = new HashMap<>();
this.typingUsers = new HashMap<>();
this.typingUsersSnapshot = h0.emptyMap();
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreUserTyping(StoreStream storeStream, Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(storeStream, dispatcher, (i & 4) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 8) != 0 ? RestAPI.Companion.getApi() : restAPI);
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreUserTyping storeUserTyping) {
return storeUserTyping.dispatcher;
}
public static final /* synthetic */ Map access$getTypingUsers(StoreUserTyping storeUserTyping) {
return storeUserTyping.getTypingUsers();
}
public static final /* synthetic */ HashMap access$getTypingUsersRemoveCallbacks$p(StoreUserTyping storeUserTyping) {
return storeUserTyping.typingUsersRemoveCallbacks;
}
public static final /* synthetic */ void access$handleTypingStop(StoreUserTyping storeUserTyping, TypingUser typingUser) {
storeUserTyping.handleTypingStop(typingUser);
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends java.util.Set<java.lang.Long>>, java.util.Map<java.lang.Long, java.util.Set<java.lang.Long>> */
private final Map<Long, Set<Long>> getTypingUsers() {
return this.typingUsersSnapshot;
}
@StoreThread
private final void handleTypingStop(TypingUser typingUser) {
Set<Long> set = this.typingUsers.get(Long.valueOf(typingUser.a()));
if (set != null) {
m.checkNotNullExpressionValue(set, "typingUsers[typing.channelId] ?: return");
if (set.remove(Long.valueOf(typingUser.d()))) {
markChanged();
}
}
}
@StoreThread
public final void handleMessageCreate(Message message) {
m.checkNotNullParameter(message, "message");
User e = message.e();
if (e != null) {
long i = e.i();
Set<Long> set = this.typingUsers.get(Long.valueOf(message.g()));
if (set != null) {
m.checkNotNullExpressionValue(set, "typingUsers[message.channelId] ?: return");
if (set.remove(Long.valueOf(i))) {
markChanged();
}
}
}
}
@StoreThread
public final void handleTypingStart(TypingUser typingUser) {
m.checkNotNullParameter(typingUser, "typing");
long id2 = this.stream.getUsers$app_productionBetaRelease().getMeInternal$app_productionBetaRelease().getId();
long d = typingUser.d();
if (id2 != d) {
long a = typingUser.a();
HashMap<Long, Map<Long, Subscription>> hashMap = this.typingUsersRemoveCallbacks;
Long valueOf = Long.valueOf(a);
Map<Long, Subscription> map = hashMap.get(valueOf);
if (map == null) {
map = new HashMap<>();
hashMap.put(valueOf, map);
}
Subscription subscription = map.get(Long.valueOf(d));
if (subscription != null) {
subscription.unsubscribe();
}
Observable<T> q = new j(typingUser).q(10, TimeUnit.SECONDS);
m.checkNotNullExpressionValue(q, "Observable\n .just…lay(10, TimeUnit.SECONDS)");
ObservableExtensionsKt.appSubscribe$default(q, (Context) null, "typingRemove", new StoreUserTyping$handleTypingStart$2(this, a, d), new StoreUserTyping$handleTypingStart$1(this), (Function1) null, (Function0) null, (Function0) null, 113, (Object) null);
HashMap<Long, Set<Long>> hashMap2 = this.typingUsers;
Long valueOf2 = Long.valueOf(a);
Set<Long> set = hashMap2.get(valueOf2);
if (set == null) {
set = new HashSet<>();
hashMap2.put(valueOf2, set);
}
if (set.add(Long.valueOf(d))) {
markChanged();
}
}
}
public final Observable<Set<Long>> observeTypingUsers(long j) {
Observable<Set<Long>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserTyping$observeTypingUsers$1(this), 14, null).F(new StoreUserTyping$observeTypingUsers$2(j)).r();
m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()");
return r;
}
public final void setUserTyping(long j) {
if (j != 0) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.setUserTyping(j, new RestAPIParams.EmptyBody()), false, 1, null), (Context) null, "typingEvent", (Function1) null, new StoreUserTyping$setUserTyping$1(this, j), (Function1) null, (Function0) null, (Function0) null, 117, (Object) null);
}
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData() {
super.snapshotData();
HashMap hashMap = new HashMap();
for (Map.Entry<Long, Set<Long>> entry : this.typingUsers.entrySet()) {
hashMap.put(Long.valueOf(entry.getKey().longValue()), new HashSet(entry.getValue()));
}
this.typingUsersSnapshot = hashMap;
}
}