Do not provide the context, but use the StringProvider.
This commit is contained in:
parent
0d836ffe96
commit
dbafc9d4c4
1 changed files with 6 additions and 7 deletions
|
|
@ -35,6 +35,7 @@ import io.element.android.libraries.push.api.notifications.NotificationDrawerMan
|
||||||
import io.element.android.libraries.push.impl.R
|
import io.element.android.libraries.push.impl.R
|
||||||
import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent
|
import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent
|
||||||
import io.element.android.libraries.push.impl.push.OnNotifiableEventReceived
|
import io.element.android.libraries.push.impl.push.OnNotifiableEventReceived
|
||||||
|
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
@ -54,7 +55,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
if (intent == null || context == null) return
|
if (intent == null || context == null) return
|
||||||
context.bindings<NotificationBroadcastReceiverBindings>().inject(this)
|
context.bindings<NotificationBroadcastReceiverBindings>().inject(this)
|
||||||
notificationBroadcastReceiverHandler.onReceive(context, intent)
|
notificationBroadcastReceiverHandler.onReceive(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -74,8 +75,9 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
private val actionIds: NotificationActionIds,
|
private val actionIds: NotificationActionIds,
|
||||||
private val systemClock: SystemClock,
|
private val systemClock: SystemClock,
|
||||||
private val onNotifiableEventReceived: OnNotifiableEventReceived,
|
private val onNotifiableEventReceived: OnNotifiableEventReceived,
|
||||||
|
private val stringProvider: StringProvider,
|
||||||
) {
|
) {
|
||||||
fun onReceive(context: Context, intent: Intent) {
|
fun onReceive(intent: Intent) {
|
||||||
val sessionId = intent.extras?.getString(NotificationBroadcastReceiver.KEY_SESSION_ID)?.let(::SessionId) ?: return
|
val sessionId = intent.extras?.getString(NotificationBroadcastReceiver.KEY_SESSION_ID)?.let(::SessionId) ?: return
|
||||||
val roomId = intent.getStringExtra(NotificationBroadcastReceiver.KEY_ROOM_ID)?.let(::RoomId)
|
val roomId = intent.getStringExtra(NotificationBroadcastReceiver.KEY_ROOM_ID)?.let(::RoomId)
|
||||||
val threadId = intent.getStringExtra(NotificationBroadcastReceiver.KEY_THREAD_ID)?.let(::ThreadId)
|
val threadId = intent.getStringExtra(NotificationBroadcastReceiver.KEY_THREAD_ID)?.let(::ThreadId)
|
||||||
|
|
@ -84,7 +86,7 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
Timber.tag(loggerTag.value).d("onReceive: ${intent.action} ${intent.data} for: ${roomId?.value}/${eventId?.value}")
|
Timber.tag(loggerTag.value).d("onReceive: ${intent.action} ${intent.data} for: ${roomId?.value}/${eventId?.value}")
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
actionIds.smartReply -> if (roomId != null) {
|
actionIds.smartReply -> if (roomId != null) {
|
||||||
handleSmartReply(sessionId, roomId, threadId, intent, context)
|
handleSmartReply(sessionId, roomId, threadId, intent)
|
||||||
}
|
}
|
||||||
actionIds.dismissRoom -> if (roomId != null) {
|
actionIds.dismissRoom -> if (roomId != null) {
|
||||||
notificationDrawerManager.clearMessagesForRoom(sessionId, roomId)
|
notificationDrawerManager.clearMessagesForRoom(sessionId, roomId)
|
||||||
|
|
@ -138,7 +140,6 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
roomId: RoomId,
|
roomId: RoomId,
|
||||||
threadId: ThreadId?,
|
threadId: ThreadId?,
|
||||||
intent: Intent,
|
intent: Intent,
|
||||||
context: Context
|
|
||||||
) = appCoroutineScope.launch {
|
) = appCoroutineScope.launch {
|
||||||
val message = getReplyMessage(intent)
|
val message = getReplyMessage(intent)
|
||||||
|
|
||||||
|
|
@ -155,7 +156,6 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
threadId = threadId,
|
threadId = threadId,
|
||||||
room = room,
|
room = room,
|
||||||
message = message,
|
message = message,
|
||||||
context = context,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +166,6 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
threadId: ThreadId?,
|
threadId: ThreadId?,
|
||||||
room: MatrixRoom,
|
room: MatrixRoom,
|
||||||
message: String,
|
message: String,
|
||||||
context: Context,
|
|
||||||
) {
|
) {
|
||||||
// Create a new event to be displayed in the notification drawer, right now
|
// Create a new event to be displayed in the notification drawer, right now
|
||||||
val notifiableMessageEvent = NotifiableMessageEvent(
|
val notifiableMessageEvent = NotifiableMessageEvent(
|
||||||
|
|
@ -180,7 +179,7 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
||||||
noisy = false,
|
noisy = false,
|
||||||
timestamp = systemClock.epochMillis(),
|
timestamp = systemClock.epochMillis(),
|
||||||
senderDisambiguatedDisplayName = room.getUpdatedMember(sessionId).getOrNull()?.disambiguatedDisplayName
|
senderDisambiguatedDisplayName = room.getUpdatedMember(sessionId).getOrNull()?.disambiguatedDisplayName
|
||||||
?: context.getString(R.string.notification_sender_me),
|
?: stringProvider.getString(R.string.notification_sender_me),
|
||||||
body = message,
|
body = message,
|
||||||
imageUriString = null,
|
imageUriString = null,
|
||||||
threadId = threadId,
|
threadId = threadId,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue