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 aff7160b6b..17a1b222a7 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 c6673698ab..5b54f502eb 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) } diff --git a/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml b/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml index 4355242882..ffc77da3fb 100644 --- a/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml +++ b/vector/src/main/res/layout/constraint_set_composer_layout_compact.xml @@ -149,6 +149,7 @@ android:layout_height="wrap_content" android:background="@android:color/transparent" android:hint="@string/room_message_placeholder_not_encrypted" + android:inputType="textCapSentences|textMultiLine" android:maxHeight="200dp" android:minHeight="48dp" android:nextFocusLeft="@id/composerEditText" diff --git a/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml b/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml index dcf13b4dbc..aa1f21dac7 100644 --- a/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml +++ b/vector/src/main/res/layout/constraint_set_composer_layout_expanded.xml @@ -159,6 +159,7 @@ android:layout_height="wrap_content" android:background="@android:color/transparent" android:hint="@string/room_message_placeholder_not_encrypted" + android:inputType="textCapSentences|textMultiLine" android:minHeight="48dp" android:nextFocusLeft="@id/composerEditText" android:nextFocusUp="@id/composerEditText" diff --git a/vector/src/main/res/layout/merge_composer_layout.xml b/vector/src/main/res/layout/merge_composer_layout.xml index c5db963c09..c88495d8ad 100644 --- a/vector/src/main/res/layout/merge_composer_layout.xml +++ b/vector/src/main/res/layout/merge_composer_layout.xml @@ -116,6 +116,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:background="@android:color/transparent" + android:inputType="textCapSentences|textMultiLine" android:nextFocusLeft="@id/composerEditText" android:nextFocusUp="@id/composerEditText" android:padding="8dp"