def toRegistration()

in registration/app/registration/services/LegacyRegistrationConverter.scala [11:41]


  def toRegistration(legacyRegistration: LegacyRegistration): Either[NotificationsError, Registration] = {

    def deviceTokenFromRegistration(platform: Platform): Either[NotificationsError, DeviceToken] = {
      (platform, legacyRegistration.device.pushToken, legacyRegistration.device.firebaseToken) match {
        //This first case is to handle lange numbers of android devices not using the latest version of the app
        //See: https://theguardian.atlassian.net/browse/MSS-609
        case (Android, _, None) => Left(MalformattedRegistration("Android device without firebase registration token"))
        case (Android, _, Some(fcmToken)) => Right(DeviceToken(fcmToken))
        case (_, Some(azureToken), _) => Right(DeviceToken(azureToken))
        case _ => Left(MalformattedRegistration("no fcm token nor azure token"))
      }
    }

    def platformFromRegistration: Either[NotificationsError, Platform] = {
      Either.fromOption(
        Platform.fromString(legacyRegistration.device.platform),
        UnsupportedPlatform(legacyRegistration.device.platform)
      )
    }

    for {
      platform <- platformFromRegistration
      deviceToken <- deviceTokenFromRegistration(platform)
    } yield Registration(
      deviceToken = deviceToken,
      platform = platform,
      topics = topics(legacyRegistration),
      buildTier = Some(legacyRegistration.device.buildTier),
      appVersion = None
    )
  }