Skip to content

Commit

Permalink
Try to get event fastlane before sync on push
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Oct 5, 2021
1 parent 03a4e75 commit 94f9f7f
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,34 @@ val upHandler = object: MessagingReceiverHandler {
} else {
// Try to get the Event content faster
Timber.d("Requesting event in fast lane")
getEventFastLane(session, notification.roomId, notification.eventId)

Timber.d("Requesting background sync")
session.requireBackgroundSync()
if (!getEventFastLane(session, notification.roomId, notification.eventId)) {
Timber.d("Requesting background sync")
session.requireBackgroundSync()
}
}
}
} catch (e: Exception) {
Timber.e(e, "## onMessageReceivedInternal() failed")
}
}

private fun getEventFastLane(session: Session, roomId: String?, eventId: String?) {
roomId?.takeIf { it.isNotEmpty() } ?: return
eventId?.takeIf { it.isNotEmpty() } ?: return
private fun getEventFastLane(session: Session, roomId: String?, eventId: String?): Boolean {
roomId?.takeIf { it.isNotEmpty() } ?: return false
eventId?.takeIf { it.isNotEmpty() } ?: return false

// If the room is currently displayed, we will not show a notification, so no need to get the Event faster
if (notificationDrawerManager.shouldIgnoreMessageEventInRoom(roomId)) {
return
}

if (wifiDetector.isConnectedToWifi().not()) {
Timber.d("No WiFi network, do not get Event")
return
return true
}

coroutineScope.launch {
Timber.d("Fast lane: start request")
val event = tryOrNull { session.getEvent(roomId, eventId) } ?: return@launch
val event = tryOrNull { session.getEvent(roomId, eventId) }
event ?: run {
Timber.d("Fast lane: can not retrieve event")
session.requireBackgroundSync()
return@launch
}

val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event)

Expand All @@ -258,6 +258,8 @@ val upHandler = object: MessagingReceiverHandler {
notificationDrawerManager.refreshNotificationDrawer()
}
}

return true
}

// check if the event was not yet received
Expand Down

0 comments on commit 94f9f7f

Please sign in to comment.