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

445 lines
18 KiB
Java

package com.discord.stores;
import a0.a.a.b;
import android.content.Context;
import b.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.app.AppLog;
import com.discord.models.domain.ModelPayload;
import com.discord.models.guild.Guild;
import com.discord.restapi.RestAPIInterface;
import com.discord.restapi.RestAPIParams;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.widgets.chat.input.MentionUtilsKt;
import com.discord.widgets.guilds.join.GuildJoinHelperKt;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function3;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/* compiled from: StoreLurking.kt */
public final class StoreLurking {
public static final Companion Companion = new Companion(null);
private final Dispatcher dispatcher;
private final StoreGuilds guildsStore;
private LurkRequest lurkRequest;
private final Map<Long, LurkContext> lurkedGuilds = new LinkedHashMap();
private final BehaviorSubject<Map<Long, LurkContext>> lurkedGuildsSubject = BehaviorSubject.l0(new LinkedHashMap());
private String sessionId;
private final StoreStream stream;
/* compiled from: StoreLurking.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ boolean access$isLurking(Companion companion, boolean z2, long j, Set set) {
return companion.isLurking(z2, j, set);
}
private final boolean isLurking(boolean z2, long j, Set<Long> set) {
return !z2 && set.contains(Long.valueOf(j));
}
}
/* compiled from: StoreLurking.kt */
public static final class LurkContext {
private final long guildId;
private final boolean shouldNavigate;
public LurkContext(long j, boolean z2) {
this.guildId = j;
this.shouldNavigate = z2;
}
public static /* synthetic */ LurkContext copy$default(LurkContext lurkContext, long j, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
j = lurkContext.guildId;
}
if ((i & 2) != 0) {
z2 = lurkContext.shouldNavigate;
}
return lurkContext.copy(j, z2);
}
public final long component1() {
return this.guildId;
}
public final boolean component2() {
return this.shouldNavigate;
}
public final LurkContext copy(long j, boolean z2) {
return new LurkContext(j, z2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LurkContext)) {
return false;
}
LurkContext lurkContext = (LurkContext) obj;
return this.guildId == lurkContext.guildId && this.shouldNavigate == lurkContext.shouldNavigate;
}
public final long getGuildId() {
return this.guildId;
}
public final boolean getShouldNavigate() {
return this.shouldNavigate;
}
public int hashCode() {
int a = b.a(this.guildId) * 31;
boolean z2 = this.shouldNavigate;
if (z2) {
z2 = true;
}
int i = z2 ? 1 : 0;
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
return a + i;
}
public String toString() {
StringBuilder R = a.R("LurkContext(guildId=");
R.append(this.guildId);
R.append(", shouldNavigate=");
return a.M(R, this.shouldNavigate, ")");
}
}
/* compiled from: StoreLurking.kt */
public static final class LurkRequest {
private final Long channelId;
private final long guildId;
public LurkRequest(long j, Long l) {
this.guildId = j;
this.channelId = l;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ LurkRequest(long j, Long l, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(j, (i & 2) != 0 ? null : l);
}
public static /* synthetic */ LurkRequest copy$default(LurkRequest lurkRequest, long j, Long l, int i, Object obj) {
if ((i & 1) != 0) {
j = lurkRequest.guildId;
}
if ((i & 2) != 0) {
l = lurkRequest.channelId;
}
return lurkRequest.copy(j, l);
}
public final long component1() {
return this.guildId;
}
public final Long component2() {
return this.channelId;
}
public final LurkRequest copy(long j, Long l) {
return new LurkRequest(j, l);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LurkRequest)) {
return false;
}
LurkRequest lurkRequest = (LurkRequest) obj;
return this.guildId == lurkRequest.guildId && m.areEqual(this.channelId, lurkRequest.channelId);
}
public final Long getChannelId() {
return this.channelId;
}
public final long getGuildId() {
return this.guildId;
}
public int hashCode() {
int a = b.a(this.guildId) * 31;
Long l = this.channelId;
return a + (l != null ? l.hashCode() : 0);
}
public String toString() {
StringBuilder R = a.R("LurkRequest(guildId=");
R.append(this.guildId);
R.append(", channelId=");
return a.F(R, this.channelId, ")");
}
}
public StoreLurking(StoreStream storeStream, StoreGuilds storeGuilds, Dispatcher dispatcher) {
m.checkNotNullParameter(storeStream, "stream");
m.checkNotNullParameter(storeGuilds, "guildsStore");
m.checkNotNullParameter(dispatcher, "dispatcher");
this.stream = storeStream;
this.guildsStore = storeGuilds;
this.dispatcher = dispatcher;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreLurking storeLurking) {
return storeLurking.dispatcher;
}
public static final /* synthetic */ LurkRequest access$getLurkRequest$p(StoreLurking storeLurking) {
return storeLurking.lurkRequest;
}
public static final /* synthetic */ Map access$getLurkedGuilds$p(StoreLurking storeLurking) {
return storeLurking.lurkedGuilds;
}
public static final /* synthetic */ BehaviorSubject access$getLurkedGuildsSubject$p(StoreLurking storeLurking) {
return storeLurking.lurkedGuildsSubject;
}
public static final /* synthetic */ String access$getSessionId$p(StoreLurking storeLurking) {
return storeLurking.sessionId;
}
public static final /* synthetic */ StoreStream access$getStream$p(StoreLurking storeLurking) {
return storeLurking.stream;
}
public static final /* synthetic */ void access$setLurkRequest$p(StoreLurking storeLurking, LurkRequest lurkRequest) {
storeLurking.lurkRequest = lurkRequest;
}
public static final /* synthetic */ void access$setSessionId$p(StoreLurking storeLurking, String str) {
storeLurking.sessionId = str;
}
private final void postLeaveGuild(long j, Function0<Unit> function0, Function0<Unit> function02) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().leaveGuild(j, new RestAPIParams.LeaveGuildBody(true)), false, 1, null), StoreLurking.class, (Context) null, (Function1) null, new StoreLurking$postLeaveGuild$3(function02), (Function0) null, (Function0) null, new StoreLurking$postLeaveGuild$4(function0), 54, (Object) null);
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreLurking */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void postLeaveGuild$default(StoreLurking storeLurking, long j, Function0 function0, Function0 function02, int i, Object obj) {
if ((i & 2) != 0) {
function0 = StoreLurking$postLeaveGuild$1.INSTANCE;
}
if ((i & 4) != 0) {
function02 = StoreLurking$postLeaveGuild$2.INSTANCE;
}
storeLurking.postLeaveGuild(j, function0, function02);
}
/* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: com.discord.stores.StoreLurking */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void startLurking$default(StoreLurking storeLurking, long j, Long l, boolean z2, Function3 function3, Function0 function0, int i, Object obj) {
boolean z3 = (i & 4) != 0 ? true : z2;
if ((i & 8) != 0) {
function3 = StoreLurking$startLurking$1.INSTANCE;
}
if ((i & 16) != 0) {
function0 = StoreLurking$startLurking$2.INSTANCE;
}
storeLurking.startLurking(j, l, z3, function3, function0);
}
public static /* synthetic */ void startLurkingAndNavigate$default(StoreLurking storeLurking, long j, Long l, Context context, int i, Object obj) {
if ((i & 4) != 0) {
context = null;
}
storeLurking.startLurkingAndNavigate(j, l, context);
}
@StoreThread
private final void startLurkingInternal(long j, Long l, boolean z2, Function3<? super Guild, ? super Long, ? super Boolean, Unit> function3, Function0<Unit> function0, Context context) {
if (this.sessionId == null) {
AppLog appLog = AppLog.g;
Logger.w$default(appLog, "Cannot lurk " + j + MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR + l + " with no session", null, 2, null);
function0.mo1invoke();
} else if (j != 0 || j == -1) {
Guild guild = this.stream.getGuilds$app_productionBetaRelease().getGuildsInternal$app_productionBetaRelease().get(Long.valueOf(j));
if (guild == null || isLurking$app_productionBetaRelease(guild)) {
this.lurkedGuilds.put(Long.valueOf(j), new LurkContext(j, z2));
this.lurkedGuildsSubject.onNext(this.lurkedGuilds);
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(ObservableExtensionsKt.restSubscribeOn$default(RestAPIInterface.DefaultImpls.joinGuild$default(RestAPI.Companion.getApi(), j, true, this.sessionId, null, new RestAPIParams.InviteCode(null, null), null, 32, null), false, 1, null)), StoreLurking.class, context, (Function1) null, new StoreLurking$startLurkingInternal$3(this, j), (Function0) null, (Function0) null, new StoreLurking$startLurkingInternal$4(this, j, function3, l), 52, (Object) null);
return;
}
function3.invoke(guild, l, Boolean.TRUE);
} else {
AppLog appLog2 = AppLog.g;
Logger.w$default(appLog2, "Invalid ids for lurking " + j + MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR + l, null, 2, null);
function0.mo1invoke();
}
}
public static /* synthetic */ void startLurkingInternal$default(StoreLurking storeLurking, long j, Long l, boolean z2, Function3 function3, Function0 function0, Context context, int i, Object obj) {
storeLurking.startLurkingInternal(j, l, (i & 4) != 0 ? false : z2, (i & 8) != 0 ? StoreLurking$startLurkingInternal$1.INSTANCE : function3, (i & 16) != 0 ? StoreLurking$startLurkingInternal$2.INSTANCE : function0, (i & 32) != 0 ? null : context);
}
@StoreThread
private final void stopLurkingInternal(long j) {
if (this.lurkedGuilds.remove(Long.valueOf(j)) != null) {
this.lurkedGuildsSubject.onNext(this.lurkedGuilds);
}
}
public final Observable<Set<Long>> getLurkingGuildIds() {
Observable<R> F = this.lurkedGuildsSubject.F(StoreLurking$getLurkingGuildIds$1.INSTANCE);
m.checkNotNullExpressionValue(F, "lurkedGuildsSubject.map { it.keys }");
return F;
}
public final Set<Long> getLurkingGuildIdsSync() {
return this.lurkedGuilds.keySet();
}
@StoreThread
public final void handleConnectionOpen$app_productionBetaRelease(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
this.sessionId = modelPayload.getSessionId();
LurkRequest lurkRequest = this.lurkRequest;
if (lurkRequest != null) {
AppLog.i("Processing lurk request from app link");
startLurkingAndNavigate$default(this, lurkRequest.getGuildId(), lurkRequest.getChannelId(), null, 4, null);
}
this.lurkRequest = null;
}
@StoreThread
public final void handleGuildAdd$app_productionBetaRelease(com.discord.api.guild.Guild guild) {
LurkContext lurkContext;
m.checkNotNullParameter(guild, "guild");
if (!this.lurkedGuilds.keySet().contains(Long.valueOf(guild.r()))) {
return;
}
if (guild.s() == null && (lurkContext = this.lurkedGuilds.get(Long.valueOf(guild.r()))) != null && lurkContext.getShouldNavigate()) {
this.stream.getGuildSelected$app_productionBetaRelease().handleGuildSelected(guild.r());
} else if (guild.s() != null) {
stopLurkingInternal(guild.r());
}
}
@StoreThread
public final void handleGuildRemove$app_productionBetaRelease(com.discord.api.guild.Guild guild) {
m.checkNotNullParameter(guild, "guild");
stopLurkingInternal(guild.r());
}
@StoreThread
public final void handleGuildSelected$app_productionBetaRelease(long j) {
LurkRequest lurkRequest = this.lurkRequest;
if ((lurkRequest == null || j != lurkRequest.getGuildId()) && this.sessionId != null) {
this.lurkRequest = null;
}
removeOldLurkingGuilds(j);
}
@StoreThread
public final void handleVoiceChannelSelected$app_productionBetaRelease(long j) {
Channel channel = this.stream.getChannels$app_productionBetaRelease().getChannel(j);
Set<Long> keySet = this.lurkedGuilds.keySet();
ArrayList<Number> arrayList = new ArrayList();
for (Object obj : keySet) {
if (channel == null || ((Number) obj).longValue() != channel.f()) {
arrayList.add(obj);
}
}
for (Number number : arrayList) {
long longValue = number.longValue();
if (longValue != this.stream.getGuildSelected$app_productionBetaRelease().getSelectedGuildIdInternal$app_productionBetaRelease()) {
postLeaveGuild$default(this, longValue, null, null, 6, null);
}
}
}
@StoreThread
public final boolean isLurking$app_productionBetaRelease(long j) {
return Companion.access$isLurking(Companion, false, j, this.lurkedGuilds.keySet());
}
@StoreThread
public final boolean isLurking$app_productionBetaRelease(com.discord.api.guild.Guild guild) {
m.checkNotNullParameter(guild, "guild");
return Companion.access$isLurking(Companion, guild.s() != null, guild.r(), this.lurkedGuilds.keySet());
}
@StoreThread
public final boolean isLurking$app_productionBetaRelease(Guild guild) {
m.checkNotNullParameter(guild, "guild");
return Companion.access$isLurking(Companion, guild.getJoinedAt() != null, guild.getId(), this.lurkedGuilds.keySet());
}
public final Observable<Boolean> isLurkingObs(long j) {
Observable<Boolean> q = Observable.j(getLurkingGuildIds(), this.stream.getGuilds$app_productionBetaRelease().observeGuild(j), StoreLurking$isLurkingObs$1.INSTANCE).q();
m.checkNotNullExpressionValue(q, "Observable\n .co… .distinctUntilChanged()");
return q;
}
public final void postJoinGuildAsMember(long j, Context context) {
m.checkNotNullParameter(context, "context");
GuildJoinHelperKt.joinGuild$default(context, j, false, this.sessionId, null, null, StoreLurking.class, null, null, null, StoreLurking$postJoinGuildAsMember$1.INSTANCE, 944, null);
}
public final void removeOldLurkingGuilds(long j) {
Channel channel = this.stream.getChannels$app_productionBetaRelease().getChannel(this.stream.getVoiceChannelSelected$app_productionBetaRelease().getSelectedVoiceChannelId());
Long valueOf = channel != null ? Long.valueOf(channel.f()) : null;
Set<Long> keySet = this.lurkedGuilds.keySet();
ArrayList<Number> arrayList = new ArrayList();
for (Object obj : keySet) {
long longValue = ((Number) obj).longValue();
if (longValue != j && (valueOf == null || longValue != valueOf.longValue())) {
arrayList.add(obj);
}
}
ArrayList<Guild> arrayList2 = new ArrayList();
for (Number number : arrayList) {
Guild guild = this.guildsStore.getGuildsInternal$app_productionBetaRelease().get(Long.valueOf(number.longValue()));
if (guild != null) {
arrayList2.add(guild);
}
}
for (Guild guild2 : arrayList2) {
postLeaveGuild$default(this, guild2.getId(), null, null, 6, null);
}
}
public final void startLurking(long j, Long l, boolean z2, Function3<? super Guild, ? super Long, ? super Boolean, Unit> function3, Function0<Unit> function0) {
m.checkNotNullParameter(function3, "onGuildLurked");
m.checkNotNullParameter(function0, "onErrorLurking");
this.dispatcher.schedule(new StoreLurking$startLurking$3(this, j, l, z2, function3, function0));
}
public final void startLurkingAndNavigate(long j, Long l, Context context) {
this.dispatcher.schedule(new StoreLurking$startLurkingAndNavigate$1(this, j, l, context));
}
public final void stopLurking(long j, Function0<Unit> function0, Function0<Unit> function02) {
m.checkNotNullParameter(function0, "onSuccess");
m.checkNotNullParameter(function02, "onFailure");
postLeaveGuild(j, function0, function02);
}
}