diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt index aff7160b..17a1b222 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt @@ -55,12 +55,38 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { NotificationUtils.MARK_ROOM_READ_ACTION -> intent.getStringExtra(KEY_ROOM_ID)?.let { notificationDrawerManager.clearMessageEventOfRoom(it) - handleMarkAsRead(context, it) + handleMarkAsRead(it) } + NotificationUtils.JOIN_ACTION -> { + intent.getStringExtra(KEY_ROOM_ID)?.let { + notificationDrawerManager.clearMemberShipNotificationForRoom(it) + handleJoinRoom(it) + } + } + NotificationUtils.REJECT_ACTION -> { + intent.getStringExtra(KEY_ROOM_ID)?.let { + notificationDrawerManager.clearMemberShipNotificationForRoom(it) + handleRejectRoom(it) + } + } } } - private fun handleMarkAsRead(context: Context, roomId: String) { + private fun handleJoinRoom(roomId: String) { + activeSessionHolder.getSafeActiveSession()?.let { session -> + session.getRoom(roomId) + ?.join(object : MatrixCallback {}) + } + } + + private fun handleRejectRoom(roomId: String) { + activeSessionHolder.getSafeActiveSession()?.let { session -> + session.getRoom(roomId) + ?.leave(object : MatrixCallback {}) + } + } + + private fun handleMarkAsRead(roomId: String) { activeSessionHolder.getActiveSession().let { session -> session.getRoom(roomId) ?.markAllAsRead(object : MatrixCallback {}) @@ -96,7 +122,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { false, System.currentTimeMillis(), session.getUser(session.sessionParams.credentials.userId)?.displayName - ?: context?.getString(R.string.notification_sender_me), + ?: context?.getString(R.string.notification_sender_me), session.sessionParams.credentials.userId, message, room.roomId, @@ -165,7 +191,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { private fun getReplyMessage(intent: Intent?): String? { if (intent != null) { - val remoteInput = RemoteInput.getResultsFromIntent(intent); + val remoteInput = RemoteInput.getResultsFromIntent(intent) if (remoteInput != null) { return remoteInput.getCharSequence(KEY_TEXT_REPLY)?.toString() } diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt index c6673698..5b54f502 100755 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationUtils.kt @@ -69,8 +69,8 @@ object NotificationUtils { * IDs for actions * ========================================================================================== */ - private const val JOIN_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.JOIN_ACTION" - private const val REJECT_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.REJECT_ACTION" + const val JOIN_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.JOIN_ACTION" + const val REJECT_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.REJECT_ACTION" private const val QUICK_LAUNCH_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.QUICK_LAUNCH_ACTION" const val MARK_ROOM_READ_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.MARK_ROOM_READ_ACTION" const val SMART_REPLY_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.SMART_REPLY_ACTION" @@ -492,31 +492,31 @@ object NotificationUtils { .setColor(accentColor) .apply { if (simpleNotifiableEvent is InviteNotifiableEvent) { - /* - TODO val roomId = simpleNotifiableEvent.roomId // offer to type a quick reject button - val rejectIntent = JoinRoomActivity.getRejectRoomIntent(context, roomId, matrixId) - - // the action must be unique else the parameters are ignored + val rejectIntent = Intent(context, NotificationBroadcastReceiver::class.java) rejectIntent.action = REJECT_ACTION rejectIntent.data = Uri.parse("foobar://$roomId&$matrixId") + rejectIntent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomId) + val rejectIntentPendingIntent = PendingIntent.getBroadcast(context, System.currentTimeMillis().toInt(), rejectIntent, + PendingIntent.FLAG_UPDATE_CURRENT) + addAction( R.drawable.vector_notification_reject_invitation, context.getString(R.string.reject), - PendingIntent.getActivity(context, System.currentTimeMillis().toInt(), rejectIntent, 0)) + rejectIntentPendingIntent) // offer to type a quick accept button - val joinIntent = JoinRoomActivity.getJoinRoomIntent(context, roomId, matrixId) - - // the action must be unique else the parameters are ignored + val joinIntent = Intent(context, NotificationBroadcastReceiver::class.java) joinIntent.action = JOIN_ACTION joinIntent.data = Uri.parse("foobar://$roomId&$matrixId") + rejectIntent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomId) + val joinIntentPendingIntent = PendingIntent.getBroadcast(context, System.currentTimeMillis().toInt(), joinIntent, + PendingIntent.FLAG_UPDATE_CURRENT) addAction( R.drawable.vector_notification_accept_invitation, context.getString(R.string.join), - PendingIntent.getActivity(context, 0, joinIntent, 0)) - */ + joinIntentPendingIntent) } else { setAutoCancel(true) }