42
42
import com .qiscus .nirmana .Nirmana ;
43
43
import com .qiscus .sdk .Qiscus ;
44
44
import com .qiscus .sdk .R ;
45
+ import com .qiscus .sdk .chat .core .QiscusCore ;
45
46
import com .qiscus .sdk .chat .core .data .local .QiscusCacheManager ;
46
47
import com .qiscus .sdk .chat .core .data .model .QiscusChatRoom ;
47
48
import com .qiscus .sdk .chat .core .data .model .QiscusComment ;
@@ -215,10 +216,10 @@ private static void showPushNotification(Context context, QiscusComment comment)
215
216
new QiscusPushNotificationMessage (comment .getId (), messageText );
216
217
pushNotificationMessage .setRoomName (comment .getRoomName ());
217
218
pushNotificationMessage .setRoomAvatar (comment .getRoomAvatar ());
218
- if (!QiscusCacheManager .getInstance ()
219
- .addMessageNotifItem (pushNotificationMessage , comment .getRoomId ())) {
220
- return ;
221
- }
219
+ // if (!QiscusCacheManager.getInstance()
220
+ // .addMessageNotifItem(pushNotificationMessage, comment.getRoomId())) {
221
+ // return;
222
+ // }
222
223
223
224
if (Qiscus .getChatConfig ().isEnableAvatarAsNotificationIcon ()) {
224
225
QiscusAndroidUtil .runOnUIThread (() -> loadAvatar (context , comment , pushNotificationMessage ));
@@ -259,7 +260,13 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
259
260
private static void pushNotification (Context context , QiscusComment comment ,
260
261
QiscusPushNotificationMessage pushNotificationMessage , Bitmap largeIcon ) {
261
262
262
- String notificationChannelId = Qiscus .getApps ().getPackageName () + ".qiscus.sdk.notification.channel" ;
263
+ // if (QiscusCore.getDataStore().isContains(comment)) {
264
+ // return;
265
+ // }
266
+
267
+ QiscusCore .getDataStore ().addOrUpdate (comment );
268
+
269
+ String notificationChannelId = QiscusCore .getApps ().getPackageName () + ".qiscus.sdk.notification.channel" ;
263
270
if (BuildVersionUtil .isOreoOrHigher ()) {
264
271
NotificationChannel notificationChannel =
265
272
new NotificationChannel (notificationChannelId , "Chat" , NotificationManager .IMPORTANCE_HIGH );
@@ -270,9 +277,8 @@ private static void pushNotification(Context context, QiscusComment comment,
270
277
}
271
278
272
279
PendingIntent pendingIntent ;
273
- Intent openIntent = new Intent (context , QiscusPushNotificationClickReceiver .class );
280
+ Intent openIntent = new Intent (context , NotificationClickReceiver .class );
274
281
openIntent .putExtra ("data" , comment );
275
-
276
282
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
277
283
pendingIntent = PendingIntent .getBroadcast (context , QiscusNumberUtil .convertToInt (comment .getRoomId ()),
278
284
openIntent , PendingIntent .FLAG_IMMUTABLE | PendingIntent .FLAG_CANCEL_CURRENT );
@@ -282,66 +288,19 @@ private static void pushNotification(Context context, QiscusComment comment,
282
288
}
283
289
284
290
NotificationCompat .Builder notificationBuilder = new NotificationCompat .Builder (context , notificationChannelId );
285
- notificationBuilder .setContentTitle (pushNotificationMessage . getRoomName ())
291
+ notificationBuilder .setContentTitle (comment . getSender ())
286
292
.setContentIntent (pendingIntent )
287
- .setContentText (pushNotificationMessage .getMessage ())
288
- .setTicker (pushNotificationMessage .getMessage ())
289
- .setSmallIcon (Qiscus .getChatConfig ().getNotificationSmallIcon ())
290
- .setLargeIcon (largeIcon )
291
- .setColor (ContextCompat .getColor (context , Qiscus .getChatConfig ().getInlineReplyColor ()))
293
+ .setContentText (comment .getMessage ())
294
+ .setTicker (comment .getMessage ())
295
+ .setSmallIcon (R .drawable .ic_qiscus_notif_app )
296
+ .setColor (ContextCompat .getColor (context , R .color .colorAccent ))
292
297
.setGroup ("CHAT_NOTIF_" + comment .getRoomId ())
293
298
.setAutoCancel (true )
294
299
.setSound (RingtoneManager .getDefaultUri (RingtoneManager .TYPE_NOTIFICATION ));
295
300
296
- if (Qiscus .getChatConfig ().isEnableReplyNotification () && isNougatOrHigher ()) {
297
- String getRepliedTo = pushNotificationMessage .getRoomName ();
298
- RemoteInput remoteInput = new RemoteInput .Builder (KEY_NOTIFICATION_REPLY )
299
- .setLabel (QiscusTextUtil .getString (R .string .qiscus_reply_to , getRepliedTo .toUpperCase ()))
300
- .build ();
301
-
302
- NotificationCompat .Action replyAction = new NotificationCompat .Action .Builder (android .R .drawable .ic_menu_send ,
303
- QiscusTextUtil .getString (R .string .qiscus_reply_to , getRepliedTo .toUpperCase ()), pendingIntent )
304
- .addRemoteInput (remoteInput )
305
- .build ();
306
- notificationBuilder .addAction (replyAction );
307
- }
308
-
309
- boolean cancel = false ;
310
- if (Qiscus .getChatConfig ().getNotificationBuilderInterceptor () != null ) {
311
- cancel = !Qiscus .getChatConfig ().getNotificationBuilderInterceptor ()
312
- .intercept (notificationBuilder , comment );
313
- }
314
-
315
- if (cancel ) {
316
- return ;
317
- }
318
-
319
- NotificationCompat .InboxStyle inboxStyle = new NotificationCompat .InboxStyle ();
320
- List <QiscusPushNotificationMessage > notifItems = QiscusCacheManager .getInstance ()
321
- .getMessageNotifItems (comment .getRoomId ());
322
- if (notifItems == null ) {
323
- notifItems = new ArrayList <>();
324
- }
325
- int notifSize = 5 ;
326
- if (notifItems .size () < notifSize ) {
327
- notifSize = notifItems .size ();
328
- }
329
- if (notifItems .size () > notifSize ) {
330
- inboxStyle .addLine ("......." );
331
- }
332
- int start = notifItems .size () - notifSize ;
333
- for (int i = start ; i < notifItems .size (); i ++) {
334
- inboxStyle .addLine (notifItems .get (i ).getMessage ());
335
- }
336
- inboxStyle .setSummaryText (QiscusTextUtil .getString (R .string .qiscus_notif_count , notifItems .size ()));
337
- notificationBuilder .setStyle (inboxStyle );
338
-
339
- if (notifSize <= 3 ) {
340
- notificationBuilder .setPriority (Notification .PRIORITY_HIGH );
341
- }
342
-
343
301
QiscusAndroidUtil .runOnUIThread (() -> NotificationManagerCompat .from (context )
344
302
.notify (QiscusNumberUtil .convertToInt (comment .getRoomId ()), notificationBuilder .build ()));
303
+
345
304
}
346
305
347
306
private static void handleDeletedComment (Context context , List <QiscusComment > comments , boolean hardDelete ) {
0 commit comments