mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 12:30:07 +03:00
adding matrix SDK support for email adding and removing email pushes
- email pushes make use of a new undocumented `brand` field, for now this field maps directly to the app display name so we can resuse it
This commit is contained in:
parent
1591375aa2
commit
ee3f2877e9
5 changed files with 77 additions and 25 deletions
|
@ -27,7 +27,6 @@ interface PushersService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new HTTP pusher.
|
* Add a new HTTP pusher.
|
||||||
* Note that only `http` kind is supported by the SDK for now.
|
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set
|
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set
|
||||||
*
|
*
|
||||||
* @param pushkey This is a unique identifier for this pusher. The value you should use for
|
* @param pushkey This is a unique identifier for this pusher. The value you should use for
|
||||||
|
@ -64,6 +63,28 @@ interface PushersService {
|
||||||
append: Boolean,
|
append: Boolean,
|
||||||
withEventIdOnly: Boolean): UUID
|
withEventIdOnly: Boolean): UUID
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new Email pusher.
|
||||||
|
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set
|
||||||
|
*
|
||||||
|
* @param email The email address to send notifications to.
|
||||||
|
* If the kind is "email", this is the email address to send notifications to.
|
||||||
|
* @param lang The preferred language for receiving notifications (e.g. "en" or "en-US").
|
||||||
|
* @param appDisplayName A human readable string that will allow the user to identify what application owns this pusher.
|
||||||
|
* @param deviceDisplayName A human readable string that will allow the user to identify what device owns this pusher.
|
||||||
|
* @param append If true, the homeserver should add another pusher with the given pushkey and App ID in addition
|
||||||
|
* to any others with different user IDs. Otherwise, the homeserver must remove any other pushers
|
||||||
|
* with the same App ID and pushkey for different users.
|
||||||
|
* @return A work request uuid. Can be used to listen to the status
|
||||||
|
* (LiveData<WorkInfo> status = workManager.getWorkInfoByIdLiveData(<UUID>))
|
||||||
|
* @throws [InvalidParameterException] if a parameter is not correct
|
||||||
|
*/
|
||||||
|
fun addEmailPusher(email: String,
|
||||||
|
lang: String,
|
||||||
|
appDisplayName: String,
|
||||||
|
deviceDisplayName: String,
|
||||||
|
append: Boolean): UUID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directly ask the push gateway to send a push to this device
|
* Directly ask the push gateway to send a push to this device
|
||||||
* If successful, the push gateway has accepted the request. In this case, the app should receive a Push with the provided eventId.
|
* If successful, the push gateway has accepted the request. In this case, the app should receive a Push with the provided eventId.
|
||||||
|
@ -84,6 +105,11 @@ interface PushersService {
|
||||||
*/
|
*/
|
||||||
suspend fun removeHttpPusher(pushkey: String, appId: String)
|
suspend fun removeHttpPusher(pushkey: String, appId: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the email pusher for a given email
|
||||||
|
*/
|
||||||
|
suspend fun removeEmailPusher(email: String)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current pushers, as a LiveData
|
* Get the current pushers, as a LiveData
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationMan
|
||||||
import org.matrix.android.sdk.internal.session.media.MediaModule
|
import org.matrix.android.sdk.internal.session.media.MediaModule
|
||||||
import org.matrix.android.sdk.internal.session.openid.OpenIdModule
|
import org.matrix.android.sdk.internal.session.openid.OpenIdModule
|
||||||
import org.matrix.android.sdk.internal.session.profile.ProfileModule
|
import org.matrix.android.sdk.internal.session.profile.ProfileModule
|
||||||
import org.matrix.android.sdk.internal.session.pushers.AddHttpPusherWorker
|
import org.matrix.android.sdk.internal.session.pushers.AddPusherWorker
|
||||||
import org.matrix.android.sdk.internal.session.pushers.PushersModule
|
import org.matrix.android.sdk.internal.session.pushers.PushersModule
|
||||||
import org.matrix.android.sdk.internal.session.room.RoomModule
|
import org.matrix.android.sdk.internal.session.room.RoomModule
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.SendRelationWorker
|
import org.matrix.android.sdk.internal.session.room.relation.SendRelationWorker
|
||||||
|
@ -127,7 +127,7 @@ internal interface SessionComponent {
|
||||||
|
|
||||||
fun inject(worker: SyncWorker)
|
fun inject(worker: SyncWorker)
|
||||||
|
|
||||||
fun inject(worker: AddHttpPusherWorker)
|
fun inject(worker: AddPusherWorker)
|
||||||
|
|
||||||
fun inject(worker: SendVerificationMessageWorker)
|
fun inject(worker: SendVerificationMessageWorker)
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@ import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker
|
||||||
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
import org.matrix.android.sdk.internal.worker.SessionWorkerParams
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
|
internal class AddPusherWorker(context: Context, params: WorkerParameters)
|
||||||
: SessionSafeCoroutineWorker<AddHttpPusherWorker.Params>(context, params, Params::class.java) {
|
: SessionSafeCoroutineWorker<AddPusherWorker.Params>(context, params, Params::class.java) {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
internal data class Params(
|
internal data class Params(
|
|
@ -66,27 +66,38 @@ internal class DefaultPushersService @Inject constructor(
|
||||||
deviceDisplayName: String,
|
deviceDisplayName: String,
|
||||||
url: String,
|
url: String,
|
||||||
append: Boolean,
|
append: Boolean,
|
||||||
withEventIdOnly: Boolean)
|
withEventIdOnly: Boolean
|
||||||
: UUID {
|
) = addPusher(
|
||||||
// Do some parameter checks. It's ok to throw Exception, to inform developer of the problem
|
JsonPusher(
|
||||||
if (pushkey.length > 512) throw InvalidParameterException("pushkey should not exceed 512 chars")
|
pushKey = pushkey,
|
||||||
if (appId.length > 64) throw InvalidParameterException("appId should not exceed 64 chars")
|
kind = "http",
|
||||||
if ("/_matrix/push/v1/notify" !in url) throw InvalidParameterException("url should contain '/_matrix/push/v1/notify'")
|
appId = appId,
|
||||||
|
profileTag = profileTag,
|
||||||
|
lang = lang,
|
||||||
|
appDisplayName = appDisplayName,
|
||||||
|
deviceDisplayName = deviceDisplayName,
|
||||||
|
data = JsonPusherData(url, EVENT_ID_ONLY.takeIf { withEventIdOnly }),
|
||||||
|
append = append
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
val pusher = JsonPusher(
|
override fun addEmailPusher(email: String, lang: String, appDisplayName: String, deviceDisplayName: String, append: Boolean) = addPusher(
|
||||||
pushKey = pushkey,
|
JsonPusher(pushKey = email,
|
||||||
kind = "http",
|
kind = "email",
|
||||||
appId = appId,
|
appId = "m.email",
|
||||||
appDisplayName = appDisplayName,
|
profileTag = "",
|
||||||
deviceDisplayName = deviceDisplayName,
|
lang = lang,
|
||||||
profileTag = profileTag,
|
appDisplayName = appDisplayName,
|
||||||
lang = lang,
|
deviceDisplayName = deviceDisplayName,
|
||||||
data = JsonPusherData(url, EVENT_ID_ONLY.takeIf { withEventIdOnly }),
|
data = JsonPusherData(brand = appDisplayName),
|
||||||
append = append)
|
append = append
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
val params = AddHttpPusherWorker.Params(sessionId, pusher)
|
private fun addPusher(pusher: JsonPusher): UUID {
|
||||||
|
pusher.validateParameters()
|
||||||
val request = workManagerProvider.matrixOneTimeWorkRequestBuilder<AddHttpPusherWorker>()
|
val params = AddPusherWorker.Params(sessionId, pusher)
|
||||||
|
val request = workManagerProvider.matrixOneTimeWorkRequestBuilder<AddPusherWorker>()
|
||||||
.setConstraints(WorkManagerProvider.workConstraints)
|
.setConstraints(WorkManagerProvider.workConstraints)
|
||||||
.setInputData(WorkerParamsFactory.toData(params))
|
.setInputData(WorkerParamsFactory.toData(params))
|
||||||
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
|
.setBackoffCriteria(BackoffPolicy.LINEAR, WorkManagerProvider.BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS)
|
||||||
|
@ -95,11 +106,23 @@ internal class DefaultPushersService @Inject constructor(
|
||||||
return request.id
|
return request.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JsonPusher.validateParameters() {
|
||||||
|
// Do some parameter checks. It's ok to throw Exception, to inform developer of the problem
|
||||||
|
if (this.pushKey.length > 512) throw InvalidParameterException("pushkey should not exceed 512 chars")
|
||||||
|
if (this.appId.length > 64) throw InvalidParameterException("appId should not exceed 64 chars")
|
||||||
|
this.data?.url?.let { url -> if ("/_matrix/push/v1/notify" !in url) throw InvalidParameterException("url should contain '/_matrix/push/v1/notify'") }
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun removeHttpPusher(pushkey: String, appId: String) {
|
override suspend fun removeHttpPusher(pushkey: String, appId: String) {
|
||||||
val params = RemovePusherTask.Params(pushkey, appId)
|
val params = RemovePusherTask.Params(pushkey, appId)
|
||||||
removePusherTask.execute(params)
|
removePusherTask.execute(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun removeEmailPusher(email: String) {
|
||||||
|
val params = RemovePusherTask.Params(email, "m.email")
|
||||||
|
removePusherTask.execute(params)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getPushersLive(): LiveData<List<Pusher>> {
|
override fun getPushersLive(): LiveData<List<Pusher>> {
|
||||||
return monarchy.findAllMappedWithChanges(
|
return monarchy.findAllMappedWithChanges(
|
||||||
{ realm -> PusherEntity.where(realm) },
|
{ realm -> PusherEntity.where(realm) },
|
||||||
|
|
|
@ -32,5 +32,8 @@ internal data class JsonPusherData(
|
||||||
* Currently the only format available is 'event_id_only'.
|
* Currently the only format available is 'event_id_only'.
|
||||||
*/
|
*/
|
||||||
@Json(name = "format")
|
@Json(name = "format")
|
||||||
val format: String? = null
|
val format: String? = null,
|
||||||
|
|
||||||
|
@Json(name = "brand")
|
||||||
|
val brand: String? = null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue