2021-06-27 20:44:35 +00:00
package com.discord.utilities.fcm ;
import android.app.AlarmManager ;
import android.app.Application ;
import android.app.NotificationChannel ;
import android.app.NotificationManager ;
import android.app.PendingIntent ;
import android.content.Context ;
import android.content.Intent ;
import android.graphics.Bitmap ;
import android.media.AudioAttributes ;
import android.net.Uri ;
import android.os.Build ;
import android.os.SystemClock ;
import androidx.annotation.RequiresApi ;
import androidx.core.app.NotificationCompat ;
import androidx.core.app.NotificationManagerCompat ;
import androidx.core.app.Person ;
import androidx.core.content.pm.ShortcutInfoCompat ;
import androidx.core.content.pm.ShortcutManagerCompat ;
import androidx.core.graphics.drawable.IconCompat ;
import c.a.l.b ;
import c.d.b.a.a ;
import com.discord.app.AppActivity ;
import com.discord.app.AppLog ;
import com.discord.utilities.color.ColorCompat ;
import com.discord.utilities.extensions.PendingIntentExtensionsKt ;
import com.discord.utilities.fcm.NotificationClient ;
import com.discord.utilities.fcm.NotificationData ;
import com.discord.utilities.images.MGImagesBitmap ;
import com.discord.utilities.intent.IntentUtils ;
import com.discord.utilities.logging.Logger ;
import com.discord.utilities.media.AppSound ;
import com.discord.utilities.rx.ObservableExtensionsKt ;
import com.discord.utilities.time.ClockFactory ;
import com.discord.widgets.notice.NoticePopup ;
import d0.g0.t ;
import d0.t.h0 ;
import d0.t.n ;
import d0.t.o ;
import d0.t.u ;
import d0.z.d.m ;
import j0.l.a.d ;
import j0.l.a.d1 ;
import j0.l.a.f1 ;
import j0.l.a.r ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Set ;
import java.util.concurrent.TimeUnit ;
import kotlin.jvm.functions.Function0 ;
import kotlin.jvm.functions.Function1 ;
import rx.Observable ;
import rx.Subscription ;
import rx.subscriptions.CompositeSubscription ;
/* compiled from: NotificationRenderer.kt */
public final class NotificationRenderer {
public static final NotificationRenderer INSTANCE = new NotificationRenderer ( ) ;
private static final long NOTIFICATION_AUTO_DISMISS = 3000 ;
private static final long NOTIFICATION_ICON_FETCH_DELAY_MS = 250 ;
private static final int NOTIFICATION_LIGHT_PERIOD = 1500 ;
/* compiled from: NotificationRenderer.kt */
public static final class NotificationDisplaySubscriptionManager {
public static final NotificationDisplaySubscriptionManager INSTANCE = new NotificationDisplaySubscriptionManager ( ) ;
private static final HashMap < Integer , Subscription > notificationDisplaySubscriptions = new HashMap < > ( ) ;
private NotificationDisplaySubscriptionManager ( ) {
}
public final void add ( int i , Subscription subscription ) {
m . checkNotNullParameter ( subscription , " subscription " ) ;
HashMap < Integer , Subscription > hashMap = notificationDisplaySubscriptions ;
synchronized ( hashMap ) {
INSTANCE . cancel ( i ) ;
hashMap . put ( Integer . valueOf ( i ) , subscription ) ;
}
}
public final void cancel ( int i ) {
HashMap < Integer , Subscription > hashMap = notificationDisplaySubscriptions ;
synchronized ( hashMap ) {
Subscription remove = hashMap . remove ( Integer . valueOf ( i ) ) ;
if ( remove ! = null ) {
remove . unsubscribe ( ) ;
}
}
}
}
private NotificationRenderer ( ) {
}
public static final /* synthetic */ void access$displayNotification ( NotificationRenderer notificationRenderer , Context context , int i , NotificationCompat . Builder builder ) {
notificationRenderer . displayNotification ( context , i , builder ) ;
}
public static final /* synthetic */ NotificationCompat . MessagingStyle access$getMessageStyle ( NotificationRenderer notificationRenderer , Context context , NotificationData notificationData , List list , Map map ) {
return notificationRenderer . getMessageStyle ( context , notificationData , list , map ) ;
}
private final void autoDismissNotification ( Context context , int i ) {
PendingIntent broadcast = PendingIntent . getBroadcast ( context , 0 , NotificationActions . Companion . cancel ( context , i ) , PendingIntentExtensionsKt . immutablePendingIntentFlag$default ( 0 , 1 , null ) ) ;
Object systemService = context . getSystemService ( " alarm " ) ;
Objects . requireNonNull ( systemService , " null cannot be cast to non-null type android.app.AlarmManager " ) ;
( ( AlarmManager ) systemService ) . set ( 2 , SystemClock . elapsedRealtime ( ) + 3000 , broadcast ) ;
}
/* JADX WARNING: Removed duplicated region for block: B:17:0x00df */
private final void displayAndUpdateCache ( Context context , NotificationData notificationData , NotificationClient . SettingsV2 settingsV2 ) {
boolean z2 ;
NotificationCompat . Builder contentIntent = new NotificationCompat . Builder ( context , notificationData . getNotificationChannelId ( ) ) . setAutoCancel ( true ) . setOnlyAlertOnce ( true ) . setSmallIcon ( notificationData . getSmallIcon ( ) ) . setColor ( ColorCompat . getThemedColor ( context , 2130969007 ) ) . setCategory ( notificationData . getNotificationCategory ( ) ) . setContentTitle ( notificationData . getTitle ( context ) ) . setContentText ( notificationData . getContent ( context ) ) . setDefaults ( getNotificationDefaults ( settingsV2 . isDisableSound ( ) , settingsV2 . isDisableVibrate ( ) ) ) . setDeleteIntent ( notificationData . getDeleteIntent ( context ) ) . setContentIntent ( notificationData . getContentIntent ( context ) ) ;
contentIntent . setGroup ( notificationData . getGroupKey ( ) ) ;
NotificationData . DisplayPayload andUpdate = NotificationCache . INSTANCE . getAndUpdate ( notificationData ) ;
List < NotificationData > extras = andUpdate . getExtras ( ) ;
PendingIntent fullScreenIntent = notificationData . getFullScreenIntent ( context ) ;
if ( fullScreenIntent ! = null ) {
contentIntent . setFullScreenIntent ( fullScreenIntent , true ) ;
contentIntent . setVisibility ( 1 ) ;
}
if ( ! extras . isEmpty ( ) ) {
contentIntent . setNumber ( extras . size ( ) ) ;
contentIntent . setStyle ( getMessageStyle ( context , notificationData , extras , new MGImagesBitmap . CloseableBitmaps ( h0 . emptyMap ( ) ) ) ) ;
String valueOf = String . valueOf ( notificationData . getChannelId ( ) ) ;
List < ShortcutInfoCompat > dynamicShortcuts = ShortcutManagerCompat . getDynamicShortcuts ( context ) ;
m . checkNotNullExpressionValue ( dynamicShortcuts , " ShortcutManagerCompat.getDynamicShortcuts(context) " ) ;
if ( ! ( dynamicShortcuts instanceof Collection ) | | ! dynamicShortcuts . isEmpty ( ) ) {
Iterator < T > it = dynamicShortcuts . iterator ( ) ;
while ( true ) {
if ( ! it . hasNext ( ) ) {
break ;
}
ShortcutInfoCompat shortcutInfoCompat = ( ShortcutInfoCompat ) it . next ( ) ;
m . checkNotNullExpressionValue ( shortcutInfoCompat , " it " ) ;
if ( m . areEqual ( shortcutInfoCompat . getId ( ) , valueOf ) ) {
z2 = true ;
break ;
}
}
if ( z2 ) {
contentIntent . setShortcutId ( valueOf ) ;
}
}
z2 = false ;
if ( z2 ) {
}
}
int i = Build . VERSION . SDK_INT ;
if ( i < 26 ) {
contentIntent . setPriority ( notificationData . getNotificationPriority ( ) ) . setVibrate ( new long [ ] { 0 } ) ;
if ( ! settingsV2 . isDisableBlink ( ) ) {
contentIntent . setLights ( ColorCompat . getThemedColor ( context , 2130968994 ) , 1500 , 1500 ) ;
}
Uri notificationSound = notificationData . getNotificationSound ( context ) ;
if ( notificationSound ! = null ) {
if ( ! ( ! settingsV2 . isDisableSound ( ) ) ) {
notificationSound = null ;
}
if ( notificationSound ! = null ) {
contentIntent . setSound ( notificationSound ) . setDefaults ( INSTANCE . getNotificationDefaults ( settingsV2 . isDisableSound ( ) , settingsV2 . isDisableVibrate ( ) ) & - 2 ) ;
}
}
}
if ( i > = 24 ) {
for ( NotificationCompat . Action action : n . listOf ( ( Object [ ] ) new NotificationCompat . Action [ ] { notificationData . getMarkAsReadAction ( context ) , notificationData . getDirectReplyAction ( context , settingsV2 . getSendBlockedChannels ( ) ) , notificationData . getTimedMute ( context , ClockFactory . get ( ) , extras . size ( ) ) , notificationData . getCallAction ( context , false ) , notificationData . getCallAction ( context , true ) } ) ) {
if ( action ! = null ) {
contentIntent . addAction ( action ) ;
}
}
}
NotificationDisplaySubscriptionManager . INSTANCE . cancel ( andUpdate . getId ( ) ) ;
List < NotificationData > extras2 = andUpdate . getExtras ( ) ;
ArrayList arrayList = new ArrayList ( ) ;
for ( NotificationData notificationData2 : extras2 ) {
String iconUrlForUser = notificationData2 . getIconUrlForUser ( ) ;
if ( iconUrlForUser ! = null ) {
arrayList . add ( iconUrlForUser ) ;
}
}
List < String > plus = u . plus ( ( Collection < ? extends String > ) arrayList , notificationData . getIconUrl ( ) ) ;
ArrayList arrayList2 = new ArrayList ( o . collectionSizeOrDefault ( plus , 10 ) ) ;
for ( String str : plus ) {
arrayList2 . add ( new MGImagesBitmap . ImageRequest ( str , true ) ) ;
}
Set mutableSet = u . toMutableSet ( arrayList2 ) ;
Observable < MGImagesBitmap . CloseableBitmaps > R = MGImagesBitmap . getBitmaps ( mutableSet ) . R ( ) ;
CompositeSubscription compositeSubscription = new CompositeSubscription ( ) ;
Observable < Long > b02 = Observable . e0 ( 250 , TimeUnit . MILLISECONDS ) . b0 ( Observable . i0 ( new r ( R . i , new f1 ( new d1 ( d . j ) ) ) ) ) ;
m . checkNotNullExpressionValue ( b02 , " Observable \ n .time…Next(Observable.never())) " ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . ui ( b02 ) , ( Context ) null , " Unable to display notification, timeout. " , new NotificationRenderer$displayAndUpdateCache$4 ( compositeSubscription ) , new NotificationRenderer$displayAndUpdateCache$5 ( context , andUpdate , contentIntent ) , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , 112 , ( Object ) null ) ;
m . checkNotNullExpressionValue ( R , " bitmapsObservable " ) ;
Observable ui = ObservableExtensionsKt . ui ( R ) ;
StringBuilder L = a . L ( " Unable to display notification multi-fetch " ) ;
L . append ( mutableSet . size ( ) ) ;
L . append ( " bitmaps. " ) ;
ObservableExtensionsKt . appSubscribe$default ( ui , ( Context ) null , L . toString ( ) , new NotificationRenderer$displayAndUpdateCache$6 ( compositeSubscription ) , new NotificationRenderer$displayAndUpdateCache$7 ( notificationData , contentIntent , extras , context , andUpdate ) , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , 112 , ( Object ) null ) ;
NotificationDisplaySubscriptionManager . INSTANCE . add ( andUpdate . getId ( ) , compositeSubscription ) ;
}
private final void displayNotification ( Context context , int i , NotificationCompat . Builder builder ) {
try {
NotificationManagerCompat . from ( context ) . notify ( i , builder . build ( ) ) ;
} catch ( IllegalStateException e ) {
Logger . e$default ( AppLog . g , " NotifyError " , e , null , 4 , null ) ;
}
}
private final NotificationCompat . MessagingStyle getMessageStyle ( Context context , NotificationData notificationData , List < NotificationData > list , Map < String , Bitmap > map ) {
2021-06-27 20:53:42 +00:00
Person build = new Person . Builder ( ) . setName ( context . getString ( 2131891006 ) ) . setKey ( " me " ) . build ( ) ;
2021-06-27 20:44:35 +00:00
m . checkNotNullExpressionValue ( build , " Person.Builder() \ n …ey( \" me \" ) \ n .build() " ) ;
NotificationCompat . MessagingStyle groupConversation = new NotificationCompat . MessagingStyle ( build ) . setConversationTitle ( notificationData . getConversationTitle ( context ) ) . setGroupConversation ( notificationData . isGroupConversation ( ) ) ;
for ( NotificationData notificationData2 : list ) {
Bitmap bitmap = map . get ( notificationData2 . getIconUrlForUser ( ) ) ;
IconCompat createWithBitmap = bitmap ! = null ? IconCompat . createWithBitmap ( bitmap ) : null ;
Person build2 = notificationData2 . getSender ( context ) . toBuilder ( ) . setIcon ( createWithBitmap ) . build ( ) ;
m . checkNotNullExpressionValue ( build2 , " person.toBuilder() \ n …(icon) \ n .build() " ) ;
groupConversation . addMessage ( notificationData2 . getContent ( context ) , notificationData2 . getMessageIdTimestamp ( ) + ( ( long ) ( createWithBitmap = = null ? 0 : 1 ) ) , build2 ) ;
}
m . checkNotNullExpressionValue ( groupConversation , " msgStyle " ) ;
return groupConversation ;
}
private final int getNotificationDefaults ( boolean z2 , boolean z3 ) {
int i = ! z2 ? 1 : 0 ;
return ! z3 ? i | 2 : i ;
}
public final void clear ( Context context , long j , boolean z2 ) {
NotificationCache . INSTANCE . remove ( j , z2 , new NotificationRenderer$clear$1 ( context ) ) ;
}
public final void display ( Context context , NotificationData notificationData , NotificationClient . SettingsV2 settingsV2 ) {
m . checkNotNullParameter ( context , " context " ) ;
m . checkNotNullParameter ( notificationData , " notificationData " ) ;
m . checkNotNullParameter ( settingsV2 , " settings " ) ;
try {
displayAndUpdateCache ( context , notificationData , settingsV2 ) ;
} catch ( Exception e ) {
Logger . e$default ( AppLog . g , " Unable to display notification. " , e , null , 4 , null ) ;
}
}
public final void displayInApp ( Context context , NotificationData notificationData ) {
m . checkNotNullParameter ( context , " context " ) ;
m . checkNotNullParameter ( notificationData , " notificationData " ) ;
if ( notificationData . getChannelId ( ) = = - 1 ) {
CharSequence title = notificationData . getTitle ( context ) ;
String str = title ! = null ? title : " " ;
CharSequence content = notificationData . getContent ( context ) ;
String str2 = content ! = null ? content : " " ;
if ( ! t . isBlank ( str ) | | ! t . isBlank ( str2 ) ) {
NoticePopup noticePopup = NoticePopup . INSTANCE ;
StringBuilder L = a . L ( " InAppNotif# " ) ;
L . append ( ClockFactory . get ( ) . currentTimeMillis ( ) ) ;
NoticePopup . enqueue$default ( noticePopup , L . toString ( ) , str , null , str2 , null , null , null , null , notificationData . getIconUrl ( ) , null , null , null , null , null , new NotificationRenderer$displayInApp$1 ( notificationData , context ) , 16116 , null ) ;
}
}
}
public final void displaySent ( Context context , long j , CharSequence charSequence , boolean z2 , int i ) {
m . checkNotNullParameter ( context , " context " ) ;
m . checkNotNullParameter ( charSequence , " channelName " ) ;
2021-06-27 20:53:42 +00:00
int i2 = z2 ? 2131891533 : 2131891532 ;
2021-06-27 20:44:35 +00:00
PendingIntent broadcast = PendingIntent . getBroadcast ( context , 0 , NotificationActions . Companion . delete ( context , j ) , PendingIntentExtensionsKt . immutablePendingIntentFlag ( 134217728 ) ) ;
Intent selectChannel$default = IntentUtils . RouteBuilders . selectChannel$default ( j , 0 , null , 6 , null ) ;
selectChannel$default . setClass ( context , AppActivity . Main . class ) ;
2021-06-27 20:53:42 +00:00
NotificationManagerCompat . from ( context ) . notify ( i , new NotificationCompat . Builder ( context , " Messages " ) . setAutoCancel ( true ) . setSmallIcon ( 2131231794 ) . setCategory ( " msg " ) . setContentText ( b . g ( context , i2 , new Object [ ] { charSequence } , null , 4 ) ) . setDeleteIntent ( broadcast ) . setContentIntent ( PendingIntent . getActivity ( context , 0 , selectChannel$default , PendingIntentExtensionsKt . immutablePendingIntentFlag ( 134217728 ) ) ) . build ( ) ) ;
2021-06-27 20:44:35 +00:00
autoDismissNotification ( context , i ) ;
}
@RequiresApi ( 26 )
public final void initNotificationChannels ( Application application ) {
m . checkNotNullParameter ( application , " context " ) ;
2021-06-27 20:53:42 +00:00
NotificationChannel notificationChannel = new NotificationChannel ( " Calls " , application . getString ( 2131887113 ) , 4 ) ;
NotificationChannel notificationChannel2 = new NotificationChannel ( " Media Connections " , application . getString ( 2131894511 ) , 2 ) ;
List < NotificationChannel > listOf = n . listOf ( ( Object [ ] ) new NotificationChannel [ ] { notificationChannel , notificationChannel2 , new NotificationChannel ( " Messages " , application . getString ( 2131891184 ) , 4 ) , new NotificationChannel ( " DirectMessages " , application . getString ( 2131888116 ) , 4 ) , new NotificationChannel ( " Social " , application . getString ( 2131888810 ) , 2 ) , new NotificationChannel ( " Game Detection " , application . getString ( 2131888884 ) , 1 ) } ) ;
2021-06-27 20:44:35 +00:00
for ( NotificationChannel notificationChannel3 : listOf ) {
notificationChannel3 . setShowBadge ( true ) ;
notificationChannel3 . enableVibration ( true ) ;
notificationChannel3 . enableLights ( true ) ;
notificationChannel3 . setLightColor ( ColorCompat . getThemedColor ( application , 2130968994 ) ) ;
}
2021-06-27 20:53:42 +00:00
notificationChannel . setDescription ( application . getString ( 2131887113 ) ) ;
2021-06-27 20:44:35 +00:00
notificationChannel . setVibrationPattern ( new long [ ] { 100 , 200 , 300 , 400 , 500 , 400 , 300 , 200 , 400 } ) ;
notificationChannel . setShowBadge ( false ) ;
StringBuilder sb = new StringBuilder ( ) ;
sb . append ( " android.resource:// " ) ;
sb . append ( application . getPackageName ( ) + '/' + AppSound . Companion . getSOUND_CALL_RINGING ( ) . getResId ( ) ) ;
String sb2 = sb . toString ( ) ;
m . checkNotNullExpressionValue ( sb2 , " StringBuilder() \ n …) \ n .toString() " ) ;
notificationChannel . setSound ( Uri . parse ( sb2 ) , new AudioAttributes . Builder ( ) . setUsage ( 7 ) . setContentType ( 2 ) . build ( ) ) ;
notificationChannel2 . setShowBadge ( false ) ;
notificationChannel2 . enableVibration ( false ) ;
Object systemService = application . getSystemService ( " notification " ) ;
Objects . requireNonNull ( systemService , " null cannot be cast to non-null type android.app.NotificationManager " ) ;
( ( NotificationManager ) systemService ) . createNotificationChannels ( listOf ) ;
}
}