2021-06-27 20:44:35 +00:00
package com.discord.stores ;
import a0.a.a.b ;
import android.content.Context ;
import android.content.SharedPreferences ;
import c.d.b.a.a ;
import c.i.d.e ;
import com.discord.api.commands.ApplicationCommandData ;
import com.discord.api.interaction.Interaction ;
import com.discord.api.interaction.InteractionStateUpdate ;
2021-06-27 20:53:42 +00:00
import com.discord.api.message.Message ;
2021-06-27 20:44:35 +00:00
import com.discord.api.user.User ;
import com.discord.app.AppLog ;
import com.discord.models.commands.Application ;
import com.discord.models.commands.ApplicationCommandLocalSendData ;
import com.discord.models.domain.NonceGenerator ;
import com.discord.nullserializable.NullSerializable ;
import com.discord.restapi.RestAPIParams ;
import com.discord.stores.updates.ObservationDeck ;
import com.discord.stores.updates.ObservationDeckProvider ;
import com.discord.utilities.cache.SharedPreferencesProvider ;
import com.discord.utilities.error.Error ;
import com.discord.utilities.logging.Logger ;
2021-06-27 20:53:42 +00:00
import com.discord.utilities.message.LocalMessageCreatorsKt ;
2021-06-27 20:44:35 +00:00
import com.discord.utilities.messagesend.MessageResult ;
import com.discord.utilities.rest.RestAPI ;
import com.discord.utilities.rx.ObservableExtensionsKt ;
import com.discord.utilities.time.Clock ;
import com.discord.utilities.user.UserUtils ;
import com.google.gson.Gson ;
import d0.g0.t ;
import d0.o ;
import d0.t.g0 ;
import d0.t.h0 ;
import d0.z.d.m ;
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.Map ;
import kotlin.Unit ;
import kotlin.jvm.functions.Function0 ;
import kotlin.jvm.functions.Function1 ;
import kotlin.jvm.internal.DefaultConstructorMarker ;
import rx.Observable ;
/* compiled from: StoreApplicationInteractions.kt */
public final class StoreApplicationInteractions extends StoreV2 {
private static final String CACHE_KEY_APPLICATION_COMMAND_SEND_DATA_SET = " CACHE_KEY_APPLICATION_COMMAND_SEND_DATA_SET " ;
public static final Companion Companion = new Companion ( null ) ;
private static final ObservationDeck . UpdateSource ComponentStateUpdate = new StoreApplicationInteractions$Companion$ComponentStateUpdate$1 ( ) ;
public static final long TYPE_COMPONENT_INTERACTION = 3 ;
private Map < String , ApplicationCommandLocalSendData > applicationCommandLocalSendDataSet ;
private Map < String , ApplicationCommandLocalSendData > applicationCommandLocalSendDataSnapshot ;
private final Clock clock ;
private final Map < String , ComponentLocation > componentInteractions ;
private final Dispatcher dispatcher ;
private final Gson gson ;
private final Map < Long , Map < Integer , InteractionSendState > > interactionComponentSendState ;
private Map < Long , ? extends Map < Integer , ? extends InteractionSendState > > interactionComponentSendStateSnapshot ;
private final HashMap < Long , State > interactionData ;
private Map < Long , ? extends State > interactionDataSnapshot ;
private final NonceGenerator nonceGenerator ;
private final ObservationDeck observationDeck ;
private final RestAPI restAPI ;
private final SharedPreferences sharedPrefs ;
private final StoreLocalActionComponentState storeLocalActionComponentState ;
private final StoreMessages storeMessages ;
private final StoreStream storeStream ;
private final StoreUser storeUser ;
/* compiled from: StoreApplicationInteractions.kt */
public static final class Companion {
private Companion ( ) {
}
public /* synthetic */ Companion ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
public final ObservationDeck . UpdateSource getComponentStateUpdate ( ) {
return StoreApplicationInteractions . access$getComponentStateUpdate$cp ( ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static final class ComponentLocation {
private final int componentIndex ;
private final long messageId ;
public ComponentLocation ( long j , int i ) {
this . messageId = j ;
this . componentIndex = i ;
}
public static /* synthetic */ ComponentLocation copy$default ( ComponentLocation componentLocation , long j , int i , int i2 , Object obj ) {
if ( ( i2 & 1 ) ! = 0 ) {
j = componentLocation . messageId ;
}
if ( ( i2 & 2 ) ! = 0 ) {
i = componentLocation . componentIndex ;
}
return componentLocation . copy ( j , i ) ;
}
public final long component1 ( ) {
return this . messageId ;
}
public final int component2 ( ) {
return this . componentIndex ;
}
public final ComponentLocation copy ( long j , int i ) {
return new ComponentLocation ( j , i ) ;
}
public boolean equals ( Object obj ) {
if ( this = = obj ) {
return true ;
}
if ( ! ( obj instanceof ComponentLocation ) ) {
return false ;
}
ComponentLocation componentLocation = ( ComponentLocation ) obj ;
return this . messageId = = componentLocation . messageId & & this . componentIndex = = componentLocation . componentIndex ;
}
public final int getComponentIndex ( ) {
return this . componentIndex ;
}
public final long getMessageId ( ) {
return this . messageId ;
}
public int hashCode ( ) {
return ( b . a ( this . messageId ) * 31 ) + this . componentIndex ;
}
public String toString ( ) {
StringBuilder L = a . L ( " ComponentLocation(messageId= " ) ;
L . append ( this . messageId ) ;
L . append ( " , componentIndex= " ) ;
return a . z ( L , this . componentIndex , " ) " ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static abstract class InteractionSendState {
/* compiled from: StoreApplicationInteractions.kt */
public static final class Failed extends InteractionSendState {
private final String errorMessage ;
public Failed ( ) {
this ( null , 1 , null ) ;
}
public Failed ( String str ) {
super ( null ) ;
this . errorMessage = str ;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ Failed ( String str , int i , DefaultConstructorMarker defaultConstructorMarker ) {
this ( ( i & 1 ) ! = 0 ? null : str ) ;
}
public final String getErrorMessage ( ) {
return this . errorMessage ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static final class Loading extends InteractionSendState {
public static final Loading INSTANCE = new Loading ( ) ;
private Loading ( ) {
super ( null ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static final class Success extends InteractionSendState {
public static final Success INSTANCE = new Success ( ) ;
private Success ( ) {
super ( null ) ;
}
}
private InteractionSendState ( ) {
}
public /* synthetic */ InteractionSendState ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static abstract class State {
/* compiled from: StoreApplicationInteractions.kt */
public static final class Failure extends State {
public static final Failure INSTANCE = new Failure ( ) ;
private Failure ( ) {
super ( null ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static final class Fetching extends State {
public static final Fetching INSTANCE = new Fetching ( ) ;
private Fetching ( ) {
super ( null ) ;
}
}
/* compiled from: StoreApplicationInteractions.kt */
public static final class Loaded extends State {
private final ApplicationCommandData commandOptions ;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded ( ApplicationCommandData applicationCommandData ) {
super ( null ) ;
m . checkNotNullParameter ( applicationCommandData , " commandOptions " ) ;
this . commandOptions = applicationCommandData ;
}
public static /* synthetic */ Loaded copy$default ( Loaded loaded , ApplicationCommandData applicationCommandData , int i , Object obj ) {
if ( ( i & 1 ) ! = 0 ) {
applicationCommandData = loaded . commandOptions ;
}
return loaded . copy ( applicationCommandData ) ;
}
public final ApplicationCommandData component1 ( ) {
return this . commandOptions ;
}
public final Loaded copy ( ApplicationCommandData applicationCommandData ) {
m . checkNotNullParameter ( applicationCommandData , " commandOptions " ) ;
return new Loaded ( applicationCommandData ) ;
}
public boolean equals ( Object obj ) {
if ( this ! = obj ) {
return ( obj instanceof Loaded ) & & m . areEqual ( this . commandOptions , ( ( Loaded ) obj ) . commandOptions ) ;
}
return true ;
}
public final ApplicationCommandData getCommandOptions ( ) {
return this . commandOptions ;
}
public int hashCode ( ) {
ApplicationCommandData applicationCommandData = this . commandOptions ;
if ( applicationCommandData ! = null ) {
return applicationCommandData . hashCode ( ) ;
}
return 0 ;
}
public String toString ( ) {
StringBuilder L = a . L ( " Loaded(commandOptions= " ) ;
L . append ( this . commandOptions ) ;
L . append ( " ) " ) ;
return L . toString ( ) ;
}
}
private State ( ) {
}
public /* synthetic */ State ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
}
public StoreApplicationInteractions ( StoreStream storeStream , Dispatcher dispatcher , StoreMessages storeMessages , StoreLocalActionComponentState storeLocalActionComponentState , StoreUser storeUser , Clock clock , SharedPreferences sharedPreferences , ObservationDeck observationDeck , RestAPI restAPI , NonceGenerator nonceGenerator ) {
m . checkNotNullParameter ( storeStream , " storeStream " ) ;
m . checkNotNullParameter ( dispatcher , " dispatcher " ) ;
m . checkNotNullParameter ( storeMessages , " storeMessages " ) ;
m . checkNotNullParameter ( storeLocalActionComponentState , " storeLocalActionComponentState " ) ;
m . checkNotNullParameter ( storeUser , " storeUser " ) ;
m . checkNotNullParameter ( clock , " clock " ) ;
m . checkNotNullParameter ( sharedPreferences , " sharedPrefs " ) ;
m . checkNotNullParameter ( observationDeck , " observationDeck " ) ;
m . checkNotNullParameter ( restAPI , " restAPI " ) ;
m . checkNotNullParameter ( nonceGenerator , " nonceGenerator " ) ;
this . storeStream = storeStream ;
this . dispatcher = dispatcher ;
this . storeMessages = storeMessages ;
this . storeLocalActionComponentState = storeLocalActionComponentState ;
this . storeUser = storeUser ;
this . clock = clock ;
this . sharedPrefs = sharedPreferences ;
this . observationDeck = observationDeck ;
this . restAPI = restAPI ;
this . nonceGenerator = nonceGenerator ;
this . componentInteractions = new LinkedHashMap ( ) ;
this . interactionComponentSendState = new LinkedHashMap ( ) ;
this . interactionComponentSendStateSnapshot = h0 . emptyMap ( ) ;
this . applicationCommandLocalSendDataSnapshot = new LinkedHashMap ( ) ;
this . applicationCommandLocalSendDataSet = new LinkedHashMap ( ) ;
this . interactionDataSnapshot = h0 . emptyMap ( ) ;
this . interactionData = new HashMap < > ( ) ;
e eVar = new e ( ) ;
c . a . b . a . a ( eVar ) ;
this . gson = eVar . a ( ) ;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreApplicationInteractions ( StoreStream storeStream , Dispatcher dispatcher , StoreMessages storeMessages , StoreLocalActionComponentState storeLocalActionComponentState , StoreUser storeUser , Clock clock , SharedPreferences sharedPreferences , ObservationDeck observationDeck , RestAPI restAPI , NonceGenerator nonceGenerator , int i , DefaultConstructorMarker defaultConstructorMarker ) {
this ( storeStream , dispatcher , storeMessages , storeLocalActionComponentState , storeUser , clock , ( i & 64 ) ! = 0 ? SharedPreferencesProvider . INSTANCE . get ( ) : sharedPreferences , ( i & 128 ) ! = 0 ? ObservationDeckProvider . get ( ) : observationDeck , ( i & 256 ) ! = 0 ? RestAPI . Companion . getApi ( ) : restAPI , ( i & 512 ) ! = 0 ? new NonceGenerator ( ) : nonceGenerator ) ;
}
public static final /* synthetic */ void access$addInteractionStateToComponent ( StoreApplicationInteractions storeApplicationInteractions , long j , int i , InteractionSendState interactionSendState ) {
storeApplicationInteractions . addInteractionStateToComponent ( j , i , interactionSendState ) ;
}
public static final /* synthetic */ ObservationDeck . UpdateSource access$getComponentStateUpdate$cp ( ) {
return ComponentStateUpdate ;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p ( StoreApplicationInteractions storeApplicationInteractions ) {
return storeApplicationInteractions . dispatcher ;
}
public static final /* synthetic */ RestAPI access$getRestAPI$p ( StoreApplicationInteractions storeApplicationInteractions ) {
return storeApplicationInteractions . restAPI ;
}
public static final /* synthetic */ StoreLocalActionComponentState access$getStoreLocalActionComponentState$p ( StoreApplicationInteractions storeApplicationInteractions ) {
return storeApplicationInteractions . storeLocalActionComponentState ;
}
public static final /* synthetic */ StoreMessages access$getStoreMessages$p ( StoreApplicationInteractions storeApplicationInteractions ) {
return storeApplicationInteractions . storeMessages ;
}
public static final /* synthetic */ void access$handleApplicationCommandResult ( StoreApplicationInteractions storeApplicationInteractions , MessageResult messageResult , ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 function0 , Function1 function1 ) {
storeApplicationInteractions . handleApplicationCommandResult ( messageResult , applicationCommandLocalSendData , function0 , function1 ) ;
}
public static final /* synthetic */ void access$handleInteractionDataFetchFailure ( StoreApplicationInteractions storeApplicationInteractions , long j ) {
storeApplicationInteractions . handleInteractionDataFetchFailure ( j ) ;
}
public static final /* synthetic */ void access$handleInteractionDataFetchStart ( StoreApplicationInteractions storeApplicationInteractions , long j ) {
storeApplicationInteractions . handleInteractionDataFetchStart ( j ) ;
}
public static final /* synthetic */ void access$handleInteractionDataFetchSuccess ( StoreApplicationInteractions storeApplicationInteractions , long j , ApplicationCommandData applicationCommandData ) {
storeApplicationInteractions . handleInteractionDataFetchSuccess ( j , applicationCommandData ) ;
}
public static final /* synthetic */ void access$handleSendApplicationCommandRequest ( StoreApplicationInteractions storeApplicationInteractions , ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 function0 , Function1 function1 ) {
storeApplicationInteractions . handleSendApplicationCommandRequest ( applicationCommandLocalSendData , function0 , function1 ) ;
}
public static final /* synthetic */ void access$removeApplicationCommandSendData ( StoreApplicationInteractions storeApplicationInteractions , String str ) {
storeApplicationInteractions . removeApplicationCommandSendData ( str ) ;
}
@StoreThread
private final void addInteractionStateToComponent ( long j , int i , InteractionSendState interactionSendState ) {
this . interactionComponentSendState . put ( Long . valueOf ( j ) , g0 . mapOf ( o . to ( Integer . valueOf ( i ) , interactionSendState ) ) ) ;
markChanged ( ComponentStateUpdate ) ;
}
2021-06-27 20:53:42 +00:00
private final Message buildApplicationCommandLocalMessage ( ApplicationCommandLocalSendData applicationCommandLocalSendData , boolean z2 , boolean z3 ) {
return LocalMessageCreatorsKt . createLocalApplicationCommandMessage ( applicationCommandLocalSendData . getNonce ( ) , applicationCommandLocalSendData . getApplicationCommandName ( ) , applicationCommandLocalSendData . getChannelId ( ) , UserUtils . INSTANCE . synthesizeApiUser ( this . storeUser . getMe ( ) ) , toUser ( applicationCommandLocalSendData . getApplication ( ) ) , z3 , z2 , applicationCommandLocalSendData . getInteractionId ( ) , this . clock ) ;
2021-06-27 20:44:35 +00:00
}
2021-06-27 20:53:42 +00:00
public static /* synthetic */ Message buildApplicationCommandLocalMessage$default ( StoreApplicationInteractions storeApplicationInteractions , ApplicationCommandLocalSendData applicationCommandLocalSendData , boolean z2 , boolean z3 , int i , Object obj ) {
2021-06-27 20:44:35 +00:00
if ( ( i & 2 ) ! = 0 ) {
z2 = false ;
}
if ( ( i & 4 ) ! = 0 ) {
z3 = false ;
}
return storeApplicationInteractions . buildApplicationCommandLocalMessage ( applicationCommandLocalSendData , z2 , z3 ) ;
}
@StoreThread
private final void clearCache ( ) {
SharedPreferences . Editor edit = this . sharedPrefs . edit ( ) ;
m . checkExpressionValueIsNotNull ( edit , " editor " ) ;
edit . putString ( " CACHE_KEY_APPLICATION_COMMAND_SEND_DATA_SET " , null ) ;
edit . apply ( ) ;
this . applicationCommandLocalSendDataSet . clear ( ) ;
markChanged ( ) ;
}
private final void clearComponentInteractionSendSuccessAndFailures ( ) {
this . dispatcher . schedule ( new StoreApplicationInteractions$clearComponentInteractionSendSuccessAndFailures$1 ( this ) ) ;
}
@StoreThread
private final void handleApplicationCommandRequestStateUpdate ( ApplicationCommandLocalSendData applicationCommandLocalSendData , Long l ) {
upsertApplicationCommandSendData ( ApplicationCommandLocalSendData . copy$default ( applicationCommandLocalSendData , 0 , 0 , null , null , null , null , null , null , null , l , 511 , null ) ) ;
}
public static /* synthetic */ void handleApplicationCommandRequestStateUpdate$default ( StoreApplicationInteractions storeApplicationInteractions , ApplicationCommandLocalSendData applicationCommandLocalSendData , Long l , int i , Object obj ) {
if ( ( i & 2 ) ! = 0 ) {
l = null ;
}
storeApplicationInteractions . handleApplicationCommandRequestStateUpdate ( applicationCommandLocalSendData , l ) ;
}
@StoreThread
private final void handleApplicationCommandResult ( MessageResult messageResult , ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 < Unit > function0 , Function1 < ? super Error , Unit > function1 ) {
ApplicationCommandLocalSendData applicationCommandLocalSendData2 = this . applicationCommandLocalSendDataSet . get ( applicationCommandLocalSendData . getNonceString ( ) ) ;
boolean z2 = ( applicationCommandLocalSendData2 ! = null ? applicationCommandLocalSendData2 . getInteractionId ( ) : null ) = = null ;
if ( messageResult instanceof MessageResult . Success ) {
if ( function0 ! = null ) {
function0 . mo1invoke ( ) ;
}
if ( z2 ) {
handleApplicationCommandRequestStateUpdate$default ( this , applicationCommandLocalSendData , null , 2 , null ) ;
}
} else if ( messageResult instanceof MessageResult . UnknownFailure ) {
if ( function1 ! = null ) {
function1 . invoke ( ( ( MessageResult . UnknownFailure ) messageResult ) . getError ( ) ) ;
}
if ( z2 ) {
this . storeStream . handleInteractionFailure ( new InteractionStateUpdate ( applicationCommandLocalSendData . getInteractionId ( ) , applicationCommandLocalSendData . getNonceString ( ) ) ) ;
}
} else if ( z2 ) {
this . storeStream . handleInteractionFailure ( new InteractionStateUpdate ( applicationCommandLocalSendData . getInteractionId ( ) , applicationCommandLocalSendData . getNonceString ( ) ) ) ;
}
}
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.discord.stores.StoreApplicationInteractions */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void handleApplicationCommandResult$default ( StoreApplicationInteractions storeApplicationInteractions , MessageResult messageResult , ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 function0 , Function1 function1 , int i , Object obj ) {
if ( ( i & 4 ) ! = 0 ) {
function0 = null ;
}
if ( ( i & 8 ) ! = 0 ) {
function1 = null ;
}
storeApplicationInteractions . handleApplicationCommandResult ( messageResult , applicationCommandLocalSendData , function0 , function1 ) ;
}
private final void handleComponentInteractionMessage ( ComponentLocation componentLocation ) {
addInteractionStateToComponent ( componentLocation . getMessageId ( ) , componentLocation . getComponentIndex ( ) , InteractionSendState . Success . INSTANCE ) ;
}
@StoreThread
private final void handleInteractionDataFetchFailure ( long j ) {
this . interactionData . put ( Long . valueOf ( j ) , State . Failure . INSTANCE ) ;
markChanged ( ) ;
}
@StoreThread
private final void handleInteractionDataFetchStart ( long j ) {
this . interactionData . put ( Long . valueOf ( j ) , State . Fetching . INSTANCE ) ;
markChanged ( ) ;
}
@StoreThread
private final void handleInteractionDataFetchSuccess ( long j , ApplicationCommandData applicationCommandData ) {
this . interactionData . put ( Long . valueOf ( j ) , new State . Loaded ( applicationCommandData ) ) ;
markChanged ( ) ;
}
@StoreThread
private final void handleInteractionFailure ( ApplicationCommandLocalSendData applicationCommandLocalSendData , Long l ) {
handleApplicationCommandRequestStateUpdate ( applicationCommandLocalSendData , l ) ;
}
public static /* synthetic */ void handleInteractionFailure$default ( StoreApplicationInteractions storeApplicationInteractions , ApplicationCommandLocalSendData applicationCommandLocalSendData , Long l , int i , Object obj ) {
if ( ( i & 2 ) ! = 0 ) {
l = null ;
}
storeApplicationInteractions . handleInteractionFailure ( applicationCommandLocalSendData , l ) ;
}
@StoreThread
private final void handleSendApplicationCommandRequest ( ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 < Unit > function0 , Function1 < ? super Error , Unit > function1 ) {
upsertApplicationCommandSendData ( applicationCommandLocalSendData ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . restSubscribeOn$default ( sendApplicationCommandObservable ( applicationCommandLocalSendData ) , false , 1 , null ) , StoreApplicationInteractions . class , ( Context ) null , ( Function1 ) null , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , new StoreApplicationInteractions$handleSendApplicationCommandRequest$1 ( this , applicationCommandLocalSendData , function0 , function1 ) , 62 , ( Object ) null ) ;
}
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.discord.stores.StoreApplicationInteractions */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ void handleSendApplicationCommandRequest$default ( StoreApplicationInteractions storeApplicationInteractions , ApplicationCommandLocalSendData applicationCommandLocalSendData , Function0 function0 , Function1 function1 , int i , Object obj ) {
if ( ( i & 2 ) ! = 0 ) {
function0 = null ;
}
if ( ( i & 4 ) ! = 0 ) {
function1 = null ;
}
storeApplicationInteractions . handleSendApplicationCommandRequest ( applicationCommandLocalSendData , function0 , function1 ) ;
}
/* JADX WARNING: Removed duplicated region for block: B:10:0x001d A[Catch:{ Exception -> 0x0036 }] */
/* JADX WARNING: Removed duplicated region for block: B:9:0x0017 A[Catch:{ Exception -> 0x0036 }] */
@StoreThread
private final void loadCachedApplicationCommandSendDataSet ( ) {
boolean z2 ;
Map < String , ApplicationCommandLocalSendData > map ;
try {
String string = this . sharedPrefs . getString ( " CACHE_KEY_APPLICATION_COMMAND_SEND_DATA_SET " , null ) ;
if ( string ! = null ) {
if ( ! t . isBlank ( string ) ) {
z2 = false ;
if ( ! z2 ) {
map = new LinkedHashMap < > ( ) ;
} else {
Object g = this . gson . g ( string , new StoreApplicationInteractions$loadCachedApplicationCommandSendDataSet$type$1 ( ) . getType ( ) ) ;
m . checkNotNullExpressionValue ( g , " gson.fromJson(cachedDataSet, type) " ) ;
map = ( Map ) g ;
}
this . applicationCommandLocalSendDataSet = map ;
markChanged ( ) ;
}
}
z2 = true ;
if ( ! z2 ) {
}
this . applicationCommandLocalSendDataSet = map ;
} catch ( Exception e ) {
clearCache ( ) ;
this . applicationCommandLocalSendDataSet . clear ( ) ;
Logger . e$default ( AppLog . g , " Error restoring cached command send data " , e , null , 4 , null ) ;
}
markChanged ( ) ;
}
@StoreThread
private final void markAllLocalApplicationCommandRequestsAsFailed ( ) {
for ( ApplicationCommandLocalSendData applicationCommandLocalSendData : this . applicationCommandLocalSendDataSet . values ( ) ) {
this . storeStream . handleInteractionFailure ( new InteractionStateUpdate ( applicationCommandLocalSendData . getInteractionId ( ) , applicationCommandLocalSendData . getNonceString ( ) ) ) ;
}
}
@StoreThread
private final void removeApplicationCommandSendData ( String str ) {
if ( this . applicationCommandLocalSendDataSet . remove ( str ) ! = null ) {
markChanged ( ) ;
}
}
private final Observable < MessageResult > sendApplicationCommandObservable ( ApplicationCommandLocalSendData applicationCommandLocalSendData ) {
return this . storeMessages . sendMessage ( buildApplicationCommandLocalMessage$default ( this , applicationCommandLocalSendData , false , false , 6 , null ) , applicationCommandLocalSendData ) ;
}
private final User toUser ( Application application ) {
User bot = application . getBot ( ) ;
if ( bot ! = null ) {
return bot ;
}
long id2 = application . getId ( ) ;
String name = application . getName ( ) ;
String icon = application . getIcon ( ) ;
return new User ( id2 , name , icon ! = null ? new NullSerializable . b ( icon ) : new NullSerializable . a ( null , 1 ) , null , null , null , null , Boolean . TRUE , null , null , null , null , null , null , null , null , null , null , null , null , null , null , 4194168 ) ;
}
@StoreThread
private final void upsertApplicationCommandSendData ( ApplicationCommandLocalSendData applicationCommandLocalSendData ) {
this . applicationCommandLocalSendDataSet . put ( applicationCommandLocalSendData . getNonceString ( ) , applicationCommandLocalSendData ) ;
markChanged ( ) ;
}
public final void fetchInteractionDataIfNonExisting ( long j , long j2 , long j3 , String str ) {
ApplicationCommandLocalSendData applicationCommandLocalSendData ;
State state = this . interactionData . get ( Long . valueOf ( j ) ) ;
if ( ! ( state instanceof State . Fetching ) & & ! ( state instanceof State . Loaded ) ) {
if ( ( str = = null | | t . isBlank ( str ) ) | | ! this . applicationCommandLocalSendDataSnapshot . containsKey ( str ) | | ( applicationCommandLocalSendData = this . applicationCommandLocalSendDataSnapshot . get ( str ) ) = = null ) {
this . dispatcher . schedule ( new StoreApplicationInteractions$fetchInteractionDataIfNonExisting$2 ( this , j ) ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . restSubscribeOn$default ( this . restAPI . getInteractionData ( j2 , j3 ) , false , 1 , null ) , StoreApplicationInteractions . class , ( Context ) null , ( Function1 ) null , new StoreApplicationInteractions$fetchInteractionDataIfNonExisting$4 ( this , j ) , ( Function0 ) null , ( Function0 ) null , new StoreApplicationInteractions$fetchInteractionDataIfNonExisting$3 ( this , j ) , 54 , ( Object ) null ) ;
return ;
}
this . dispatcher . schedule ( new StoreApplicationInteractions$fetchInteractionDataIfNonExisting$$inlined$let$lambda$1 ( applicationCommandLocalSendData , this , j ) ) ;
}
}
public final Map < String , ApplicationCommandLocalSendData > getApplicationCommandLocalSendDataSet$app_productionBetaRelease ( ) {
return this . applicationCommandLocalSendDataSet ;
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends java.util.Map<java.lang.Integer, ? extends com.discord.stores.StoreApplicationInteractions$InteractionSendState>>, java.util.Map<java.lang.Long, java.util.Map<java.lang.Integer, com.discord.stores.StoreApplicationInteractions$InteractionSendState>> */
public final Map < Long , Map < Integer , InteractionSendState > > getComponentInteractionData ( ) {
return this . interactionComponentSendStateSnapshot ;
}
public final Map < String , ComponentLocation > getComponentInteractions ( ) {
return this . componentInteractions ;
}
public final Map < Long , Map < Integer , InteractionSendState > > getInteractionComponentSendState ( ) {
return this . interactionComponentSendState ;
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends java.util.Map<java.lang.Integer, ? extends com.discord.stores.StoreApplicationInteractions$InteractionSendState>>, java.util.Map<java.lang.Long, java.util.Map<java.lang.Integer, com.discord.stores.StoreApplicationInteractions$InteractionSendState>> */
public final Map < Long , Map < Integer , InteractionSendState > > getInteractionComponentSendStateSnapshot ( ) {
return this . interactionComponentSendStateSnapshot ;
}
public final State getInteractionData ( long j ) {
return ( State ) this . interactionDataSnapshot . get ( Long . valueOf ( j ) ) ;
}
@StoreThread
public final void handleChannelSelected ( ) {
clearComponentInteractionSendSuccessAndFailures ( ) ;
}
@StoreThread
public final void handleConnectionReady ( boolean z2 ) {
if ( z2 ) {
markAllLocalApplicationCommandRequestsAsFailed ( ) ;
}
}
@StoreThread
public final void handleInteractionCreate ( InteractionStateUpdate interactionStateUpdate ) {
m . checkNotNullParameter ( interactionStateUpdate , " interactionStateUpdate " ) ;
ApplicationCommandLocalSendData applicationCommandLocalSendData = this . applicationCommandLocalSendDataSet . get ( interactionStateUpdate . b ( ) ) ;
if ( applicationCommandLocalSendData ! = null ) {
handleApplicationCommandRequestStateUpdate ( applicationCommandLocalSendData , interactionStateUpdate . a ( ) ) ;
}
}
@StoreThread
public final void handleInteractionFailure ( InteractionStateUpdate interactionStateUpdate ) {
ApplicationCommandLocalSendData applicationCommandLocalSendData ;
m . checkNotNullParameter ( interactionStateUpdate , " interactionStateUpdate " ) ;
if ( this . componentInteractions . containsKey ( interactionStateUpdate . b ( ) ) ) {
ComponentLocation componentLocation = this . componentInteractions . get ( interactionStateUpdate . b ( ) ) ;
if ( componentLocation ! = null ) {
this . storeLocalActionComponentState . clearState ( componentLocation . getMessageId ( ) , Integer . valueOf ( componentLocation . getComponentIndex ( ) ) ) ;
this . componentInteractions . remove ( interactionStateUpdate . b ( ) ) ;
addInteractionStateToComponent ( componentLocation . getMessageId ( ) , componentLocation . getComponentIndex ( ) , new InteractionSendState . Failed ( null , 1 , null ) ) ;
}
} else if ( this . applicationCommandLocalSendDataSet . containsKey ( interactionStateUpdate . b ( ) ) & & ( applicationCommandLocalSendData = this . applicationCommandLocalSendDataSet . get ( interactionStateUpdate . b ( ) ) ) ! = null ) {
handleInteractionFailure ( applicationCommandLocalSendData , interactionStateUpdate . a ( ) ) ;
}
}
@StoreThread
public final void handleInteractionSuccess ( InteractionStateUpdate interactionStateUpdate ) {
ComponentLocation componentLocation ;
m . checkNotNullParameter ( interactionStateUpdate , " interactionStateUpdate " ) ;
if ( this . componentInteractions . containsKey ( interactionStateUpdate . b ( ) ) & & ( componentLocation = this . componentInteractions . get ( interactionStateUpdate . b ( ) ) ) ! = null ) {
this . interactionComponentSendState . remove ( Long . valueOf ( componentLocation . getMessageId ( ) ) ) ;
this . componentInteractions . remove ( interactionStateUpdate . b ( ) ) ;
markChanged ( ComponentStateUpdate ) ;
}
}
@StoreThread
2021-06-27 20:53:42 +00:00
public final void handleLocalMessageDelete ( Message message ) {
m . checkNotNullParameter ( message , " message " ) ;
String B = message . B ( ) ;
if ( B ! = null ) {
removeApplicationCommandSendData ( B ) ;
2021-06-27 20:44:35 +00:00
}
}
@StoreThread
2021-06-27 20:53:42 +00:00
public final void handleMessageCreate ( Message message ) {
m . checkNotNullParameter ( message , " message " ) ;
handleMessagesCreateOrLoad ( d0 . t . m . listOf ( message ) ) ;
2021-06-27 20:44:35 +00:00
}
@StoreThread
2021-06-27 20:53:42 +00:00
public final void handleMessageUpdate ( Message message ) {
2021-06-27 20:44:35 +00:00
boolean z2 ;
boolean z3 ;
2021-06-27 20:53:42 +00:00
m . checkNotNullParameter ( message , " message " ) ;
2021-06-27 20:44:35 +00:00
Map < String , ComponentLocation > map = this . componentInteractions ;
if ( ! map . isEmpty ( ) ) {
Iterator < Map . Entry < String , ComponentLocation > > it = map . entrySet ( ) . iterator ( ) ;
while ( true ) {
if ( ! it . hasNext ( ) ) {
break ;
}
2021-06-27 20:53:42 +00:00
if ( it . next ( ) . getValue ( ) . getMessageId ( ) = = message . r ( ) ) {
2021-06-27 20:44:35 +00:00
z3 = true ;
continue ;
} else {
z3 = false ;
continue ;
}
if ( z3 ) {
z2 = true ;
break ;
}
}
}
z2 = false ;
if ( z2 ) {
2021-06-27 20:53:42 +00:00
this . storeLocalActionComponentState . clearState ( message . r ( ) , null ) ;
2021-06-27 20:44:35 +00:00
Map < String , ComponentLocation > map2 = this . componentInteractions ;
LinkedHashMap linkedHashMap = new LinkedHashMap ( ) ;
for ( Map . Entry < String , ComponentLocation > entry : map2 . entrySet ( ) ) {
2021-06-27 20:53:42 +00:00
if ( entry . getValue ( ) . getMessageId ( ) = = message . r ( ) ) {
2021-06-27 20:44:35 +00:00
linkedHashMap . put ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
}
for ( String str : linkedHashMap . keySet ( ) ) {
this . componentInteractions . remove ( str ) ;
}
markChanged ( ComponentStateUpdate ) ;
}
2021-06-27 20:53:42 +00:00
if ( this . interactionComponentSendState . containsKey ( Long . valueOf ( message . r ( ) ) ) ) {
this . interactionComponentSendState . remove ( Long . valueOf ( message . r ( ) ) ) ;
2021-06-27 20:44:35 +00:00
markChanged ( ComponentStateUpdate ) ;
}
}
/* JADX DEBUG: Multi-variable search result rejected for r3v3, resolved type: java.lang.Object */
/* JADX WARN: Multi-variable type inference failed */
@StoreThread
2021-06-27 20:53:42 +00:00
public final void handleMessagesCreateOrLoad ( List < Message > list ) {
2021-06-27 20:44:35 +00:00
m . checkNotNullParameter ( list , " messagesList " ) ;
2021-06-27 20:53:42 +00:00
for ( Message message : list ) {
String B = message . B ( ) ;
if ( B = = null | | ! this . componentInteractions . containsKey ( B ) ) {
Interaction t = message . t ( ) ;
2021-06-27 20:44:35 +00:00
ApplicationCommandLocalSendData applicationCommandLocalSendData = null ;
2021-06-27 20:53:42 +00:00
Long a = t ! = null ? t . a ( ) : null ;
if ( ! ( B = = null | | t . isBlank ( B ) ) & & this . applicationCommandLocalSendDataSet . containsKey ( B ) ) {
applicationCommandLocalSendData = this . applicationCommandLocalSendDataSet . get ( B ) ;
2021-06-27 20:44:35 +00:00
} else if ( a ! = null ) {
Iterator < T > it = this . applicationCommandLocalSendDataSet . values ( ) . iterator ( ) ;
while ( true ) {
if ( ! it . hasNext ( ) ) {
break ;
}
Object next = it . next ( ) ;
if ( m . areEqual ( ( ( ApplicationCommandLocalSendData ) next ) . getInteractionId ( ) , a ) ) {
applicationCommandLocalSendData = next ;
break ;
}
}
applicationCommandLocalSendData = applicationCommandLocalSendData ;
}
if ( applicationCommandLocalSendData ! = null ) {
removeApplicationCommandSendData ( applicationCommandLocalSendData . getNonceString ( ) ) ;
this . storeMessages . deleteLocalMessage ( applicationCommandLocalSendData . getChannelId ( ) , applicationCommandLocalSendData . getNonceString ( ) ) ;
}
} else {
2021-06-27 20:53:42 +00:00
ComponentLocation componentLocation = this . componentInteractions . get ( B ) ;
2021-06-27 20:44:35 +00:00
if ( componentLocation ! = null ) {
handleComponentInteractionMessage ( componentLocation ) ;
2021-06-27 20:53:42 +00:00
this . componentInteractions . remove ( B ) ;
2021-06-27 20:44:35 +00:00
} else {
return ;
}
}
}
}
@StoreThread
public final void handlePreLogout ( ) {
this . applicationCommandLocalSendDataSet . clear ( ) ;
markChanged ( ) ;
}
@Override // com.discord.stores.Store
@StoreThread
public void init ( Context context ) {
m . checkNotNullParameter ( context , " context " ) ;
super . init ( context ) ;
loadCachedApplicationCommandSendDataSet ( ) ;
}
public final Observable < Map < Long , Map < Integer , InteractionSendState > > > observeComponentInteractionState ( ) {
Observable < Map < Long , Map < Integer , InteractionSendState > > > s2 = ObservationDeck . connectRx$default ( this . observationDeck , new ObservationDeck . UpdateSource [ ] { ComponentStateUpdate } , false , null , null , new StoreApplicationInteractions$observeComponentInteractionState$1 ( this ) , 14 , null ) . s ( ) ;
m . checkNotNullExpressionValue ( s2 , " observationDeck.connectR… }.distinctUntilChanged() " ) ;
return s2 ;
}
public final Observable < State > observeInteractionData ( long j ) {
Observable < State > s2 = ObservationDeck . connectRx$default ( this . observationDeck , new ObservationDeck . UpdateSource [ ] { this } , false , null , null , new StoreApplicationInteractions$observeInteractionData$1 ( this , j ) , 14 , null ) . s ( ) ;
m . checkNotNullExpressionValue ( s2 , " observationDeck.connectR… }.distinctUntilChanged() " ) ;
return s2 ;
}
2021-06-27 20:53:42 +00:00
public final void resendApplicationCommand ( Message message ) {
String B ;
ApplicationCommandLocalSendData applicationCommandLocalSendData ;
m . checkNotNullParameter ( message , " message " ) ;
Integer M = message . M ( ) ;
if ( M ! = null & & M . intValue ( ) = = - 4 & & ( B = message . B ( ) ) ! = null & & ( applicationCommandLocalSendData = this . applicationCommandLocalSendDataSnapshot . get ( B ) ) ! = null ) {
this . dispatcher . schedule ( new StoreApplicationInteractions$resendApplicationCommand$1 ( this , message , B , ApplicationCommandLocalSendData . copy$default ( applicationCommandLocalSendData , NonceGenerator . Companion . computeNonce$default ( NonceGenerator . Companion , null , 1 , null ) , 0 , null , null , null , null , null , null , null , null , 510 , null ) ) ) ;
2021-06-27 20:44:35 +00:00
}
}
public final void sendApplicationCommand ( long j , Long l , String str , com . discord . widgets . chat . input . ApplicationCommandData applicationCommandData , Function0 < Unit > function0 , Function1 < ? super Error , Unit > function1 ) {
m . checkNotNullParameter ( applicationCommandData , " data " ) ;
m . checkNotNullParameter ( function0 , " onSuccess " ) ;
m . checkNotNullParameter ( function1 , " onFail " ) ;
this . dispatcher . schedule ( new StoreApplicationInteractions$sendApplicationCommand$1 ( this , new ApplicationCommandLocalSendData ( this . nonceGenerator . nonce ( ) , j , l , applicationCommandData . getApplicationCommand ( ) . getGuildId ( ) , applicationCommandData . getApplication ( ) , applicationCommandData . getApplicationCommand ( ) . getName ( ) , applicationCommandData . getApplicationCommand ( ) . getId ( ) , applicationCommandData . getValues ( ) , str , null , 512 , null ) , function0 , function1 ) ) ;
}
public final void sendComponentInteraction ( long j , Long l , long j2 , long j3 , int i , RestAPIParams . ComponentInteractionData componentInteractionData , Long l2 ) {
m . checkNotNullParameter ( componentInteractionData , " data " ) ;
this . dispatcher . schedule ( new StoreApplicationInteractions$sendComponentInteraction$1 ( this , j3 , i , String . valueOf ( this . nonceGenerator . nonce ( ) ) , j , l , j2 , l2 , componentInteractionData ) ) ;
}
public final void setInteractionComponentSendStateSnapshot ( Map < Long , ? extends Map < Integer , ? extends InteractionSendState > > map ) {
m . checkNotNullParameter ( map , " <set-?> " ) ;
this . interactionComponentSendStateSnapshot = map ;
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData ( ) {
super . snapshotData ( ) ;
this . interactionDataSnapshot = new HashMap ( this . interactionData ) ;
this . interactionComponentSendStateSnapshot = new HashMap ( this . interactionComponentSendState ) ;
HashMap hashMap = new HashMap ( this . applicationCommandLocalSendDataSet ) ;
this . applicationCommandLocalSendDataSnapshot = hashMap ;
String m = this . gson . m ( hashMap ) ;
SharedPreferences . Editor edit = this . sharedPrefs . edit ( ) ;
m . checkExpressionValueIsNotNull ( edit , " editor " ) ;
edit . putString ( " CACHE_KEY_APPLICATION_COMMAND_SEND_DATA_SET " , m ) ;
edit . apply ( ) ;
}
}