Quick implementation of accept/reject invitation from notification

This commit is contained in:
Benoit Marty 2019-07-04 18:14:39 +02:00
parent 063c35380a
commit 857a4c5a26
2 changed files with 43 additions and 17 deletions

View File

@ -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<Unit> {})
}
}

private fun handleRejectRoom(roomId: String) {
activeSessionHolder.getSafeActiveSession()?.let { session ->
session.getRoom(roomId)
?.leave(object : MatrixCallback<Unit> {})
}
}

private fun handleMarkAsRead(roomId: String) {
activeSessionHolder.getActiveSession().let { session ->
session.getRoom(roomId)
?.markAllAsRead(object : MatrixCallback<Unit> {})
@ -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()
}

View File

@ -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)
}