mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 08:15:02 +00:00
Add KDoc to the libraries/pushstore API interfaces
Document UserPushStore, UserPushStoreFactory, PushClientSecret, PushClientSecretStore and PushClientSecretFactory along with all their members. The client secret interfaces now explain why they exist at all: a push gateway delivers notifications without saying which account they belong to, so the secret is what lets an incoming push be attributed back to a session. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+22
@@ -13,15 +13,36 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
* Store data related to push about a user.
|
* Store data related to push about a user.
|
||||||
*/
|
*/
|
||||||
interface UserPushStore {
|
interface UserPushStore {
|
||||||
|
/** The push provider selected for this user, or `null` when none has been selected yet. */
|
||||||
suspend fun getPushProviderName(): String?
|
suspend fun getPushProviderName(): String?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value the name of the push provider to remember for this user.
|
||||||
|
*/
|
||||||
suspend fun setPushProviderName(value: String)
|
suspend fun setPushProviderName(value: String)
|
||||||
|
|
||||||
|
/** The push key last registered with the homeserver, used to detect that a re-registration is needed; `null` when never registered. */
|
||||||
suspend fun getCurrentRegisteredPushKey(): String?
|
suspend fun getCurrentRegisteredPushKey(): String?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value the push key that has just been registered, or `null` to forget it after unregistering.
|
||||||
|
*/
|
||||||
suspend fun setCurrentRegisteredPushKey(value: String?)
|
suspend fun setCurrentRegisteredPushKey(value: String?)
|
||||||
|
|
||||||
|
/** Whether the user has enabled notifications on this device. */
|
||||||
fun getNotificationEnabledForDevice(): Flow<Boolean>
|
fun getNotificationEnabledForDevice(): Flow<Boolean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param enabled true to enable notifications on this device.
|
||||||
|
*/
|
||||||
suspend fun setNotificationEnabledForDevice(enabled: Boolean)
|
suspend fun setNotificationEnabledForDevice(enabled: Boolean)
|
||||||
|
|
||||||
|
/** Whether the user has asked not to be warned about pusher registration failures. */
|
||||||
fun ignoreRegistrationError(): Flow<Boolean>
|
fun ignoreRegistrationError(): Flow<Boolean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ignore true to stop warning the user about registration failures.
|
||||||
|
*/
|
||||||
suspend fun setIgnoreRegistrationError(ignore: Boolean)
|
suspend fun setIgnoreRegistrationError(ignore: Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,5 +50,6 @@ interface UserPushStore {
|
|||||||
*/
|
*/
|
||||||
fun useCompleteNotificationFormat(): Boolean
|
fun useCompleteNotificationFormat(): Boolean
|
||||||
|
|
||||||
|
/** Erases every push preference of this user, to be called when their session is removed. */
|
||||||
suspend fun reset()
|
suspend fun reset()
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -14,5 +14,10 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
|||||||
* Store data related to push about a user.
|
* Store data related to push about a user.
|
||||||
*/
|
*/
|
||||||
interface UserPushStoreFactory {
|
interface UserPushStoreFactory {
|
||||||
|
/**
|
||||||
|
* Returns the push store of a user, creating it on first use.
|
||||||
|
*
|
||||||
|
* @param userId the user whose store is requested.
|
||||||
|
*/
|
||||||
fun getOrCreate(userId: SessionId): UserPushStore
|
fun getOrCreate(userId: SessionId): UserPushStore
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -10,15 +10,24 @@ package io.element.android.libraries.pushstore.api.clientsecret
|
|||||||
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the per-session client secret sent along with a pusher registration.
|
||||||
|
*
|
||||||
|
* Push gateways deliver notifications without saying which account they belong to, so the secret is what lets an incoming push be attributed to a session.
|
||||||
|
*/
|
||||||
interface PushClientSecret {
|
interface PushClientSecret {
|
||||||
/**
|
/**
|
||||||
* To call when registering a pusher. It will return the existing secret or create a new one.
|
* To call when registering a pusher. It will return the existing secret or create a new one.
|
||||||
|
*
|
||||||
|
* @param userId the user the pusher is being registered for.
|
||||||
*/
|
*/
|
||||||
suspend fun getSecretForUser(userId: SessionId): String
|
suspend fun getSecretForUser(userId: SessionId): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To call when receiving a push containing a client secret.
|
* To call when receiving a push containing a client secret.
|
||||||
* Return null if not found.
|
* Return null if not found.
|
||||||
|
*
|
||||||
|
* @param clientSecret the secret carried by the incoming push.
|
||||||
*/
|
*/
|
||||||
suspend fun getUserIdFromSecret(clientSecret: String): SessionId?
|
suspend fun getUserIdFromSecret(clientSecret: String): SessionId?
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
package io.element.android.libraries.pushstore.api.clientsecret
|
package io.element.android.libraries.pushstore.api.clientsecret
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the client secrets used to attribute an incoming push to a session; see [PushClientSecret] for how they are used.
|
||||||
|
*/
|
||||||
interface PushClientSecretFactory {
|
interface PushClientSecretFactory {
|
||||||
|
/** Returns a new random secret. */
|
||||||
fun create(): String
|
fun create(): String
|
||||||
}
|
}
|
||||||
|
|||||||
+28
@@ -10,9 +10,37 @@ package io.element.android.libraries.pushstore.api.clientsecret
|
|||||||
|
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persists the mapping between sessions and their push client secrets, in both directions.
|
||||||
|
*/
|
||||||
interface PushClientSecretStore {
|
interface PushClientSecretStore {
|
||||||
|
/**
|
||||||
|
* Stores the secret of a user, replacing any previous one.
|
||||||
|
*
|
||||||
|
* @param userId the user the secret belongs to.
|
||||||
|
* @param clientSecret the secret to store.
|
||||||
|
*/
|
||||||
suspend fun storeSecret(userId: SessionId, clientSecret: String)
|
suspend fun storeSecret(userId: SessionId, clientSecret: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the stored secret of a user, or `null` when they have none yet.
|
||||||
|
*
|
||||||
|
* @param userId the user whose secret is requested.
|
||||||
|
*/
|
||||||
suspend fun getSecret(userId: SessionId): String?
|
suspend fun getSecret(userId: SessionId): String?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forgets the secret of a user, to be called when their session is removed.
|
||||||
|
*
|
||||||
|
* @param userId the user whose secret is erased.
|
||||||
|
*/
|
||||||
suspend fun resetSecret(userId: SessionId)
|
suspend fun resetSecret(userId: SessionId)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse lookup used when a push arrives carrying only a secret.
|
||||||
|
*
|
||||||
|
* @param clientSecret the secret to resolve.
|
||||||
|
* @return the user it belongs to, or `null` when no session matches.
|
||||||
|
*/
|
||||||
suspend fun getUserIdFromSecret(clientSecret: String): SessionId?
|
suspend fun getUserIdFromSecret(clientSecret: String): SessionId?
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user