2021-08-09 22:50:52 +00:00
package com.discord.utilities.textprocessing ;
2021-08-18 07:29:27 +00:00
import c.a.t.b.c.a ;
2021-08-09 22:50:52 +00:00
import com.airbnb.lottie.parser.AnimatableValueParser ;
import com.discord.api.message.embed.MessageEmbed ;
import com.discord.simpleast.code.CodeNode ;
import com.discord.simpleast.core.node.Node ;
import com.discord.simpleast.core.node.StyleNode ;
import com.discord.stores.StoreMessageState ;
import com.discord.utilities.embed.EmbedResourceUtils ;
import com.discord.utilities.textprocessing.node.BasicRenderContext ;
import com.discord.utilities.textprocessing.node.BlockQuoteNode ;
import com.discord.utilities.textprocessing.node.EmojiNode ;
import com.discord.utilities.textprocessing.node.SpoilerNode ;
import com.discord.utilities.textprocessing.node.UrlNode ;
import d0.g0.t ;
import d0.t.u ;
import d0.z.d.e0 ;
import d0.z.d.m ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Objects ;
import kotlin.jvm.internal.DefaultConstructorMarker ;
/* compiled from: MessagePreprocessor.kt */
public final class MessagePreprocessor implements a {
public static final Companion Companion = new Companion ( null ) ;
private static final int MAX_JUMBO_EMOJI_COUNT = 27 ;
private int customEmojiCount ;
private final List < MessageEmbed > embeds ;
private boolean hasLinkConflictingNode ;
private final Integer maxNodes ;
private final long myUserId ;
private boolean shouldJumboify ;
private List < SpoilerNode < ? > > spoilers ;
private final Collection < Integer > visibleSpoilerNodeIndices ;
/* compiled from: MessagePreprocessor.kt */
public static final class Companion {
private Companion ( ) {
}
public /* synthetic */ Companion ( DefaultConstructorMarker defaultConstructorMarker ) {
this ( ) ;
}
}
/* compiled from: MessagePreprocessor.kt */
public static final class ConstrainState {
private int limit ;
public ConstrainState ( int i ) {
this . limit = i ;
}
public static /* synthetic */ ConstrainState copy$default ( ConstrainState constrainState , int i , int i2 , Object obj ) {
if ( ( i2 & 1 ) ! = 0 ) {
i = constrainState . limit ;
}
return constrainState . copy ( i ) ;
}
public final int component1 ( ) {
return this . limit ;
}
public final ConstrainState copy ( int i ) {
return new ConstrainState ( i ) ;
}
public boolean equals ( Object obj ) {
if ( this ! = obj ) {
return ( obj instanceof ConstrainState ) & & this . limit = = ( ( ConstrainState ) obj ) . limit ;
}
return true ;
}
public final int getLimit ( ) {
return this . limit ;
}
public int hashCode ( ) {
return this . limit ;
}
public final void setLimit ( int i ) {
this . limit = i ;
}
public String toString ( ) {
2021-08-18 07:29:27 +00:00
return c . d . b . a . a . w ( c . d . b . a . a . L ( " ConstrainState(limit= " ) , this . limit , " ) " ) ;
2021-08-09 22:50:52 +00:00
}
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public MessagePreprocessor ( long j , StoreMessageState . State state ) {
this ( j , state ! = null ? state . getVisibleSpoilerNodeIndices ( ) : null , null , false , null , 24 , null ) ;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public MessagePreprocessor ( long j , StoreMessageState . State state , List < MessageEmbed > list , boolean z2 , Integer num ) {
this ( j , state ! = null ? state . getVisibleSpoilerNodeIndices ( ) : null , list , z2 , num ) ;
}
public MessagePreprocessor ( long j , Collection < Integer > collection , List < MessageEmbed > list , boolean z2 , Integer num ) {
this . myUserId = j ;
this . visibleSpoilerNodeIndices = collection ;
this . embeds = list ;
this . shouldJumboify = z2 ;
this . maxNodes = num ;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ MessagePreprocessor ( long j , Collection collection , List list , boolean z2 , Integer num , int i , DefaultConstructorMarker defaultConstructorMarker ) {
this ( j , ( i & 2 ) ! = 0 ? null : collection , ( i & 4 ) ! = 0 ? null : list , ( i & 8 ) ! = 0 ? true : z2 , ( i & 16 ) ! = 0 ? null : num ) ;
}
public static final /* synthetic */ void access$mergeConsecutiveQuoteNodes ( MessagePreprocessor messagePreprocessor , Collection collection ) {
messagePreprocessor . mergeConsecutiveQuoteNodes ( collection ) ;
}
private final < R extends BasicRenderContext > void constrainAST ( Collection < ? extends Node < R > > collection ) {
if ( this . maxNodes ! = null ) {
Objects . requireNonNull ( collection , " null cannot be cast to non-null type kotlin.collections.MutableCollection<com.discord.simpleast.core.node.Node<R>> " ) ;
constrainAST ( e0 . asMutableCollection ( collection ) , new ConstrainState ( this . maxNodes . intValue ( ) ) ) ;
}
}
private final < R extends BasicRenderContext > void constrainAST ( Collection < Node < R > > collection , ConstrainState constrainState ) {
Iterator < Node < R > > it = collection . iterator ( ) ;
while ( it . hasNext ( ) ) {
Node < R > next = it . next ( ) ;
2021-08-18 07:29:27 +00:00
if ( ! m . areEqual ( next . getClass ( ) , c . a . t . b . a . a . class ) ) {
2021-08-09 22:50:52 +00:00
constrainState . setLimit ( constrainState . getLimit ( ) - 1 ) ;
}
if ( constrainState . getLimit ( ) < = 0 ) {
it . remove ( ) ;
} else if ( next . hasChildren ( ) ) {
Collection < Node < R > > children = next . getChildren ( ) ;
Objects . requireNonNull ( children , " null cannot be cast to non-null type kotlin.collections.MutableCollection<com.discord.simpleast.core.node.Node<R>> " ) ;
constrainAST ( e0 . asMutableCollection ( children ) , constrainState ) ;
if ( ! next . hasChildren ( ) ) {
it . remove ( ) ;
}
}
}
}
private final < R extends BasicRenderContext > void mergeConsecutiveQuoteNodes ( Collection < Node < R > > collection ) {
ArrayList arrayList = new ArrayList ( ) ;
Iterator < Node < R > > it = collection . iterator ( ) ;
while ( true ) {
BlockQuoteNode blockQuoteNode = null ;
while ( true ) {
if ( it . hasNext ( ) ) {
Node < R > next = it . next ( ) ;
if ( next instanceof BlockQuoteNode ) {
if ( blockQuoteNode = = null ) {
blockQuoteNode = ( BlockQuoteNode ) next ;
} else {
arrayList . add ( next ) ;
Collection < Node < R > > children = next . getChildren ( ) ;
if ( children ! = null ) {
for ( Node < R > node : children ) {
blockQuoteNode . addChild ( node ) ;
}
}
}
}
} else {
collection . removeAll ( arrayList ) ;
return ;
}
}
}
}
private final < R extends BasicRenderContext > void processQuoteChildren ( Collection < ? extends Node < R > > collection ) {
Objects . requireNonNull ( collection , " null cannot be cast to non-null type kotlin.collections.MutableCollection<com.discord.simpleast.core.node.Node<R>> " ) ;
mergeConsecutiveQuoteNodes ( e0 . asMutableCollection ( collection ) ) ;
MessagePreprocessor$processQuoteChildren$1 messagePreprocessor$processQuoteChildren$1 = new MessagePreprocessor$processQuoteChildren$1 ( this ) ;
Iterator < ? extends Node < R > > it = collection . iterator ( ) ;
while ( it . hasNext ( ) ) {
2021-08-20 10:00:12 +00:00
AnimatableValueParser . M2 ( ( Node ) it . next ( ) , messagePreprocessor$processQuoteChildren$1 ) ;
2021-08-09 22:50:52 +00:00
}
}
private final void processSpoilerChildren ( ) {
List < SpoilerNode < ? > > list = this . spoilers ;
if ( ! ( ! ( list = = null | | list . isEmpty ( ) ) ) ) {
list = null ;
}
if ( list ! = null ) {
ArrayList < SpoilerNode > arrayList = new ArrayList ( ) ;
for ( Object obj : list ) {
if ( ! ( ( SpoilerNode ) obj ) . isRevealed ( ) ) {
arrayList . add ( obj ) ;
}
}
for ( SpoilerNode spoilerNode : arrayList ) {
2021-08-20 10:00:12 +00:00
AnimatableValueParser . K2 ( spoilerNode . getChildren ( ) , MessagePreprocessor$processSpoilerChildren$3$1 . INSTANCE ) ;
2021-08-09 22:50:52 +00:00
}
}
}
private final void stripSimpleEmbedLink ( Collection < Node < MessageRenderContext > > collection ) {
List < MessageEmbed > list ;
if ( collection . size ( ) = = 1 & & ( list = this . embeds ) ! = null & & list . size ( ) = = 1 ) {
MessageEmbed messageEmbed = this . embeds . get ( 0 ) ;
if ( ( ( ( Node ) u . elementAt ( collection , 0 ) ) instanceof UrlNode ) & & EmbedResourceUtils . INSTANCE . isSimpleEmbed ( messageEmbed ) ) {
collection . clear ( ) ;
}
}
}
public final long getMyUserId ( ) {
return this . myUserId ;
}
public final List < SpoilerNode < ? > > getSpoilers ( ) {
return this . spoilers ;
}
public final boolean isLinkifyConflicting ( ) {
if ( ! this . hasLinkConflictingNode ) {
List < SpoilerNode < ? > > list = this . spoilers ;
if ( list = = null | | list . isEmpty ( ) ) {
return false ;
}
}
return true ;
}
public final < R extends BasicRenderContext > void process ( Collection < ? extends Node < R > > collection ) {
m . checkNotNullParameter ( collection , " ast " ) ;
stripSimpleEmbedLink ( e0 . asMutableCollection ( collection ) ) ;
2021-08-20 10:00:12 +00:00
AnimatableValueParser . K2 ( collection , this ) ;
2021-08-09 22:50:52 +00:00
if ( this . shouldJumboify ) {
2021-08-20 10:00:12 +00:00
AnimatableValueParser . K2 ( collection , MessagePreprocessor$process$1 . INSTANCE ) ;
2021-08-09 22:50:52 +00:00
}
processSpoilerChildren ( ) ;
processQuoteChildren ( collection ) ;
constrainAST ( collection ) ;
}
/ * JADX WARNING : Code restructure failed : missing block : B : 5 : 0x0017 , code lost :
if ( r0 < = 27 ) goto L_0x0020 ;
* /
/* JADX WARNING: Removed duplicated region for block: B:14:0x0033 */
/* JADX WARNING: Removed duplicated region for block: B:18:0x003c */
/* JADX WARNING: Removed duplicated region for block: B:19:0x003f */
2021-08-18 07:29:27 +00:00
@Override // c.a.t.b.c.a
2021-08-09 22:50:52 +00:00
public void processNode ( Node < ? > node ) {
boolean z2 ;
boolean z3 ;
m . checkNotNullParameter ( node , " node " ) ;
boolean z4 = false ;
if ( this . shouldJumboify ) {
if ( node instanceof EmojiNode ) {
int i = this . customEmojiCount + 1 ;
this . customEmojiCount = i ;
} else {
if ( ! ( node instanceof StyleNode ) ) {
2021-08-18 07:29:27 +00:00
if ( node instanceof c . a . t . b . a . a ) {
z3 = t . isBlank ( ( ( c . a . t . b . a . a ) node ) . getContent ( ) ) ;
2021-08-09 22:50:52 +00:00
if ( z3 ) {
z2 = true ;
this . shouldJumboify = z2 ;
if ( ! ( node instanceof CodeNode ) ) {
this . hasLinkConflictingNode = true ;
return ;
} else if ( node instanceof UrlNode ) {
this . hasLinkConflictingNode = true ;
return ;
} else if ( node instanceof SpoilerNode ) {
List list = this . spoilers ;
if ( list = = null ) {
list = new ArrayList ( ) ;
this . spoilers = list ;
}
int size = list . size ( ) ;
list . add ( node ) ;
Collection < Integer > collection = this . visibleSpoilerNodeIndices ;
if ( collection ! = null ) {
z4 = collection . contains ( Integer . valueOf ( size ) ) ;
}
( ( SpoilerNode ) node ) . updateState ( size , z4 ) ;
return ;
} else {
return ;
}
}
}
}
z3 = true ;
if ( z3 ) {
}
}
z3 = false ;
if ( z3 ) {
}
}
z2 = false ;
this . shouldJumboify = z2 ;
if ( ! ( node instanceof CodeNode ) ) {
}
}
}