2021-08-09 22:50:52 +00:00
package com.discord.utilities.fcm ;
import android.app.AlarmManager ;
import android.app.Application ;
2021-09-21 07:33:49 +00:00
import android.app.Notification ;
2021-08-09 22:50:52 +00:00
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.graphics.drawable.IconCompat ;
2021-08-18 07:29:27 +00:00
import c.a.k.b ;
2021-08-09 22:50:52 +00:00
import c.d.b.a.a ;
import com.discord.R ;
import com.discord.app.AppActivity ;
import com.discord.app.AppLog ;
2021-09-21 07:33:49 +00:00
import com.discord.utilities.ShareUtils ;
2021-08-09 22:50:52 +00:00
import com.discord.utilities.analytics.Traits ;
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.chat.input.MentionUtilsKt ;
import com.discord.widgets.notice.NoticePopup ;
2021-11-01 07:19:03 +00:00
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 ;
2021-08-09 22:50:52 +00:00
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.HashMap ;
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 , Traits . Payment . Type . 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 ) ;
}
2021-09-21 07:33:49 +00:00
public static final /* synthetic */ void access$pushShortcut ( NotificationRenderer notificationRenderer , Context context , NotificationData notificationData , NotificationCompat . Builder builder , IconCompat iconCompat ) {
notificationRenderer . pushShortcut ( context , notificationData , builder , iconCompat ) ;
}
2021-08-09 22:50:52 +00:00
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 ( NotificationCompat . CATEGORY_ALARM ) ;
Objects . requireNonNull ( systemService , " null cannot be cast to non-null type android.app.AlarmManager " ) ;
( ( AlarmManager ) systemService ) . set ( 2 , SystemClock . elapsedRealtime ( ) + NOTIFICATION_AUTO_DISMISS , broadcast ) ;
}
private final void displayAndUpdateCache ( Context context , NotificationData notificationData , NotificationClient . SettingsV2 settingsV2 ) {
NotificationCompat . Builder contentIntent = new NotificationCompat . Builder ( context , notificationData . getNotificationChannelId ( ) ) . setAutoCancel ( true ) . setOnlyAlertOnce ( true ) . setSmallIcon ( notificationData . getSmallIcon ( ) ) . setColor ( ColorCompat . getThemedColor ( context , ( int ) R . attr . color_brand_500 ) ) . 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 ) ) ;
2021-09-21 07:33:49 +00:00
m . checkNotNullExpressionValue ( contentIntent , " NotificationCompat.Build…etContentIntent(context)) " ) ;
2021-08-09 22:50:52 +00:00
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 ) ;
}
2021-09-29 07:33:53 +00:00
Uri uri = null ;
2021-08-09 22:50:52 +00:00
if ( ! extras . isEmpty ( ) ) {
contentIntent . setNumber ( extras . size ( ) ) ;
2021-09-29 07:33:53 +00:00
contentIntent . setStyle ( getMessageStyle ( context , notificationData , extras , new MGImagesBitmap . CloseableBitmaps ( h0 . emptyMap ( ) , false , 2 , null ) ) ) ;
2021-08-09 22:50:52 +00:00
}
2021-09-27 21:20:28 +00:00
if ( notificationData . getShouldUseBigText ( ) ) {
contentIntent . setStyle ( new NotificationCompat . BigTextStyle ( ) . bigText ( notificationData . getContent ( context ) ) ) ;
}
2021-08-09 22:50:52 +00:00
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 , ( int ) R . attr . color_brand ) , NOTIFICATION_LIGHT_PERIOD , NOTIFICATION_LIGHT_PERIOD ) ;
}
Uri notificationSound = notificationData . getNotificationSound ( context ) ;
if ( notificationSound ! = null ) {
2021-09-29 07:33:53 +00:00
if ( ! settingsV2 . isDisableSound ( ) ) {
uri = notificationSound ;
2021-08-09 22:50:52 +00:00
}
2021-09-29 07:33:53 +00:00
if ( uri ! = null ) {
contentIntent . setSound ( uri ) . setDefaults ( INSTANCE . getNotificationDefaults ( settingsV2 . isDisableSound ( ) , settingsV2 . isDisableVibrate ( ) ) & - 2 ) ;
2021-08-09 22:50:52 +00:00
}
}
}
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 ) {
2021-08-18 07:29:27 +00:00
String iconUrlForAvatar = notificationData2 . getIconUrlForAvatar ( ) ;
if ( iconUrlForAvatar ! = null ) {
arrayList . add ( iconUrlForAvatar ) ;
2021-08-09 22:50:52 +00:00
}
}
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 ) ;
2021-10-22 07:30:30 +00:00
Observable < MGImagesBitmap . CloseableBitmaps > Q = MGImagesBitmap . getBitmaps ( mutableSet ) . Q ( ) ;
2021-08-09 22:50:52 +00:00
CompositeSubscription compositeSubscription = new CompositeSubscription ( ) ;
2021-10-22 07:30:30 +00:00
Observable < Long > a02 = Observable . d0 ( NOTIFICATION_ICON_FETCH_DELAY_MS , TimeUnit . MILLISECONDS ) . a0 ( Observable . h0 ( new r ( Q . i , new f1 ( new d1 ( d . j ) ) ) ) ) ;
m . checkNotNullExpressionValue ( a02 , " Observable \ n .time…Next(Observable.never())) " ) ;
ObservableExtensionsKt . appSubscribe$default ( ObservableExtensionsKt . ui ( a02 ) , ( Context ) null , " Unable to display notification, timeout. " , new NotificationRenderer$displayAndUpdateCache$4 ( compositeSubscription ) , new NotificationRenderer$displayAndUpdateCache$5 ( context , andUpdate , contentIntent , notificationData ) , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , 112 , ( Object ) null ) ;
m . checkNotNullExpressionValue ( Q , " bitmapsObservable " ) ;
Observable ui = ObservableExtensionsKt . ui ( Q ) ;
2021-11-05 21:05:33 +00:00
StringBuilder R = a . R ( " Unable to display notification multi-fetch " ) ;
R . append ( mutableSet . size ( ) ) ;
R . append ( " bitmaps. " ) ;
ObservableExtensionsKt . appSubscribe$default ( ui , ( Context ) null , R . toString ( ) , new NotificationRenderer$displayAndUpdateCache$6 ( compositeSubscription ) , new NotificationRenderer$displayAndUpdateCache$7 ( notificationData , contentIntent , extras , context , andUpdate ) , ( Function1 ) null , ( Function0 ) null , ( Function0 ) null , 112 , ( Object ) null ) ;
2021-08-09 22:50:52 +00:00
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-11-25 09:11:30 +00:00
Person build = new Person . Builder ( ) . setName ( context . getString ( R . string . f2998me ) ) . setKey ( " me " ) . build ( ) ;
2021-08-09 22:50:52 +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 ( ) ) ;
2021-09-21 07:33:49 +00:00
m . checkNotNullExpressionValue ( groupConversation , " NotificationCompat.Messa…tion.isGroupConversation) " ) ;
2021-08-09 22:50:52 +00:00
for ( NotificationData notificationData2 : list ) {
2021-08-18 07:29:27 +00:00
Bitmap bitmap = map . get ( notificationData2 . getIconUrlForAvatar ( ) ) ;
2021-08-09 22:50:52 +00:00
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 ) ;
}
return groupConversation ;
}
private final int getNotificationDefaults ( boolean z2 , boolean z3 ) {
int i = ! z2 ? 1 : 0 ;
return ! z3 ? i | 2 : i ;
}
2021-09-21 07:33:49 +00:00
private final void pushShortcut ( Context context , NotificationData notificationData , NotificationCompat . Builder builder , IconCompat iconCompat ) {
ShareUtils shareUtils = ShareUtils . INSTANCE ;
shareUtils . addShortcut ( context , ShareUtils . toShortcutInfo$default ( shareUtils , context , notificationData . getChannelId ( ) , notificationData . getTitle ( context ) , null , iconCompat , null , 0 , 104 , null ) , builder ) ;
}
public static /* synthetic */ void pushShortcut$default ( NotificationRenderer notificationRenderer , Context context , NotificationData notificationData , NotificationCompat . Builder builder , IconCompat iconCompat , int i , Object obj ) {
if ( ( i & 8 ) ! = 0 ) {
iconCompat = null ;
}
notificationRenderer . pushShortcut ( context , notificationData , builder , iconCompat ) ;
}
2021-08-09 22:50:52 +00:00
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 . canDisplayInApp ( ) ) {
CharSequence title = notificationData . getTitle ( context ) ;
CharSequence content = notificationData . getContent ( context ) ;
2021-09-21 07:33:49 +00:00
if ( content = = null ) {
content = " " ;
}
if ( ! t . isBlank ( title ) | | ! t . isBlank ( content ) ) {
2021-08-09 22:50:52 +00:00
NoticePopup noticePopup = NoticePopup . INSTANCE ;
2021-11-05 21:05:33 +00:00
StringBuilder R = a . R ( " InAppNotif# " ) ;
R . append ( ClockFactory . get ( ) . currentTimeMillis ( ) ) ;
NoticePopup . enqueue$default ( noticePopup , R . toString ( ) , title , null , content , null , null , null , null , notificationData . getIconUrl ( ) , null , null , null , null , null , new NotificationRenderer$displayInApp$1 ( notificationData , context ) , 16116 , null ) ;
2021-08-09 22:50:52 +00:00
}
}
}
public final void displaySent ( Context context , long j , CharSequence charSequence , boolean z2 , int i ) {
m . checkNotNullParameter ( context , " context " ) ;
m . checkNotNullParameter ( charSequence , " channelName " ) ;
int i2 = z2 ? R . string . notification_reply_success : R . string . notification_reply_failed ;
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-09-21 07:33:49 +00:00
Notification build = new NotificationCompat . Builder ( context , NotificationClient . NOTIF_CHANNEL_MESSAGES ) . setAutoCancel ( true ) . setSmallIcon ( R . drawable . ic_notification_message_24dp ) . setCategory ( NotificationCompat . CATEGORY_MESSAGE ) . setContentText ( b . h ( context , i2 , new Object [ ] { charSequence } , null , 4 ) ) . setDeleteIntent ( broadcast ) . setContentIntent ( PendingIntent . getActivity ( context , 0 , selectChannel$default , PendingIntentExtensionsKt . immutablePendingIntentFlag ( 134217728 ) ) ) . build ( ) ;
m . checkNotNullExpressionValue ( build , " NotificationCompat.Build…ent) \ n .build() " ) ;
NotificationManagerCompat . from ( context ) . notify ( i , build ) ;
2021-08-09 22:50:52 +00:00
autoDismissNotification ( context , i ) ;
}
@RequiresApi ( 26 )
public final void initNotificationChannels ( Application application ) {
m . checkNotNullParameter ( application , " context " ) ;
NotificationChannel notificationChannel = new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_CALLS , application . getString ( R . string . call ) , 4 ) ;
NotificationChannel notificationChannel2 = new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_MEDIA_CONNECTIONS , application . getString ( R . string . voice ) , 2 ) ;
2021-11-22 08:31:21 +00:00
List < NotificationChannel > listOf = n . listOf ( ( Object [ ] ) new NotificationChannel [ ] { notificationChannel , notificationChannel2 , new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_MESSAGES , application . getString ( R . string . messages ) , 4 ) , new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_MESSAGES_DIRECT , application . getString ( R . string . direct_messages ) , 4 ) , new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_SOCIAL , application . getString ( R . string . friends ) , 2 ) , new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_GAME_DETECTION , application . getString ( R . string . game_detection_service ) , 1 ) , new NotificationChannel ( NotificationClient . NOTIF_CHANNEL_STAGE_START , application . getString ( R . string . stage_start_notification_category ) , 4 ) , new NotificationChannel ( NotificationClient . NOTIF_GUILD_SCHEDULED_EVENT_START , application . getString ( R . string . guild_scheduled_event_live ) , 4 ) , new NotificationChannel ( NotificationClient . NOTIF_GENERAL , application . getString ( R . string . other ) , 2 ) , new NotificationChannel ( NotificationClient . NOTIF_GENERAL_HIGH_PRIO , application . getString ( R . string . other_high_priority ) , 4 ) } ) ;
2021-08-09 22:50:52 +00:00
for ( NotificationChannel notificationChannel3 : listOf ) {
notificationChannel3 . setShowBadge ( true ) ;
notificationChannel3 . enableVibration ( true ) ;
notificationChannel3 . enableLights ( true ) ;
notificationChannel3 . setLightColor ( ColorCompat . getThemedColor ( application , ( int ) R . attr . color_brand ) ) ;
}
notificationChannel . setDescription ( application . getString ( R . string . call ) ) ;
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 ( ) + MentionUtilsKt . SLASH_CHAR + 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 ) ;
}
}