Skip to content

Commit

Permalink
Fix user device unregistration in case of failed PNs
Browse files Browse the repository at this point in the history
  • Loading branch information
balysv committed Nov 17, 2021
1 parent 0bf52bf commit ec85609
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FirebaseNotificationSender(private val deviceRegistrationService: UserDevi
// Remove unregistered devices
if (e.messagingErrorCode == MessagingErrorCode.UNREGISTERED) {
kotlin.runCatching {
deviceRegistrationService.unregister(UnregisterDeviceCommand(deviceId))
deviceRegistrationService.unregister(receiverUserId, UnregisterDeviceCommand(deviceId))
}.onFailure {
logger.error("Error unregistering device#${deviceId}", it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.transaction.annotation.Transactional
@Service
class UserDeviceRegistrationApplicationService(
private val userRepository: UserRepository,
private val authUserService: AuthUserService
private val authUserService: AuthUserService,
) : UserDeviceRegistrationService {

@Transactional(readOnly = true)
Expand All @@ -35,11 +35,16 @@ class UserDeviceRegistrationApplicationService(
}

@Transactional
override fun unregister(command: UnregisterDeviceCommand): Boolean {
val userId = authUserService.currentUserId()
override fun unregister(userId: UserId, command: UnregisterDeviceCommand): Boolean {
val changes = userRepository.findDeviceRegistrationsByIdOrThrow(userId)
.unregister(command.deviceId)
userRepository.save(changes)
return true
}

@Transactional
override fun unregister(command: UnregisterDeviceCommand): Boolean {
val userId = authUserService.currentUserId()
return unregister(userId, command)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.sama.users.application

import com.sama.common.InternalApi
import com.sama.users.domain.UserId

interface UserDeviceRegistrationService {
fun me(): UserDeviceRegistrationsDTO
fun find(userId: UserId): UserDeviceRegistrationsDTO
fun register(command: RegisterDeviceCommand): Boolean
@InternalApi
fun unregister(userId: UserId, command: UnregisterDeviceCommand): Boolean
fun unregister(command: UnregisterDeviceCommand): Boolean
}

0 comments on commit ec85609

Please sign in to comment.