@@ -29,16 +29,13 @@ import com.google.firebase.messaging.FirebaseMessagingService
2929import com.google.firebase.messaging.RemoteMessage
3030import dagger.hilt.android.AndroidEntryPoint
3131import im.vector.app.BuildConfig
32- import im.vector.app.R
3332import im.vector.app.core.di.ActiveSessionHolder
3433import im.vector.app.core.network.WifiDetector
3534import im.vector.app.core.pushers.PushersManager
3635import im.vector.app.features.badge.BadgeProxy
3736import im.vector.app.features.notifications.NotifiableEventResolver
38- import im.vector.app.features.notifications.NotifiableMessageEvent
3937import im.vector.app.features.notifications.NotificationDrawerManager
4038import im.vector.app.features.notifications.NotificationUtils
41- import im.vector.app.features.notifications.SimpleNotifiableEvent
4239import im.vector.app.features.settings.VectorDataStore
4340import im.vector.app.features.settings.VectorPreferences
4441import im.vector.app.push.fcm.FcmHelper
@@ -48,9 +45,7 @@ import kotlinx.coroutines.launch
4845import kotlinx.coroutines.runBlocking
4946import org.matrix.android.sdk.api.extensions.tryOrNull
5047import org.matrix.android.sdk.api.logger.LoggerTag
51- import org.matrix.android.sdk.api.pushrules.Action
5248import org.matrix.android.sdk.api.session.Session
53- import org.matrix.android.sdk.api.session.events.model.Event
5449import timber.log.Timber
5550import javax.inject.Inject
5651
@@ -201,12 +196,11 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
201196 Timber .tag(loggerTag.value).d(" Fast lane: start request" )
202197 val event = tryOrNull { session.getEvent(roomId, eventId) } ? : return @launch
203198
204- val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event)
199+ val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event, canBeReplaced = true )
205200
206201 resolvedEvent
207202 ?.also { Timber .tag(loggerTag.value).d(" Fast lane: notify drawer" ) }
208203 ?.let {
209- it.isPushGatewayEvent = true
210204 notificationDrawerManager.onNotifiableEventReceived(it)
211205 notificationDrawerManager.refreshNotificationDrawer()
212206 }
@@ -227,87 +221,4 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
227221 }
228222 return false
229223 }
230-
231- private fun handleNotificationWithoutSyncingMode (data : Map <String , String >, session : Session ? ) {
232- if (session == null ) {
233- Timber .tag(loggerTag.value).e(" ## handleNotificationWithoutSyncingMode cannot find session" )
234- return
235- }
236-
237- // The Matrix event ID of the event being notified about.
238- // This is required if the notification is about a particular Matrix event.
239- // It may be omitted for notifications that only contain updated badge counts.
240- // This ID can and should be used to detect duplicate notification requests.
241- val eventId = data[" event_id" ] ? : return // Just ignore
242-
243- val eventType = data[" type" ]
244- if (eventType == null ) {
245- // Just add a generic unknown event
246- val simpleNotifiableEvent = SimpleNotifiableEvent (
247- session.myUserId,
248- eventId,
249- null ,
250- true , // It's an issue in this case, all event will bing even if expected to be silent.
251- title = getString(R .string.notification_unknown_new_event),
252- description = " " ,
253- type = null ,
254- timestamp = System .currentTimeMillis(),
255- soundName = Action .ACTION_OBJECT_VALUE_VALUE_DEFAULT ,
256- isPushGatewayEvent = true
257- )
258- notificationDrawerManager.onNotifiableEventReceived(simpleNotifiableEvent)
259- notificationDrawerManager.refreshNotificationDrawer()
260- } else {
261- val event = parseEvent(data) ? : return
262-
263- val notifiableEvent = notifiableEventResolver.resolveEvent(event, session)
264-
265- if (notifiableEvent == null ) {
266- Timber .tag(loggerTag.value).e(" Unsupported notifiable event $eventId " )
267- if (BuildConfig .LOW_PRIVACY_LOG_ENABLE ) {
268- Timber .tag(loggerTag.value).e(" --> $event " )
269- }
270- } else {
271- if (notifiableEvent is NotifiableMessageEvent ) {
272- if (notifiableEvent.senderName.isNullOrEmpty()) {
273- notifiableEvent.senderName = data[" sender_display_name" ] ? : data[" sender" ] ? : " "
274- }
275- if (notifiableEvent.roomName.isNullOrEmpty()) {
276- notifiableEvent.roomName = findRoomNameBestEffort(data, session) ? : " "
277- }
278- }
279-
280- notifiableEvent.isPushGatewayEvent = true
281- notifiableEvent.matrixID = session.myUserId
282- notificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
283- notificationDrawerManager.refreshNotificationDrawer()
284- }
285- }
286- }
287-
288- private fun findRoomNameBestEffort (data : Map <String , String >, session : Session ? ): String? {
289- var roomName: String? = data[" room_name" ]
290- val roomId = data[" room_id" ]
291- if (null == roomName && null != roomId) {
292- // Try to get the room name from our store
293- roomName = session?.getRoom(roomId)?.roomSummary()?.displayName
294- }
295- return roomName
296- }
297-
298- /* *
299- * Try to create an event from the FCM data
300- *
301- * @param data the FCM data
302- * @return the event or null if required data are missing
303- */
304- private fun parseEvent (data : Map <String , String >? ): Event ? {
305- return Event (
306- eventId = data?.get(" event_id" ) ? : return null ,
307- senderId = data[" sender" ],
308- roomId = data[" room_id" ] ? : return null ,
309- type = data[" type" ] ? : return null ,
310- originServerTs = System .currentTimeMillis()
311- )
312- }
313224}
0 commit comments