2021-06-27 20:44:35 +00:00
package com.discord.stores ;
import a0.a.a.b ;
import android.content.Context ;
import c.d.b.a.a ;
import com.discord.models.domain.ModelGuildFolder ;
import com.discord.models.guild.Guild ;
import com.discord.stores.StoreStream ;
import com.discord.stores.updates.ObservationDeck ;
import com.discord.utilities.rx.ObservableExtensionsKt ;
import d0.t.n ;
import d0.t.o ;
import d0.t.r ;
import d0.t.u ;
import d0.z.d.m ;
import java.util.ArrayList ;
import java.util.HashSet ;
import java.util.LinkedHashMap ;
import java.util.List ;
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 ;
/* compiled from: StoreGuildsSorted.kt */
public final class StoreGuildsSorted extends StoreV2 {
private final Dispatcher dispatcher ;
private final List < Entry > entries = new ArrayList ( ) ;
private List < ? extends Entry > entriesSnapshot = n . emptyList ( ) ;
private final StoreGuilds guildStore ;
private final StoreLurking lurkingGuildStore ;
private final ObservationDeck observationDeck ;
private final List < ModelGuildFolder > positions = new ArrayList ( ) ;
/* compiled from: StoreGuildsSorted.kt */
public static abstract class Entry {
/* compiled from: StoreGuildsSorted.kt */
public static final class Folder extends Entry {
private final Integer color ;
private final List < Guild > guilds ;
/* renamed from: id reason: collision with root package name */
2021-07-04 15:26:29 +00:00
private final long f2104id ;
2021-06-27 20:44:35 +00:00
private final String name ;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Folder ( long j , List < Guild > list , Integer num , String str ) {
super ( null ) ;
m . checkNotNullParameter ( list , " guilds " ) ;
2021-07-04 15:26:29 +00:00
this . f2104id = j ;
2021-06-27 20:44:35 +00:00
this . guilds = list ;
this . color = num ;
this . name = str ;
}
/* JADX DEBUG: Multi-variable search result rejected for r6v0, resolved type: com.discord.stores.StoreGuildsSorted$Entry$Folder */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Folder copy$default ( Folder folder , long j , List list , Integer num , String str , int i , Object obj ) {
if ( ( i & 1 ) ! = 0 ) {
2021-07-04 15:26:29 +00:00
j = folder . f2104id ;
2021-06-27 20:44:35 +00:00
}
if ( ( i & 2 ) ! = 0 ) {
list = folder . guilds ;
}
if ( ( i & 4 ) ! = 0 ) {
num = folder . color ;
}
if ( ( i & 8 ) ! = 0 ) {
str = folder . name ;
}
return folder . copy ( j , list , num , str ) ;
}
@Override // com.discord.stores.StoreGuildsSorted.Entry
public ModelGuildFolder asModelGuildFolder ( ) {
2021-07-04 15:26:29 +00:00
Long valueOf = Long . valueOf ( this . f2104id ) ;
2021-06-27 20:44:35 +00:00
List < Guild > list = this . guilds ;
ArrayList arrayList = new ArrayList ( o . collectionSizeOrDefault ( list , 10 ) ) ;
for ( Guild guild : list ) {
arrayList . add ( Long . valueOf ( guild . getId ( ) ) ) ;
}
return new ModelGuildFolder ( valueOf , arrayList , this . color , this . name ) ;
}
public final long component1 ( ) {
2021-07-04 15:26:29 +00:00
return this . f2104id ;
2021-06-27 20:44:35 +00:00
}
public final List < Guild > component2 ( ) {
return this . guilds ;
}
public final Integer component3 ( ) {
return this . color ;
}
public final String component4 ( ) {
return this . name ;
}
public final Folder copy ( long j , List < Guild > list , Integer num , String str ) {
m . checkNotNullParameter ( list , " guilds " ) ;
return new Folder ( j , list , num , str ) ;
}
public boolean equals ( Object obj ) {
if ( this = = obj ) {
return true ;
}
if ( ! ( obj instanceof Folder ) ) {
return false ;
}
Folder folder = ( Folder ) obj ;
2021-07-04 15:26:29 +00:00
return this . f2104id = = folder . f2104id & & m . areEqual ( this . guilds , folder . guilds ) & & m . areEqual ( this . color , folder . color ) & & m . areEqual ( this . name , folder . name ) ;
2021-06-27 20:44:35 +00:00
}
public final Integer getColor ( ) {
return this . color ;
}
public final List < Guild > getGuilds ( ) {
return this . guilds ;
}
public final long getId ( ) {
2021-07-04 15:26:29 +00:00
return this . f2104id ;
2021-06-27 20:44:35 +00:00
}
public final String getName ( ) {
return this . name ;
}
public int hashCode ( ) {
2021-07-04 15:26:29 +00:00
int a = b . a ( this . f2104id ) * 31 ;
2021-06-27 20:44:35 +00:00
List < Guild > list = this . guilds ;
int i = 0 ;
int hashCode = ( a + ( list ! = null ? list . hashCode ( ) : 0 ) ) * 31 ;
Integer num = this . color ;
int hashCode2 = ( hashCode + ( num ! = null ? num . hashCode ( ) : 0 ) ) * 31 ;
String str = this . name ;
if ( str ! = null ) {
i = str . hashCode ( ) ;
}
return hashCode2 + i ;
}
public String toString ( ) {
StringBuilder L = a . L ( " Folder(id= " ) ;
2021-07-04 15:26:29 +00:00
L . append ( this . f2104id ) ;
2021-06-27 20:44:35 +00:00
L . append ( " , guilds= " ) ;
L . append ( this . guilds ) ;
L . append ( " , color= " ) ;
L . append ( this . color ) ;
L . append ( " , name= " ) ;
return a . D ( L , this . name , " ) " ) ;
}
}
/* compiled from: StoreGuildsSorted.kt */
public static final class SingletonGuild extends Entry {
private final Guild guild ;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public SingletonGuild ( Guild guild ) {
super ( null ) ;
m . checkNotNullParameter ( guild , " guild " ) ;
this . guild = guild ;
}
public static /* synthetic */ SingletonGuild copy$default ( SingletonGuild singletonGuild , Guild guild , int i , Object obj ) {
if ( ( i & 1 ) ! = 0 ) {
guild = singletonGuild . guild ;
}
return singletonGuild . copy ( guild ) ;
}
@Override // com.discord.stores.StoreGuildsSorted.Entry
public ModelGuildFolder asModelGuildFolder ( ) {
return new ModelGuildFolder ( null , d0 . t . m . listOf ( Long . valueOf ( this . guild . getId ( ) ) ) , null , null , 8 , null ) ;
}
public final Guild component1 ( ) {
return this . guild ;
}
public final SingletonGuild copy ( Guild guild ) {
m . checkNotNullParameter ( guild , " guild " ) ;
return new SingletonGuild ( guild ) ;
}
public boolean equals ( Object obj ) {
if ( this ! = obj ) {
return ( obj instanceof SingletonGuild ) & & m . areEqual ( this . guild , ( ( SingletonGuild ) obj ) . guild ) ;
}
return true ;
}
public final Guild getGuild ( ) {
return this . guild ;
}
public int hashCode ( ) {
Guild guild = this . guild ;
if ( guild ! = null ) {
return guild . hashCode ( ) ;
}
return 0 ;
}
public String toString ( ) {
StringBuilder L = a . L ( " SingletonGuild(guild= " ) ;
L . append ( this . guild ) ;
L . append ( " ) " ) ;
return L . toString ( ) ;
}
}
private Entry ( ) {
}
public /* synthetic */ Entry ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
public abstract ModelGuildFolder asModelGuildFolder ( ) ;
}
/* compiled from: StoreGuildsSorted.kt */
public static final class State {
private final Map < Long , Long > joinedAt ;
private final Set < Long > mutedGuilds ;
private final List < ModelGuildFolder > userSettingsGuildPositions ;
public State ( Set < Long > set , Map < Long , Long > map , List < ModelGuildFolder > list ) {
m . checkNotNullParameter ( set , " mutedGuilds " ) ;
m . checkNotNullParameter ( map , " joinedAt " ) ;
m . checkNotNullParameter ( list , " userSettingsGuildPositions " ) ;
this . mutedGuilds = set ;
this . joinedAt = map ;
this . userSettingsGuildPositions = list ;
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreGuildsSorted$State */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ State copy$default ( State state , Set set , Map map , List list , int i , Object obj ) {
if ( ( i & 1 ) ! = 0 ) {
set = state . mutedGuilds ;
}
if ( ( i & 2 ) ! = 0 ) {
map = state . joinedAt ;
}
if ( ( i & 4 ) ! = 0 ) {
list = state . userSettingsGuildPositions ;
}
return state . copy ( set , map , list ) ;
}
public final Set < Long > component1 ( ) {
return this . mutedGuilds ;
}
public final Map < Long , Long > component2 ( ) {
return this . joinedAt ;
}
public final List < ModelGuildFolder > component3 ( ) {
return this . userSettingsGuildPositions ;
}
public final State copy ( Set < Long > set , Map < Long , Long > map , List < ModelGuildFolder > list ) {
m . checkNotNullParameter ( set , " mutedGuilds " ) ;
m . checkNotNullParameter ( map , " joinedAt " ) ;
m . checkNotNullParameter ( list , " userSettingsGuildPositions " ) ;
return new State ( set , map , list ) ;
}
public boolean equals ( Object obj ) {
if ( this = = obj ) {
return true ;
}
if ( ! ( obj instanceof State ) ) {
return false ;
}
State state = ( State ) obj ;
return m . areEqual ( this . mutedGuilds , state . mutedGuilds ) & & m . areEqual ( this . joinedAt , state . joinedAt ) & & m . areEqual ( this . userSettingsGuildPositions , state . userSettingsGuildPositions ) ;
}
public final Map < Long , Long > getJoinedAt ( ) {
return this . joinedAt ;
}
public final Set < Long > getMutedGuilds ( ) {
return this . mutedGuilds ;
}
public final List < ModelGuildFolder > getUserSettingsGuildPositions ( ) {
return this . userSettingsGuildPositions ;
}
public int hashCode ( ) {
Set < Long > set = this . mutedGuilds ;
int i = 0 ;
int hashCode = ( set ! = null ? set . hashCode ( ) : 0 ) * 31 ;
Map < Long , Long > map = this . joinedAt ;
int hashCode2 = ( hashCode + ( map ! = null ? map . hashCode ( ) : 0 ) ) * 31 ;
List < ModelGuildFolder > list = this . userSettingsGuildPositions ;
if ( list ! = null ) {
i = list . hashCode ( ) ;
}
return hashCode2 + i ;
}
public String toString ( ) {
StringBuilder L = a . L ( " State(mutedGuilds= " ) ;
L . append ( this . mutedGuilds ) ;
L . append ( " , joinedAt= " ) ;
L . append ( this . joinedAt ) ;
L . append ( " , userSettingsGuildPositions= " ) ;
return a . E ( L , this . userSettingsGuildPositions , " ) " ) ;
}
}
public StoreGuildsSorted ( ObservationDeck observationDeck , Dispatcher dispatcher , StoreGuilds storeGuilds , StoreLurking storeLurking ) {
m . checkNotNullParameter ( observationDeck , " observationDeck " ) ;
m . checkNotNullParameter ( dispatcher , " dispatcher " ) ;
m . checkNotNullParameter ( storeGuilds , " guildStore " ) ;
m . checkNotNullParameter ( storeLurking , " lurkingGuildStore " ) ;
this . observationDeck = observationDeck ;
this . dispatcher = dispatcher ;
this . guildStore = storeGuilds ;
this . lurkingGuildStore = storeLurking ;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p ( StoreGuildsSorted storeGuildsSorted ) {
return storeGuildsSorted . dispatcher ;
}
public static final /* synthetic */ void access$handleNewPositionsFromUser ( StoreGuildsSorted storeGuildsSorted , List list ) {
storeGuildsSorted . handleNewPositionsFromUser ( list ) ;
}
public static final /* synthetic */ void access$handleNewState ( StoreGuildsSorted storeGuildsSorted , State state ) {
storeGuildsSorted . handleNewState ( state ) ;
}
@StoreThread
private final void ensureValidPositions ( ) {
Map < Long , Guild > guildsInternal$app_productionBetaRelease = this . guildStore . getGuildsInternal$app_productionBetaRelease ( ) ;
Set < Long > unavailableGuildsInternal$app_productionBetaRelease = this . guildStore . getUnavailableGuildsInternal$app_productionBetaRelease ( ) ;
HashSet hashSet = new HashSet ( ) ;
for ( ModelGuildFolder modelGuildFolder : this . positions ) {
hashSet . addAll ( modelGuildFolder . getGuildIds ( ) ) ;
}
for ( Guild guild : guildsInternal$app_productionBetaRelease . values ( ) ) {
if ( ! hashSet . contains ( Long . valueOf ( guild . getId ( ) ) ) & & ! this . lurkingGuildStore . isLurking$app_productionBetaRelease ( guild ) ) {
this . positions . add ( 0 , new ModelGuildFolder ( null , d0 . t . m . listOf ( Long . valueOf ( guild . getId ( ) ) ) , null , null , 8 , null ) ) ;
}
}
int i = 0 ;
for ( Object obj : this . positions ) {
int i2 = i + 1 ;
if ( i < 0 ) {
n . throwIndexOverflow ( ) ;
}
ModelGuildFolder modelGuildFolder2 = ( ModelGuildFolder ) obj ;
List < Long > guildIds = modelGuildFolder2 . getGuildIds ( ) ;
ArrayList arrayList = new ArrayList ( ) ;
for ( Object obj2 : guildIds ) {
long longValue = ( ( Number ) obj2 ) . longValue ( ) ;
Guild guild2 = guildsInternal$app_productionBetaRelease . get ( Long . valueOf ( longValue ) ) ;
if ( guildsInternal$app_productionBetaRelease . containsKey ( Long . valueOf ( longValue ) ) & & ! unavailableGuildsInternal$app_productionBetaRelease . contains ( Long . valueOf ( longValue ) ) & & guild2 ! = null & & ! this . lurkingGuildStore . isLurking$app_productionBetaRelease ( guild2 ) ) {
arrayList . add ( obj2 ) ;
}
}
this . positions . set ( i , ModelGuildFolder . copy$default ( modelGuildFolder2 , null , arrayList , null , null , 13 , null ) ) ;
i = i2 ;
}
Set < Long > lurkingGuildIdsSync = this . lurkingGuildStore . getLurkingGuildIdsSync ( ) ;
ArrayList < Number > arrayList2 = new ArrayList ( ) ;
for ( Number number : lurkingGuildIdsSync ) {
Guild guild3 = this . guildStore . getGuildsInternal$app_productionBetaRelease ( ) . get ( Long . valueOf ( number . longValue ( ) ) ) ;
Long valueOf = guild3 ! = null ? Long . valueOf ( guild3 . getId ( ) ) : null ;
if ( valueOf ! = null ) {
arrayList2 . add ( valueOf ) ;
}
}
for ( Number number2 : arrayList2 ) {
this . positions . add ( 0 , new ModelGuildFolder ( null , d0 . t . m . listOf ( Long . valueOf ( number2 . longValue ( ) ) ) , null , null , 8 , null ) ) ;
}
r . removeAll ( ( List ) this . positions , ( Function1 ) StoreGuildsSorted$ensureValidPositions$6 . INSTANCE ) ;
}
@StoreThread
private final void handleNewPositionsFromUser ( List < ? extends Entry > list ) {
this . positions . clear ( ) ;
List < ModelGuildFolder > list2 = this . positions ;
ArrayList arrayList = new ArrayList ( o . collectionSizeOrDefault ( list , 10 ) ) ;
for ( Entry entry : list ) {
arrayList . add ( entry . asModelGuildFolder ( ) ) ;
}
list2 . addAll ( arrayList ) ;
ensureValidPositions ( ) ;
rebuildSortedGuilds ( ) ;
}
@StoreThread
private final void handleNewState ( State state ) {
updatePositions ( state ) ;
ensureValidPositions ( ) ;
rebuildSortedGuilds ( ) ;
}
private final Observable < State > observeStores ( ) {
StoreStream . Companion companion = StoreStream . Companion ;
2021-07-03 23:36:06 +00:00
Observable < State > h = Observable . h ( companion . getGuilds ( ) . observeGuilds ( ) , companion . getUserGuildSettings ( ) . observeMutedGuildIds ( ) . F ( StoreGuildsSorted$observeStores$1 . INSTANCE ) , companion . getGuilds ( ) . observeJoinedAt ( ) , companion . getUserSettings ( ) . observeGuildFolders ( ) , StoreGuildsSorted$observeStores$2 . INSTANCE ) ;
2021-06-27 20:44:35 +00:00
m . checkNotNullExpressionValue ( h , " Observable.combineLatest…lds, joinedAt, folders) } " ) ;
return h ;
}
@StoreThread
private final void rebuildSortedGuilds ( ) {
this . entries . clear ( ) ;
for ( ModelGuildFolder modelGuildFolder : this . positions ) {
Long id2 = modelGuildFolder . getId ( ) ;
if ( id2 ! = null ) {
long longValue = id2 . longValue ( ) ;
List < Long > guildIds = modelGuildFolder . getGuildIds ( ) ;
ArrayList arrayList = new ArrayList ( o . collectionSizeOrDefault ( guildIds , 10 ) ) ;
for ( Number number : guildIds ) {
Guild guild = this . guildStore . getGuildsInternal$app_productionBetaRelease ( ) . get ( Long . valueOf ( number . longValue ( ) ) ) ;
m . checkNotNull ( guild ) ;
arrayList . add ( guild ) ;
}
this . entries . add ( new Entry . Folder ( longValue , arrayList , modelGuildFolder . getColor ( ) , modelGuildFolder . getName ( ) ) ) ;
} else {
Guild guild2 = this . guildStore . getGuildsInternal$app_productionBetaRelease ( ) . get ( u . first ( ( List < ? extends Object > ) modelGuildFolder . getGuildIds ( ) ) ) ;
m . checkNotNull ( guild2 ) ;
this . entries . add ( new Entry . SingletonGuild ( guild2 ) ) ;
}
}
markChanged ( ) ;
}
@StoreThread
private final void updatePositions ( State state ) {
this . positions . clear ( ) ;
Map < Long , Guild > guildsInternal$app_productionBetaRelease = this . guildStore . getGuildsInternal$app_productionBetaRelease ( ) ;
if ( ! state . getUserSettingsGuildPositions ( ) . isEmpty ( ) ) {
this . positions . addAll ( state . getUserSettingsGuildPositions ( ) ) ;
return ;
}
List < ModelGuildFolder > list = this . positions ;
List < Number > sortedWith = u . sortedWith ( guildsInternal$app_productionBetaRelease . keySet ( ) , new StoreGuildsSorted$updatePositions$1 ( state , guildsInternal$app_productionBetaRelease ) ) ;
ArrayList arrayList = new ArrayList ( o . collectionSizeOrDefault ( sortedWith , 10 ) ) ;
for ( Number number : sortedWith ) {
arrayList . add ( new ModelGuildFolder ( null , d0 . t . m . listOf ( Long . valueOf ( number . longValue ( ) ) ) , null , null , 8 , null ) ) ;
}
list . addAll ( arrayList ) ;
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.List<? extends com.discord.stores.StoreGuildsSorted$Entry>, java.util.List<com.discord.stores.StoreGuildsSorted$Entry> */
public final List < Entry > getEntries ( ) {
return this . entriesSnapshot ;
}
public final LinkedHashMap < Long , Guild > getOrderedGuilds ( ) {
LinkedHashMap < Long , Guild > linkedHashMap = new LinkedHashMap < > ( ) ;
for ( Entry entry : getEntries ( ) ) {
if ( entry instanceof Entry . SingletonGuild ) {
Entry . SingletonGuild singletonGuild = ( Entry . SingletonGuild ) entry ;
linkedHashMap . put ( Long . valueOf ( singletonGuild . getGuild ( ) . getId ( ) ) , singletonGuild . getGuild ( ) ) ;
} else if ( entry instanceof Entry . Folder ) {
for ( Guild guild : ( ( Entry . Folder ) entry ) . getGuilds ( ) ) {
linkedHashMap . put ( Long . valueOf ( guild . getId ( ) ) , guild ) ;
}
}
}
return linkedHashMap ;
}
@Override // com.discord.stores.Store
public void init ( Context context ) {
m . checkNotNullParameter ( context , " context " ) ;
super . init ( context ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . leadingEdgeThrottle ( ObservableExtensionsKt . computationLatest ( observeStores ( ) ) , 1 , TimeUnit . SECONDS ) , StoreGuildsSorted . class , ( Context ) null , ( Function1 ) null , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , new StoreGuildsSorted$init$1 ( this ) , 62 , ( Object ) null ) ;
}
public final Observable < List < Entry > > observeEntries ( ) {
2021-07-03 23:36:06 +00:00
Observable < List < Entry > > r = ObservationDeck . connectRx$default ( this . observationDeck , new ObservationDeck . UpdateSource [ ] { this } , false , null , null , new StoreGuildsSorted$observeEntries$1 ( this ) , 14 , null ) . r ( ) ;
m . checkNotNullExpressionValue ( r , " observationDeck.connectR… .distinctUntilChanged() " ) ;
return r ;
2021-06-27 20:44:35 +00:00
}
public final Observable < LinkedHashMap < Long , Guild > > observeOrderedGuilds ( ) {
2021-07-03 23:36:06 +00:00
Observable < LinkedHashMap < Long , Guild > > r = ObservationDeck . connectRx$default ( this . observationDeck , new ObservationDeck . UpdateSource [ ] { this } , false , null , null , new StoreGuildsSorted$observeOrderedGuilds$1 ( this ) , 14 , null ) . r ( ) ;
m . checkNotNullExpressionValue ( r , " observationDeck.connectR… .distinctUntilChanged() " ) ;
return r ;
2021-06-27 20:44:35 +00:00
}
public final void setPositions ( List < ? extends Entry > list ) {
m . checkNotNullParameter ( list , " guildPositions " ) ;
this . dispatcher . schedule ( new StoreGuildsSorted$setPositions$1 ( this , list ) ) ;
}
@Override // com.discord.stores.StoreV2
public void snapshotData ( ) {
super . snapshotData ( ) ;
this . entriesSnapshot = new ArrayList ( this . entries ) ;
}
}