mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 19:07:40 +00:00
feat: add support for firebase and split out google services as a dependency for only the play version of the app. Add support for requests in new pn server
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
package org.session.libsession.messaging.sending_receiving.notifications
|
||||
|
||||
import com.goterl.lazysodium.utils.Key
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* N.B. all of these variable names will be named the same as the actual JSON utf-8 request/responses expected from the server.
|
||||
* Changing the variable names will break how data is serialized/deserialized.
|
||||
* If it's less than ideally named we can use [SerialName]
|
||||
*/
|
||||
|
||||
@Serializable
|
||||
data class SubscriptionRequest(
|
||||
/** the 33-byte account being subscribed to; typically a session ID */
|
||||
@@ -9,7 +17,7 @@ data class SubscriptionRequest(
|
||||
/** when the pubkey starts with 05 (i.e. a session ID) this is the ed25519 32-byte pubkey associated with the session ID */
|
||||
val session_ed25519: String?,
|
||||
/** 32-byte swarm authentication subkey; omitted (or null) when not using subkey auth (new closed groups) */
|
||||
val subkey_tag: String?,
|
||||
val subkey_tag: String? = null,
|
||||
/** array of integer namespaces to subscribe to, **must be sorted in ascending order** */
|
||||
val namespaces: List<Int>,
|
||||
/** if provided and true then notifications will include the body of the message (as long as it isn't too large) */
|
||||
@@ -46,7 +54,18 @@ data class SubscriptionResponse(
|
||||
const val GENERIC_ERROR = 4
|
||||
}
|
||||
fun isSuccess() = success == true && error == null
|
||||
fun errorInfo() = if (success == false && error != null) {
|
||||
true to message
|
||||
} else false to null
|
||||
fun errorInfo() = if (success != true && error != null) {
|
||||
error to message
|
||||
} else null to null
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class PushNotificationServerObject(
|
||||
val enc_payload: String,
|
||||
val spns: Int,
|
||||
) {
|
||||
fun decryptPayload(key: Key): Any {
|
||||
|
||||
TODO()
|
||||
}
|
||||
}
|
@@ -9,15 +9,17 @@ import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.snode.OnionRequestAPI
|
||||
import org.session.libsession.snode.Version
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.utilities.retryIfNeeded
|
||||
import org.session.libsignal.utilities.JsonUtil
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.session.libsignal.utilities.retryIfNeeded
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object PushNotificationAPI {
|
||||
val context = MessagingModuleConfiguration.shared.context
|
||||
val server = "https://push.getsession.org"
|
||||
val serverPublicKey: String = TODO("get the new server pubkey here")
|
||||
private val legacyServer = "https://live.apns.getsession.org"
|
||||
private val legacyServerPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049"
|
||||
private val maxRetryCount = 4
|
||||
private val tokenExpirationInterval = 12 * 60 * 60 * 1000
|
||||
|
||||
@@ -94,7 +96,7 @@ object PushNotificationAPI {
|
||||
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 ->
|
||||
OnionRequestAPI.sendOnionRequest(request.build(), legacyServer, legacyServerPublicKey, Version.V2).map { response ->
|
||||
val code = response.info["code"] as? Int
|
||||
if (code == null || code == 0) {
|
||||
Log.d("Loki", "Couldn't subscribe/unsubscribe closed group: $closedGroupPublicKey due to error: ${response.info["message"] as? String ?: "null"}.")
|
||||
|
Reference in New Issue
Block a user