2021-08-09 22:50:52 +00:00
package com.discord.stores ;
import android.content.Context ;
import c.d.b.a.a ;
import com.discord.models.domain.ModelUserNote ;
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 ;
2021-11-01 07:19:03 +00:00
import d0.g0.t ;
import d0.t.h0 ;
import d0.z.d.m ;
2021-08-09 22:50:52 +00:00
import java.util.HashMap ;
import java.util.Map ;
import kotlin.jvm.functions.Function0 ;
import kotlin.jvm.functions.Function1 ;
import kotlin.jvm.internal.DefaultConstructorMarker ;
import rx.Observable ;
/* compiled from: StoreUserNotes.kt */
public final class StoreUserNotes extends StoreV2 {
private final Dispatcher dispatcher ;
private final Map < Long , UserNoteState > notesByUserId ;
private Map < Long , ? extends UserNoteState > notesByUserIdSnapshot ;
private final ObservationDeck observationDeck ;
private final RestAPI restAPI ;
/* compiled from: StoreUserNotes.kt */
public static abstract class UserNoteState {
/* compiled from: StoreUserNotes.kt */
public static final class Empty extends UserNoteState {
public static final Empty INSTANCE = new Empty ( ) ;
private Empty ( ) {
super ( null ) ;
}
}
/* compiled from: StoreUserNotes.kt */
public static final class Loaded extends UserNoteState {
private final ModelUserNote note ;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded ( ModelUserNote modelUserNote ) {
super ( null ) ;
m . checkNotNullParameter ( modelUserNote , " note " ) ;
this . note = modelUserNote ;
}
public static /* synthetic */ Loaded copy$default ( Loaded loaded , ModelUserNote modelUserNote , int i , Object obj ) {
if ( ( i & 1 ) ! = 0 ) {
modelUserNote = loaded . note ;
}
return loaded . copy ( modelUserNote ) ;
}
public final ModelUserNote component1 ( ) {
return this . note ;
}
public final Loaded copy ( ModelUserNote modelUserNote ) {
m . checkNotNullParameter ( modelUserNote , " note " ) ;
return new Loaded ( modelUserNote ) ;
}
public boolean equals ( Object obj ) {
if ( this ! = obj ) {
return ( obj instanceof Loaded ) & & m . areEqual ( this . note , ( ( Loaded ) obj ) . note ) ;
}
return true ;
}
public final ModelUserNote getNote ( ) {
return this . note ;
}
public int hashCode ( ) {
ModelUserNote modelUserNote = this . note ;
if ( modelUserNote ! = null ) {
return modelUserNote . hashCode ( ) ;
}
return 0 ;
}
public String toString ( ) {
2021-11-05 21:05:33 +00:00
StringBuilder R = a . R ( " Loaded(note= " ) ;
R . append ( this . note ) ;
R . append ( " ) " ) ;
return R . toString ( ) ;
2021-08-09 22:50:52 +00:00
}
}
/* compiled from: StoreUserNotes.kt */
public static final class Loading extends UserNoteState {
public static final Loading INSTANCE = new Loading ( ) ;
private Loading ( ) {
super ( null ) ;
}
}
private UserNoteState ( ) {
}
public /* synthetic */ UserNoteState ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
}
public StoreUserNotes ( Dispatcher dispatcher , RestAPI restAPI , ObservationDeck observationDeck ) {
m . checkNotNullParameter ( dispatcher , " dispatcher " ) ;
m . checkNotNullParameter ( restAPI , " restAPI " ) ;
m . checkNotNullParameter ( observationDeck , " observationDeck " ) ;
this . dispatcher = dispatcher ;
this . restAPI = restAPI ;
this . observationDeck = observationDeck ;
this . notesByUserId = new HashMap ( ) ;
this . notesByUserIdSnapshot = h0 . emptyMap ( ) ;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreUserNotes ( Dispatcher dispatcher , RestAPI restAPI , ObservationDeck observationDeck , int i , DefaultConstructorMarker defaultConstructorMarker ) {
this ( dispatcher , ( i & 2 ) ! = 0 ? RestAPI . Companion . getApi ( ) : restAPI , ( i & 4 ) ! = 0 ? ObservationDeckProvider . get ( ) : observationDeck ) ;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p ( StoreUserNotes storeUserNotes ) {
return storeUserNotes . dispatcher ;
}
public static final /* synthetic */ Map access$getNotesByUserId$p ( StoreUserNotes storeUserNotes ) {
return storeUserNotes . notesByUserId ;
}
public static final /* synthetic */ RestAPI access$getRestAPI$p ( StoreUserNotes storeUserNotes ) {
return storeUserNotes . restAPI ;
}
public static final /* synthetic */ void access$handleRequestUserNoteError ( StoreUserNotes storeUserNotes , long j ) {
storeUserNotes . handleRequestUserNoteError ( j ) ;
}
public static final /* synthetic */ void access$handleRequestUserNoteSuccess ( StoreUserNotes storeUserNotes , ModelUserNote modelUserNote ) {
storeUserNotes . handleRequestUserNoteSuccess ( modelUserNote ) ;
}
public static final /* synthetic */ void access$updateNoteInternal ( StoreUserNotes storeUserNotes , long j , String str ) {
storeUserNotes . updateNoteInternal ( j , str ) ;
}
@StoreThread
private final void handleRequestUserNoteError ( long j ) {
this . notesByUserId . put ( Long . valueOf ( j ) , UserNoteState . Empty . INSTANCE ) ;
markChanged ( ) ;
}
@StoreThread
private final void handleRequestUserNoteSuccess ( ModelUserNote modelUserNote ) {
2021-11-19 19:19:27 +00:00
long noteUserId = modelUserNote . getNoteUserId ( ) ;
String note = modelUserNote . getNote ( ) ;
if ( note = = null ) {
note = " " ;
}
updateNoteInternal ( noteUserId , note ) ;
2021-08-09 22:50:52 +00:00
}
@StoreThread
private final void updateNoteInternal ( long j , String str ) {
if ( t . isBlank ( str ) ) {
this . notesByUserId . put ( Long . valueOf ( j ) , UserNoteState . Empty . INSTANCE ) ;
} else {
this . notesByUserId . put ( Long . valueOf ( j ) , new UserNoteState . Loaded ( new ModelUserNote ( j , str ) ) ) ;
}
markChanged ( ) ;
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends com.discord.stores.StoreUserNotes$UserNoteState>, java.util.Map<java.lang.Long, com.discord.stores.StoreUserNotes$UserNoteState> */
public final Map < Long , UserNoteState > getNotesByUserId ( ) {
return this . notesByUserIdSnapshot ;
}
@StoreThread
public final void handleConnectionOpen ( ) {
this . notesByUserId . clear ( ) ;
markChanged ( ) ;
}
@StoreThread
public final void handleNoteUpdate ( ModelUserNote . Update update ) {
m . checkNotNullParameter ( update , " update " ) ;
updateNoteInternal ( update . getId ( ) , update . getNote ( ) ) ;
}
public final void loadNote ( long j ) {
this . dispatcher . schedule ( new StoreUserNotes$loadNote$1 ( this , j ) ) ;
}
public final Observable < UserNoteState > observeUserNote ( long j ) {
2021-10-18 07:12:10 +00:00
Observable < UserNoteState > q = ObservationDeck . connectRx$default ( this . observationDeck , new ObservationDeck . UpdateSource [ ] { this } , false , null , null , new StoreUserNotes$observeUserNote$1 ( this , j ) , 14 , null ) . q ( ) ;
m . checkNotNullExpressionValue ( q , " observationDeck.connectR… }.distinctUntilChanged() " ) ;
return q ;
2021-08-09 22:50:52 +00:00
}
public final void saveNote ( Context context , long j , String str ) {
m . checkNotNullParameter ( str , " note " ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . restSubscribeOn$default ( this . restAPI . updateUserNotes ( j , new RestAPIParams . UserNoteUpdate ( str ) ) , false , 1 , null ) , StoreUserNotes . class , context , ( Function1 ) null , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , new StoreUserNotes$saveNote$1 ( this , j , str ) , 60 , ( Object ) null ) ;
}
@Override // com.discord.stores.StoreV2
public void snapshotData ( ) {
super . snapshotData ( ) ;
this . notesByUserIdSnapshot = new HashMap ( this . notesByUserId ) ;
}
}