2021-08-09 22:50:52 +00:00
package com.discord.stores ;
2021-10-18 07:12:10 +00:00
import c0.d0.f ;
import c0.t.g0 ;
import c0.t.h0 ;
import c0.t.n ;
import c0.t.o ;
import c0.z.d.m ;
2021-08-09 22:50:52 +00:00
import com.discord.api.emoji.GuildEmoji ;
import com.discord.api.emoji.GuildEmojisUpdate ;
import com.discord.api.guild.Guild ;
import com.discord.models.domain.ModelPayload ;
import com.discord.models.domain.emoji.ModelEmojiCustom ;
import com.discord.models.member.GuildMember ;
import com.discord.utilities.persister.Persister ;
import java.util.ArrayList ;
import java.util.Collection ;
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.internal.DefaultConstructorMarker ;
import rx.Observable ;
/* compiled from: StoreEmojiCustom.kt */
public final class StoreEmojiCustom extends StoreV2 {
public static final Companion Companion = new Companion ( null ) ;
private static final long NO_ROLE = 0 ;
private final Map < Long , Map < Long , ModelEmojiCustom > > allGuildEmoji = new LinkedHashMap ( ) ;
private Map < Long , ? extends Map < Long , ? extends ModelEmojiCustom > > allGuildEmojiSnapshot = h0 . emptyMap ( ) ;
private final Persister < Map < Long , Map < Long , ModelEmojiCustom > > > allowedGuildEmojiPersister = new Persister < > ( " STORE_EMOJI_AVAILABLE_V5 " , new HashMap ( ) ) ;
private final Map < Long , Map < Long , Map < Long , ModelEmojiCustom > > > allowedGuildEmojis = new LinkedHashMap ( ) ;
/* renamed from: me reason: collision with root package name */
2021-10-25 07:24:42 +00:00
private long f2600me ;
2021-08-09 22:50:52 +00:00
private final StoreStream stream ;
/* compiled from: StoreEmojiCustom.kt */
public static final class Companion {
private Companion ( ) {
}
public /* synthetic */ Companion ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
}
public StoreEmojiCustom ( StoreStream storeStream ) {
m . checkNotNullParameter ( storeStream , " stream " ) ;
this . stream = storeStream ;
}
private final void updateAllowedGuildEmojis ( long j , List < Long > list , Collection < ? extends ModelEmojiCustom > collection ) {
Object obj ;
Map < Long , Map < Long , Map < Long , ModelEmojiCustom > > > map = this . allowedGuildEmojis ;
Long valueOf = Long . valueOf ( j ) ;
Map < Long , Map < Long , ModelEmojiCustom > > map2 = map . get ( valueOf ) ;
if ( map2 = = null ) {
map2 = new HashMap < > ( ) ;
map . put ( valueOf , map2 ) ;
}
Map < Long , Map < Long , ModelEmojiCustom > > map3 = map2 ;
map3 . clear ( ) ;
StoreEmojiCustom$updateAllowedGuildEmojis$1 storeEmojiCustom$updateAllowedGuildEmojis$1 = new StoreEmojiCustom$updateAllowedGuildEmojis$1 ( this , map3 ) ;
for ( ModelEmojiCustom modelEmojiCustom : collection ) {
List < Long > roles = modelEmojiCustom . getRoles ( ) ;
if ( roles . isEmpty ( ) ) {
storeEmojiCustom$updateAllowedGuildEmojis$1 . invoke ( 0 , modelEmojiCustom ) ;
} else {
Iterator < T > it = list . iterator ( ) ;
while ( true ) {
if ( ! it . hasNext ( ) ) {
obj = null ;
break ;
}
obj = it . next ( ) ;
if ( roles . contains ( Long . valueOf ( ( ( Number ) obj ) . longValue ( ) ) ) ) {
break ;
}
}
Long l = ( Long ) obj ;
if ( l ! = null ) {
storeEmojiCustom$updateAllowedGuildEmojis$1 . invoke ( l . longValue ( ) , modelEmojiCustom ) ;
}
}
}
}
private final void updateGlobalEmojis ( long j , Collection < ? extends ModelEmojiCustom > collection ) {
if ( collection . isEmpty ( ) ) {
this . allGuildEmoji . remove ( Long . valueOf ( j ) ) ;
} else {
Map < Long , Map < Long , ModelEmojiCustom > > map = this . allGuildEmoji ;
Long valueOf = Long . valueOf ( j ) ;
LinkedHashMap linkedHashMap = new LinkedHashMap ( f . coerceAtLeast ( g0 . mapCapacity ( o . collectionSizeOrDefault ( collection , 10 ) ) , 16 ) ) ;
for ( Object obj : collection ) {
linkedHashMap . put ( Long . valueOf ( ( ( ModelEmojiCustom ) obj ) . getId ( ) ) , obj ) ;
}
map . put ( valueOf , linkedHashMap ) ;
}
markChanged ( ) ;
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends java.util.Map<java.lang.Long, ? extends com.discord.models.domain.emoji.ModelEmojiCustom>>, java.util.Map<java.lang.Long, java.util.Map<java.lang.Long, com.discord.models.domain.emoji.ModelEmojiCustom>> */
public final Map < Long , Map < Long , ModelEmojiCustom > > getAllGuildEmoji ( ) {
return this . allGuildEmojiSnapshot ;
}
@StoreThread
public final Map < Long , Map < Long , ModelEmojiCustom > > getAllGuildEmojiInternal ( ) {
return this . allGuildEmoji ;
}
public final Map < Long , ModelEmojiCustom > getEmojiForGuild ( long j ) {
Map < Long , ModelEmojiCustom > map = getAllGuildEmoji ( ) . get ( Long . valueOf ( j ) ) ;
return map ! = null ? map : h0 . emptyMap ( ) ;
}
@StoreThread
public final Map < Long , ModelEmojiCustom > getEmojiForGuildInternal ( long j ) {
return this . allGuildEmoji . get ( Long . valueOf ( j ) ) ;
}
@StoreThread
public final void handleConnectionOpen ( ModelPayload modelPayload ) {
m . checkNotNullParameter ( modelPayload , " payload " ) ;
2021-10-25 07:24:42 +00:00
this . f2600me = modelPayload . getMe ( ) . i ( ) ;
2021-08-09 22:50:52 +00:00
for ( Guild guild : modelPayload . getGuilds ( ) ) {
m . checkNotNullExpressionValue ( guild , " guild " ) ;
handleGuildAdd ( guild ) ;
}
}
@StoreThread
public final void handleEmojiUpdate ( GuildEmojisUpdate guildEmojisUpdate ) {
GuildMember guildMember ;
m . checkNotNullParameter ( guildEmojisUpdate , " emojiUpdate " ) ;
long c2 = guildEmojisUpdate . c ( ) ;
Map < Long , GuildMember > map = this . stream . getGuilds$app_productionBetaRelease ( ) . getGuildMembersComputedInternal$app_productionBetaRelease ( ) . get ( Long . valueOf ( c2 ) ) ;
List < GuildEmoji > a = guildEmojisUpdate . a ( ) ;
ArrayList arrayList = new ArrayList ( o . collectionSizeOrDefault ( a , 10 ) ) ;
for ( GuildEmoji guildEmoji : a ) {
arrayList . add ( new ModelEmojiCustom ( guildEmoji , c2 ) ) ;
}
2021-10-25 07:24:42 +00:00
if ( ! ( map = = null | | ( guildMember = map . get ( Long . valueOf ( this . f2600me ) ) ) = = null ) ) {
2021-08-09 22:50:52 +00:00
updateGlobalEmojis ( c2 , arrayList ) ;
updateAllowedGuildEmojis ( c2 , guildMember . getRoles ( ) , arrayList ) ;
}
}
@StoreThread
public final Unit handleGuildAdd ( Guild guild ) {
Object obj ;
Collection < ? extends ModelEmojiCustom > collection ;
boolean z2 ;
m . checkNotNullParameter ( guild , " guild " ) ;
2021-08-18 07:29:27 +00:00
List < com . discord . api . guildmember . GuildMember > t = guild . t ( ) ;
if ( t = = null ) {
2021-08-09 22:50:52 +00:00
return null ;
}
2021-08-18 07:29:27 +00:00
Iterator < T > it = t . iterator ( ) ;
2021-08-09 22:50:52 +00:00
while ( true ) {
if ( ! it . hasNext ( ) ) {
obj = null ;
break ;
}
obj = it . next ( ) ;
2021-10-25 07:24:42 +00:00
if ( ( ( com . discord . api . guildmember . GuildMember ) obj ) . j ( ) . i ( ) = = this . f2600me ) {
2021-08-09 22:50:52 +00:00
z2 = true ;
continue ;
} else {
z2 = false ;
continue ;
}
if ( z2 ) {
break ;
}
}
com . discord . api . guildmember . GuildMember guildMember = ( com . discord . api . guildmember . GuildMember ) obj ;
if ( guildMember = = null ) {
return null ;
}
2021-08-18 07:29:27 +00:00
long p = guild . p ( ) ;
2021-08-09 22:50:52 +00:00
List < GuildEmoji > j = guild . j ( ) ;
if ( j ! = null ) {
collection = new ArrayList < > ( o . collectionSizeOrDefault ( j , 10 ) ) ;
for ( GuildEmoji guildEmoji : j ) {
2021-08-18 07:29:27 +00:00
collection . add ( new ModelEmojiCustom ( guildEmoji , p ) ) ;
2021-08-09 22:50:52 +00:00
}
} else {
collection = n . emptyList ( ) ;
}
2021-08-18 07:29:27 +00:00
updateGlobalEmojis ( p , collection ) ;
updateAllowedGuildEmojis ( p , guildMember . i ( ) , collection ) ;
2021-08-09 22:50:52 +00:00
return Unit . a ;
}
@StoreThread
public final void handleGuildMemberAdd ( com . discord . api . guildmember . GuildMember guildMember ) {
Collection < ModelEmojiCustom > values ;
m . checkNotNullParameter ( guildMember , " member " ) ;
2021-10-25 07:24:42 +00:00
if ( guildMember . j ( ) . i ( ) = = this . f2600me ) {
2021-08-09 22:50:52 +00:00
long c2 = guildMember . c ( ) ;
Map < Long , ModelEmojiCustom > map = this . allGuildEmoji . get ( Long . valueOf ( c2 ) ) ;
if ( map ! = null & & ( values = map . values ( ) ) ! = null ) {
updateAllowedGuildEmojis ( c2 , guildMember . i ( ) , values ) ;
}
}
}
@StoreThread
public final void handleGuildRemove ( Guild guild ) {
m . checkNotNullParameter ( guild , " guild " ) ;
2021-08-18 07:29:27 +00:00
long p = guild . p ( ) ;
if ( this . allowedGuildEmojis . containsKey ( Long . valueOf ( p ) ) ) {
this . allowedGuildEmojis . remove ( Long . valueOf ( p ) ) ;
2021-08-09 22:50:52 +00:00
markChanged ( ) ;
}
2021-08-18 07:29:27 +00:00
if ( this . allGuildEmoji . containsKey ( Long . valueOf ( p ) ) ) {
this . allGuildEmoji . remove ( Long . valueOf ( p ) ) ;
2021-08-09 22:50:52 +00:00
markChanged ( ) ;
}
}
public final Observable < Map < Long , Map < Long , ModelEmojiCustom > > > observeAllowedGuildEmoji ( ) {
return this . allowedGuildEmojiPersister . getObservable ( ) ;
}
@Override // com.discord.stores.StoreV2
public void snapshotData ( ) {
super . snapshotData ( ) ;
LinkedHashMap linkedHashMap = new LinkedHashMap ( ) ;
for ( Map . Entry < Long , Map < Long , ModelEmojiCustom > > entry : this . allGuildEmoji . entrySet ( ) ) {
linkedHashMap . put ( Long . valueOf ( entry . getKey ( ) . longValue ( ) ) , h0 . toMap ( entry . getValue ( ) ) ) ;
}
this . allGuildEmojiSnapshot = linkedHashMap ;
LinkedHashMap linkedHashMap2 = new LinkedHashMap ( ) ;
for ( Map . Entry < Long , Map < Long , Map < Long , ModelEmojiCustom > > > entry2 : this . allowedGuildEmojis . entrySet ( ) ) {
long longValue = entry2 . getKey ( ) . longValue ( ) ;
LinkedHashMap linkedHashMap3 = new LinkedHashMap ( ) ;
for ( Map . Entry < Long , Map < Long , ModelEmojiCustom > > entry3 : entry2 . getValue ( ) . entrySet ( ) ) {
linkedHashMap3 . putAll ( entry3 . getValue ( ) ) ;
}
linkedHashMap2 . put ( Long . valueOf ( longValue ) , linkedHashMap3 ) ;
}
Persister . set$default ( this . allowedGuildEmojiPersister , linkedHashMap2 , false , 2 , null ) ;
}
}