|
|
@ -61,27 +61,6 @@ object PushNotificationAPI {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun register(token: String, publicKey: String, force: Boolean) {
|
|
|
|
fun register(token: String, publicKey: String, force: Boolean) {
|
|
|
|
val oldToken = TextSecurePreferences.getFCMToken(context)
|
|
|
|
|
|
|
|
val lastUploadDate = TextSecurePreferences.getLastFCMUploadTime(context)
|
|
|
|
|
|
|
|
if (!force && token == oldToken && System.currentTimeMillis() - lastUploadDate < tokenExpirationInterval) { return }
|
|
|
|
|
|
|
|
val parameters = mapOf( "token" to token, "pubKey" to publicKey )
|
|
|
|
|
|
|
|
val url = "$server/register"
|
|
|
|
|
|
|
|
val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
|
|
|
|
|
|
|
val request = Request.Builder().url(url).post(body)
|
|
|
|
|
|
|
|
retryIfNeeded(maxRetryCount) {
|
|
|
|
|
|
|
|
OnionRequestAPI.sendOnionRequest(request.build(), server, serverPublicKey, Version.V2).map { response ->
|
|
|
|
|
|
|
|
val code = response.info["code"] as? Int
|
|
|
|
|
|
|
|
if (code != null && code != 0) {
|
|
|
|
|
|
|
|
TextSecurePreferences.setIsUsingFCM(context, true)
|
|
|
|
|
|
|
|
TextSecurePreferences.setFCMToken(context, token)
|
|
|
|
|
|
|
|
TextSecurePreferences.setLastFCMUploadTime(context, System.currentTimeMillis())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.d("Loki", "Couldn't register for FCM due to error: ${response.info["message"] as? String ?: "null"}.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.fail { exception ->
|
|
|
|
|
|
|
|
Log.d("Loki", "Couldn't register for FCM due to error: ${exception}.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subscribe to all closed groups
|
|
|
|
// Subscribe to all closed groups
|
|
|
|
val allClosedGroupPublicKeys = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
|
|
|
val allClosedGroupPublicKeys = MessagingModuleConfiguration.shared.storage.getAllClosedGroupPublicKeys()
|
|
|
|
allClosedGroupPublicKeys.iterator().forEach { closedGroup ->
|
|
|
|
allClosedGroupPublicKeys.iterator().forEach { closedGroup ->
|
|
|
@ -92,7 +71,7 @@ object PushNotificationAPI {
|
|
|
|
fun performOperation(operation: ClosedGroupOperation, closedGroupPublicKey: String, publicKey: String) {
|
|
|
|
fun performOperation(operation: ClosedGroupOperation, closedGroupPublicKey: String, publicKey: String) {
|
|
|
|
if (!TextSecurePreferences.isUsingFCM(context)) { return }
|
|
|
|
if (!TextSecurePreferences.isUsingFCM(context)) { return }
|
|
|
|
val parameters = mapOf( "closedGroupPublicKey" to closedGroupPublicKey, "pubKey" to publicKey )
|
|
|
|
val parameters = mapOf( "closedGroupPublicKey" to closedGroupPublicKey, "pubKey" to publicKey )
|
|
|
|
val url = "$server/${operation.rawValue}"
|
|
|
|
val url = "$legacyServer/${operation.rawValue}"
|
|
|
|
val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
|
|
|
val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters))
|
|
|
|
val request = Request.Builder().url(url).post(body)
|
|
|
|
val request = Request.Builder().url(url).post(body)
|
|
|
|
retryIfNeeded(maxRetryCount) {
|
|
|
|
retryIfNeeded(maxRetryCount) {
|
|
|
|