Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-chekyrta committed Jun 25, 2024
1 parent 1577d97 commit 9a6e2f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
40 changes: 23 additions & 17 deletions app/src/main/java/org/openedx/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,8 @@ class AppViewModel(
notifier.notifier.collect { event ->
if (event is SignInEvent && config.getFirebaseConfig().isCloudMessagingEnabled) {
SyncFirebaseTokenWorker.schedule(context)
} else if (event is LogoutEvent && System.currentTimeMillis() - logoutHandledAt > 5000) {
if (event.isForced) {
logoutHandledAt = System.currentTimeMillis()
preferencesManager.clear()
withContext(dispatcher) {
room.clearAllTables()
}
analytics.logoutEvent(true)
_logoutUser.value = Unit
}
if (config.getFirebaseConfig().isCloudMessagingEnabled) {
RefreshFirebaseTokenWorker.schedule(context)
val notificationManager = context.getSystemService(
Context.NOTIFICATION_SERVICE
) as NotificationManager
notificationManager.cancelAll()
}
} else if (event is LogoutEvent) {
handleLogoutEvent(event)
}
}
}
Expand Down Expand Up @@ -114,4 +99,25 @@ class AppViewModel(
analytics.setUserIdForSession(it.id)
}
}

private suspend fun handleLogoutEvent(event: LogoutEvent) {
if (System.currentTimeMillis() - logoutHandledAt > 5000) {
if (event.isForced) {
logoutHandledAt = System.currentTimeMillis()
preferencesManager.clear()
withContext(dispatcher) {
room.clearAllTables()
}
analytics.logoutEvent(true)
_logoutUser.value = Unit
}

if (config.getFirebaseConfig().isCloudMessagingEnabled) {
RefreshFirebaseTokenWorker.schedule(context)
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancelAll()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

interface NotificationsApi {

@POST("/api/mobile/v4/notifications/create-token/")
@FormUrlEncoded
suspend fun syncFirebaseToken(
@Field("registration_id") token: String,
@Field("active") active: Boolean = true
)

}
4 changes: 2 additions & 2 deletions app/src/main/java/org/openedx/app/deeplink/DeepLink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.openedx.app.deeplink

class DeepLink(params: Map<String, String>) {

val screenName = params[Keys.SCREEN_NAME.value]
val notificationType = params[Keys.NOTIFICATION_TYPE.value]
private val screenName = params[Keys.SCREEN_NAME.value]
private val notificationType = params[Keys.NOTIFICATION_TYPE.value]
val courseId = params[Keys.COURSE_ID.value]
val pathId = params[Keys.PATH_ID.value]
val componentId = params[Keys.COMPONENT_ID.value]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ class OpenEdXFirebaseMessagingService : FirebaseMessagingService() {
private fun createId(): Int {
return SystemClock.uptimeMillis().toInt()
}

}

0 comments on commit 9a6e2f7

Please sign in to comment.