public NotificationDisplayHandler notificationDisplayHandler () { if(notificationDisplayHandler == null) { notificationDisplayHandler = new NotificationDisplayHandler(); } return notificationDisplayHandler; }
public void createMessageNotification(Message message) { Context context = ChatSDK.shared().context(); String threadID = message.getThread().getEntityID(); Intent openChatIntent = new Intent(context, ChatSDK.ui().getChatActivity()); openChatIntent.putExtra(InterfaceManager.THREAD_ENTITY_ID, threadID); openChatIntent.setAction(threadID); openChatIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); createMessageNotification(context, openChatIntent, message.getSender().getEntityID(), message.getSender().getName(), message.getText()); }
public void createMessageNotification(final Context context, Intent resultIntent, String userEntityID, String title, String message) { int pushIcon = ChatSDK.config().pushNotificationImageDefaultResourceId; if(pushIcon <= 0) { pushIcon = R.drawable.icn_72_push_mask; } final int smallPushIcon = pushIcon; final Bitmap largePushIcon = BitmapFactory.decodeResource(context.getResources(), smallPushIcon); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (userEntityID != null && !userEntityID.isEmpty()) { User user = StorageManager.shared().fetchUserWithEntityID(userEntityID); if (user != null) { ImageBuilder.bitmapForURL(context, user.getAvatarURL()).subscribe((bitmap, throwable) -> { if (throwable != null) { ChatSDK.logError(throwable); } if (bitmap == null) { bitmap = largePushIcon; } createAlertNotification(context, resultIntent, title, message, bitmap, smallPushIcon, alarmSound, -1); }); } else { createAlertNotification(context, resultIntent, title, message, largePushIcon, smallPushIcon, alarmSound, -1); } } }
ChatSDK.ui().notificationDisplayHandler().createMessageNotification(context, appIntent, userEntityID, title, body);
public void handleLocalNotifications () { if (localNotificationDisposable != null) { localNotificationDisposable.dispose(); } // TODO: Check this localNotificationDisposable = ChatSDK.events().sourceOnMain() .filter(NetworkEvent.filterType(EventType.MessageAdded)) .subscribe(networkEvent -> { Message message = networkEvent.message; Thread thread = networkEvent.thread; if(message != null && !AppBackgroundMonitor.shared().inBackground()) { if (thread.typeIs(ThreadType.Private) || (thread.typeIs(ThreadType.Public) && ChatSDK.config().pushNotificationsForPublicChatRoomsEnabled)) { if(!message.getSender().isMe() && ChatSDK.ui().showLocalNotifications(message.getThread())) { ReadStatus status = message.readStatusForUser(ChatSDK.currentUser()); if (!message.isRead() && !status.is(ReadStatus.delivered())) { // Only show the alert if we'recyclerView not on the private threads tab ChatSDK.ui().notificationDisplayHandler().createMessageNotification(message); } } } } }); }