forked from GitHub-Mirror/riotX-android
Quick implementation of accept/reject invitation from notification
This commit is contained in:
parent
063c35380a
commit
857a4c5a26
@ -55,12 +55,38 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||||||
NotificationUtils.MARK_ROOM_READ_ACTION ->
|
NotificationUtils.MARK_ROOM_READ_ACTION ->
|
||||||
intent.getStringExtra(KEY_ROOM_ID)?.let {
|
intent.getStringExtra(KEY_ROOM_ID)?.let {
|
||||||
notificationDrawerManager.clearMessageEventOfRoom(it)
|
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 ->
|
activeSessionHolder.getActiveSession().let { session ->
|
||||||
session.getRoom(roomId)
|
session.getRoom(roomId)
|
||||||
?.markAllAsRead(object : MatrixCallback<Unit> {})
|
?.markAllAsRead(object : MatrixCallback<Unit> {})
|
||||||
@ -96,7 +122,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||||||
false,
|
false,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
session.getUser(session.sessionParams.credentials.userId)?.displayName
|
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,
|
session.sessionParams.credentials.userId,
|
||||||
message,
|
message,
|
||||||
room.roomId,
|
room.roomId,
|
||||||
@ -165,7 +191,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
private fun getReplyMessage(intent: Intent?): String? {
|
private fun getReplyMessage(intent: Intent?): String? {
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
val remoteInput = RemoteInput.getResultsFromIntent(intent);
|
val remoteInput = RemoteInput.getResultsFromIntent(intent)
|
||||||
if (remoteInput != null) {
|
if (remoteInput != null) {
|
||||||
return remoteInput.getCharSequence(KEY_TEXT_REPLY)?.toString()
|
return remoteInput.getCharSequence(KEY_TEXT_REPLY)?.toString()
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ object NotificationUtils {
|
|||||||
* IDs for actions
|
* IDs for actions
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|
||||||
private const val JOIN_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.JOIN_ACTION"
|
const val JOIN_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.JOIN_ACTION"
|
||||||
private const val REJECT_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.REJECT_ACTION"
|
const val REJECT_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.REJECT_ACTION"
|
||||||
private const val QUICK_LAUNCH_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.QUICK_LAUNCH_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 MARK_ROOM_READ_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.MARK_ROOM_READ_ACTION"
|
||||||
const val SMART_REPLY_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.SMART_REPLY_ACTION"
|
const val SMART_REPLY_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.SMART_REPLY_ACTION"
|
||||||
@ -492,31 +492,31 @@ object NotificationUtils {
|
|||||||
.setColor(accentColor)
|
.setColor(accentColor)
|
||||||
.apply {
|
.apply {
|
||||||
if (simpleNotifiableEvent is InviteNotifiableEvent) {
|
if (simpleNotifiableEvent is InviteNotifiableEvent) {
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
val roomId = simpleNotifiableEvent.roomId
|
val roomId = simpleNotifiableEvent.roomId
|
||||||
// offer to type a quick reject button
|
// offer to type a quick reject button
|
||||||
val rejectIntent = JoinRoomActivity.getRejectRoomIntent(context, roomId, matrixId)
|
val rejectIntent = Intent(context, NotificationBroadcastReceiver::class.java)
|
||||||
|
|
||||||
// the action must be unique else the parameters are ignored
|
|
||||||
rejectIntent.action = REJECT_ACTION
|
rejectIntent.action = REJECT_ACTION
|
||||||
rejectIntent.data = Uri.parse("foobar://$roomId&$matrixId")
|
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(
|
addAction(
|
||||||
R.drawable.vector_notification_reject_invitation,
|
R.drawable.vector_notification_reject_invitation,
|
||||||
context.getString(R.string.reject),
|
context.getString(R.string.reject),
|
||||||
PendingIntent.getActivity(context, System.currentTimeMillis().toInt(), rejectIntent, 0))
|
rejectIntentPendingIntent)
|
||||||
|
|
||||||
// offer to type a quick accept button
|
// offer to type a quick accept button
|
||||||
val joinIntent = JoinRoomActivity.getJoinRoomIntent(context, roomId, matrixId)
|
val joinIntent = Intent(context, NotificationBroadcastReceiver::class.java)
|
||||||
|
|
||||||
// the action must be unique else the parameters are ignored
|
|
||||||
joinIntent.action = JOIN_ACTION
|
joinIntent.action = JOIN_ACTION
|
||||||
joinIntent.data = Uri.parse("foobar://$roomId&$matrixId")
|
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(
|
addAction(
|
||||||
R.drawable.vector_notification_accept_invitation,
|
R.drawable.vector_notification_accept_invitation,
|
||||||
context.getString(R.string.join),
|
context.getString(R.string.join),
|
||||||
PendingIntent.getActivity(context, 0, joinIntent, 0))
|
joinIntentPendingIntent)
|
||||||
*/
|
|
||||||
} else {
|
} else {
|
||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user